Implement CWG2631
authorCorentin Jabot <corentinjabot@gmail.com>
Sun, 23 Oct 2022 15:32:58 +0000 (17:32 +0200)
committerCorentin Jabot <corentinjabot@gmail.com>
Sun, 8 Jan 2023 09:35:26 +0000 (10:35 +0100)
commitca619613801233ef2def8c3cc7d311d5ed0033cb
treeeb15c5e383d87560df64123a3746c9aa5e5dc23e
parenteda8e999dd01e9a741a43330b693cff94d4cb955
Implement CWG2631

Implement https://cplusplus.github.io/CWG/issues/2631.html.

Immediate calls in default arguments and defaults members
are not evaluated.

Instead, we evaluate them when constructing a
`CXXDefaultArgExpr`/`BuildCXXDefaultInitExpr`.

The immediate calls are executed by doing a
transform on the initializing expression.

Note that lambdas are not considering subexpressions so
we do not need to transform them.

As a result of this patch, unused default member
initializers are not considered odr-used, and
errors about members binding to local variables
in an outer scope only surface at the point
where a constructor is defined.

Reviewed By: aaron.ballman, #clang-language-wg, rupprecht

Differential Revision: https://reviews.llvm.org/D136554
28 files changed:
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 [new file with mode: 0644]
clang/test/CodeGenCXX/meminit-initializers-odr.cpp [new file with mode: 0644]
clang/test/PCH/default-argument-with-immediate-calls.cpp [new file with mode: 0644]
clang/test/SemaCXX/cxx11-default-member-initializers.cpp
clang/test/SemaCXX/cxx2a-consteval-default-params.cpp [new file with mode: 0644]
clang/test/SemaCXX/source_location.cpp
clang/www/cxx_dr_status.html