
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
35 lines
480 B
C++
35 lines
480 B
C++
// RUN: %clang_cc1 -std=c++20 -emit-pch %s -o %t
|
|
// RUN: %clang_cc1 -std=c++20 -include-pch %t -verify %s
|
|
// expected-no-diagnostics
|
|
|
|
#ifndef HEADER_INCLUDED
|
|
#define HEADER_INCLUDED
|
|
|
|
consteval int immediate();
|
|
int regular_function() {
|
|
return 0;
|
|
}
|
|
|
|
struct S {
|
|
int a = immediate() + regular_function();
|
|
};
|
|
|
|
int f(int arg = immediate()) {
|
|
return arg;
|
|
}
|
|
|
|
#else
|
|
|
|
consteval int immediate() {
|
|
return 0;
|
|
}
|
|
|
|
void test() {
|
|
f(0);
|
|
f();
|
|
S s{0};
|
|
S t{0};
|
|
}
|
|
|
|
#endif
|