release/20.x: [clang] Don't evaluate the initializer of constexpr-unk… · llvm/llvm-project@6fa0cdf (original) (raw)
2 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -3525,7 +3525,12 @@ static bool evaluateVarDeclInit(EvalInfo &Info, const Expr *E, | ||
3525 | 3525 | // should begin within the evaluation of E |
3526 | 3526 | // Used to be C++20 [expr.const]p5.12.2: |
3527 | 3527 | // ... its lifetime began within the evaluation of E; |
3528 | - if (isa(VD) && !AllowConstexprUnknown) { | |
3528 | + if (isa(VD)) { | |
3529 | + if (AllowConstexprUnknown) { | |
3530 | + Result = &Info.CurrentCall->createConstexprUnknownAPValues(VD, Base); | |
3531 | + return true; | |
3532 | + } | |
3533 | + | |
3529 | 3534 | // Assume parameters of a potential constant expression are usable in |
3530 | 3535 | // constant expressions. |
3531 | 3536 | if (!Info.checkingPotentialConstantExpression() | |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -200,3 +200,15 @@ int f() { | ||
200 | 200 | return !get_value(); // contextually convert the function call result to bool |
201 | 201 | } |
202 | 202 | } |
203 | + | |
204 | +namespace param_reference { | |
205 | +constexpr int arbitrary = -12345; | |
206 | +constexpr void f(const int &x = arbitrary) { // expected-note {{declared here}} | |
207 | +constexpr const int &v1 = x; // expected-error {{must be initialized by a constant expression}} \ | |
208 | + // expected-note {{reference to 'x' is not a constant expression}} | |
209 | +constexpr const int &v2 = (x, arbitrary); // expected-warning {{left operand of comma operator has no effect}} | |
210 | +constexpr int v3 = x; // expected-error {{must be initialized by a constant expression}} | |
211 | +static_assert(x==arbitrary); // expected-error {{static assertion expression is not an integral constant expression}} | |
212 | +static_assert(&x - &x == 0); | |
213 | + } | |
214 | +} |