]> granicus.if.org Git - clang/commitdiff
Tweak changes in r186464 to avoid a crash.
authorEli Friedman <eli.friedman@gmail.com>
Tue, 1 Oct 2013 00:28:29 +0000 (00:28 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Tue, 1 Oct 2013 00:28:29 +0000 (00:28 +0000)
Currently, IR generation can't handle file-scope compound literals with
non-constant initializers in C++.

Fixes PR17415 (the first crash in the bug).

(We should probably change (T){1,2,3} to use the same codepath as T{1,2,3} in
C++ eventually, given that the semantics of the latter are actually defined by
the standard.)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191719 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Expr.cpp
lib/Sema/SemaExpr.cpp
test/SemaCXX/compound-literal.cpp

index a3a36da65f43eff7f9883e797c1de02a8d3e5a15..38f5e2f4887247e050d45b72259c5161fc862e25 100644 (file)
@@ -2654,9 +2654,6 @@ bool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef) const {
     return Exp->isConstantInitializer(Ctx, false);
   }
   case InitListExprClass: {
-    // FIXME: This doesn't deal with fields with reference types correctly.
-    // FIXME: This incorrectly allows pointers cast to integers to be assigned
-    // to bitfields.
     const InitListExpr *ILE = cast<InitListExpr>(this);
     if (ILE->getType()->isArrayType()) {
       unsigned numInits = ILE->getNumInits();
index 9940e8ba79b1a07106e97fc3e68c1f1d0a16cfe3..239567844d4f2b1e134b8927a95b67b356661333 100644 (file)
@@ -4717,7 +4717,10 @@ Sema::BuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo,
   LiteralExpr = Result.get();
 
   bool isFileScope = getCurFunctionOrMethodDecl() == 0;
-  if (!getLangOpts().CPlusPlus && isFileScope) { // 6.5.2.5p3
+  if (isFileScope &&
+      !LiteralExpr->isTypeDependent() &&
+      !LiteralExpr->isValueDependent() &&
+      !literalType->isDependentType()) { // 6.5.2.5p3
     if (CheckForConstantInitializer(LiteralExpr, literalType))
       return ExprError();
   }
index 595747e40ce6ee418659756ceccdc85f416be2b4..3fc61505dfee3a0c4eae9c93e49ac3f444df7635 100644 (file)
@@ -76,3 +76,13 @@ namespace brace_initializers {
     (void)(PrivateDtor){1, 2}; // expected-error {{temporary of type 'brace_initializers::PrivateDtor' has private destructor}}
   }
 }
+
+// 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}}
+
+// Make sure we accept this.  (Not sure if we actually should... but we do
+// at the moment.)
+template<unsigned> struct Value { };
+template<typename T>
+int &check_narrowed(Value<sizeof((T){1.1})>);