This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Prevent -Wunused-lambda-capture from generating false positive warnings on templated member function
Needs ReviewPublic

Authored by ziangwan on Jul 31 2019, 5:05 PM.



This is a continuation of and a potential fix for
This fix follows the specification in paragraph 7.

template <typename A>
class Variant {
  Variant() {
    [this](auto value) { Construct(value); }(5); // false positive warning about "this" capture unused.

  template <typename Arg>
  void Construct(Arg value) {}

int main() {
  Variant<int> v;
  return 0;

Whenever we see a UnresolvedMemberExpr, we always mark a this capture ODR-used, even if later on it may be resolved to a static member function. The trade-off of this fix is that it will leads to false negative in the following case:

template <typename A>
class OverloadedMixFalseNegative {
  OverloadedMixFalseNegative() {
    [this](auto value) { Construct(value); }(5); // warning disappears but should happen

  static void Construct(int value) {}
  void Construct(float value) {}

Diff Detail

Event Timeline

ziangwan created this revision.Jul 31 2019, 5:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 31 2019, 5:05 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
ziangwan edited reviewers, added: arphaman; removed: stephenkelly.Jul 31 2019, 5:06 PM
ziangwan edited the summary of this revision. (Show Details)Aug 2 2019, 1:28 PM
ziangwan changed the repository for this revision from rC Clang to rL LLVM.Aug 4 2019, 6:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2019, 6:21 PM

Thanks for the patch @ziangwan !


LLVM style is not to use {} for single statement bodies.

ziangwan updated this revision to Diff 214013.Aug 7 2019, 3:06 PM

Fix style issue.

ziangwan marked an inline comment as done.Aug 7 2019, 3:06 PM