[PATCH] D122494: Do not treat use of variable from attribute arguments as ODR use

Mariya Podchishchaeva via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 25 11:33:16 PDT 2022


Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Attribute arguments are always compile-time expressions that need to be
evaluated. So, it is not necessary to treat attribute use as ODR use.

Treatment of use from attribute aruments as ODR use had a side
effect in incorrect processing of attributes applied to nested lambdas.
That happened because ODR use from attribute applied to a lambda forced
Sema to check if used variable is correctly captured.
For the following example:

  const int I = 10;
  auto OL = [=] () {
    auto IL = [&](int K) __attribute__((enable_if(I > K, "..."))) {};
  };

when capture-checking function was validating use of either variable `I` or
parameter `K` the error "variable cannot be implicitly captured in a lambda with
no capture-default specified" was emitted. That happened due to the
following order of actions during lambda parsing: first, an empty lambda scope
is pushed to `FunctionScopes` collection in `Sema`, then the attributes on
lambdas are handled, and only after that the info about inner lambda capturing
style is saved to a corresponding lambda scope. So, at the point when
attributes on inner lambda are handled, capture-checking function thinks
that it is already inside the inner lambda and it doesn't have capturing
style, so the error was emitted.

This patch makes this error go away.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122494

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/attr-on-lambda.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122494.418281.patch
Type: text/x-patch
Size: 5460 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220325/338e15e0/attachment.bin>


More information about the cfe-commits mailing list