Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3550,7 +3550,12 @@ static bool evaluateVarDeclInit(EvalInfo &Info, const Expr *E,
// should begin within the evaluation of E
// Used to be C++20 [expr.const]p5.12.2:
// ... its lifetime began within the evaluation of E;
if (isa<ParmVarDecl>(VD) && !AllowConstexprUnknown) {
if (isa<ParmVarDecl>(VD)) {
if (AllowConstexprUnknown) {
Result = &Info.CurrentCall->createConstexprUnknownAPValues(VD, Base);
return true;
}

// Assume parameters of a potential constant expression are usable in
// constant expressions.
if (!Info.checkingPotentialConstantExpression() ||
Expand Down
12 changes: 12 additions & 0 deletions clang/test/SemaCXX/constant-expression-p2280r4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,15 @@ namespace uninit_reference_used {
// expected-note {{in call to 'g5()'}}

}

namespace param_reference {
constexpr int arbitrary = -12345;
constexpr void f(const int &x = arbitrary) { // expected-note {{declared here}}
constexpr const int &v1 = x; // expected-error {{must be initialized by a constant expression}} \
// expected-note {{reference to 'x' is not a constant expression}}
constexpr const int &v2 = (x, arbitrary); // expected-warning {{left operand of comma operator has no effect}}
constexpr int v3 = x; // expected-error {{must be initialized by a constant expression}}
static_assert(x==arbitrary); // expected-error {{static assertion expression is not an integral constant expression}}
static_assert(&x - &x == 0);
}
}
Loading