diff options
| -rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 4 | ||||
| -rw-r--r-- | clang/test/CodeGenCXX/member-initializers.cpp | 12 |
2 files changed, 16 insertions, 0 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index a0b2aa993fa..382bfe59b5b 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -878,6 +878,10 @@ bool IntExprEvaluator::CheckReferencedDecl(const Expr* E, const Decl* D) { // In C, they can also be folded, although they are not ICEs. if (Info.Ctx.getCanonicalType(E->getType()).getCVRQualifiers() == Qualifiers::Const) { + + if (isa<ParmVarDecl>(D)) + return Error(E->getLocStart(), diag::note_invalid_subexpr_in_ice, E); + if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { if (const Expr *Init = VD->getAnyInitializer()) { if (APValue *V = VD->getEvaluatedValue()) { diff --git a/clang/test/CodeGenCXX/member-initializers.cpp b/clang/test/CodeGenCXX/member-initializers.cpp index 1a27b7d202d..81dcee7e407 100644 --- a/clang/test/CodeGenCXX/member-initializers.cpp +++ b/clang/test/CodeGenCXX/member-initializers.cpp @@ -20,3 +20,15 @@ int f() { return b.i; } +// Test that we don't try to fold the default value of j when initializing i. +// CHECK: define i32 @_Z9test_foldv() nounwind +int test_fold() { + struct A { + A(const int j = 1) : i(j) { } + int i; + }; + + // CHECK: ret i32 2 + return A(2).i; +} + |

