diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -11067,8 +11067,14 @@ // except that the aforementioned are allowed in unevaluated // expressions. Everything else falls under the // "may accept other forms of constant expressions" exception. - // (We never end up here for C++, so the constant expression - // rules there don't matter.) + // + // Regular C++ code will not end up here (exceptions: language extensions, + // OpenCL C++ etc), so the constant expression rules there don't matter. + if (Init->isValueDependent()) { + assert(Init->containsErrors() && + "Dependent code should only occur in error-recovery path."); + return true; + } const Expr *Culprit; if (Init->isConstantInitializer(Context, false, &Culprit)) return false; diff --git a/clang/test/SemaOpenCL/recovery-expr.cl b/clang/test/SemaOpenCL/recovery-expr.cl new file mode 100644 --- /dev/null +++ b/clang/test/SemaOpenCL/recovery-expr.cl @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++ -frecovery-ast + +void kernel nocrash() { + constant int L1 = 0; + + private int *constant L2 = L1++; // expected-error {{read-only variable is not assignable}} +}