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 @@ -11069,6 +11069,7 @@ // "may accept other forms of constant expressions" exception. // (We never end up here for C++, so the constant expression // rules there don't matter.) + assert(!getLangOpts().CPlusPlus || getLangOpts().OpenCLCPlusPlus); const Expr *Culprit; if (Init->isConstantInitializer(Context, false, &Culprit)) return false; diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -6816,12 +6816,9 @@ auto *E = new (Context) CompoundLiteralExpr(LParenLoc, TInfo, literalType, VK, LiteralExpr, isFileScope); - if (isFileScope) { - if (!LiteralExpr->isTypeDependent() && - !LiteralExpr->isValueDependent() && - !literalType->isDependentType()) // C99 6.5.2.5p3 - if (CheckForConstantInitializer(LiteralExpr, literalType)) - return ExprError(); + if (isFileScope && !getLangOpts().CPlusPlus) { // C99 6.5.2.5p3 + if (CheckForConstantInitializer(LiteralExpr, literalType)) + return ExprError(); } else if (literalType.getAddressSpace() != LangAS::opencl_private && literalType.getAddressSpace() != LangAS::Default) { // Embedded-C extensions to C99 6.5.2.5: diff --git a/clang/test/SemaCXX/compound-literal.cpp b/clang/test/SemaCXX/compound-literal.cpp --- a/clang/test/SemaCXX/compound-literal.cpp +++ b/clang/test/SemaCXX/compound-literal.cpp @@ -89,9 +89,7 @@ } } -// This doesn't necessarily need to be an error, but CodeGen can't handle it -// at the moment. -int PR17415 = (int){PR17415}; // expected-error {{initializer element is not a compile-time constant}} +int PR17415 = (int){PR17415}; // expected-warning {{variable 'PR17415' is uninitialized when used within its own initialization}} // Make sure we accept this. (Not sure if we actually should... but we do // at the moment.)