[PATCH] D65549: [Sema] Prevent -Wunused-lambda-capture from generating false positive warnings on templated member function

Ziang Wan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 31 17:06:02 PDT 2019

ziangwan created this revision.
ziangwan added reviewers: rsmith, nickdesaulniers, kongyi, pirama, stephenkelly.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is a continuation of https://reviews.llvm.org/D44844 and a potential fix for https://bugs.llvm.org/show_bug.cgi?id=36880.

  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) {}

  rC Clang



-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65549.212705.patch
Type: text/x-patch
Size: 3260 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190801/30a7c36d/attachment.bin>

More information about the cfe-commits mailing list