
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
19 lines
573 B
C++
19 lines
573 B
C++
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
|
|
|
|
void f() {
|
|
int x = 3; // expected-note{{'x' declared here}}
|
|
const int c = 2;
|
|
struct C {
|
|
int& x2 = x; // expected-error{{reference to local variable 'x' declared in enclosing function 'f'}}
|
|
int cc = c;
|
|
};
|
|
(void)[]() mutable {
|
|
int x = 3; // expected-note{{'x' declared here}}
|
|
struct C {
|
|
int& x2 = x; // expected-error{{reference to local variable 'x' declared in enclosing lambda expression}}
|
|
}c; // expected-note {{required here}}
|
|
};
|
|
C(); // expected-note {{required here}}
|
|
}
|
|
|