[PATCH] D136554: Implement CWG2631

Corentin Jabot via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 30 08:19:19 PST 2022


cor3ntin updated this revision to Diff 485703.
cor3ntin added a comment.

Finding the issue took about all day.
I reduced your example to

  template <typename a>
  int templated_func() {
      return 0;
  }
  struct test_body {
    int mem = templated_func<int>();
  };
  
  struct S {
    int a = [] { test_body{}; return 0;}(); // #1
  } s;

When parsing the lambda #1 , we were not considering test_body{} to be 
odr used, on account of the lambda being in the default initializer of a.

However, as it turns out, expressions in the body of a lambda are always 
considered ODR used even if the lambda appear in a default parameter, 
which I think makes sense.
(as the standard specifies that the body of a lambda is not a sub expression)

The actual code fix is to simplify the check we do to see if we are 
in a nested default initializer.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136554/new/

https://reviews.llvm.org/D136554

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Sema/UsedDeclVisitor.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/AST/ast-dump-records.cpp
  clang/test/CXX/class/class.local/p1-0x.cpp
  clang/test/CXX/drs/dr26xx.cpp
  clang/test/CodeGenCXX/builtin-source-location.cpp
  clang/test/CodeGenCXX/default-arguments-with-immediate.cpp
  clang/test/CodeGenCXX/meminit-initializers-odr.cpp
  clang/test/PCH/default-argument-with-immediate-calls.cpp
  clang/test/SemaCXX/cxx11-default-member-initializers.cpp
  clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
  clang/test/SemaCXX/source_location.cpp
  clang/www/cxx_dr_status.html

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136554.485703.patch
Type: text/x-patch
Size: 65887 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221230/a5e2b981/attachment-0001.bin>


More information about the cfe-commits mailing list