[cfe-commits] r148088 - in /cfe/trunk: lib/Sema/SemaDecl.cpp lib/Sema/SemaFixItUtils.cpp test/SemaCXX/decl-expr-ambiguity.cpp

Richard Smith richard-llvm at metafoo.co.uk
Thu Jan 12 18:14:39 PST 2012


Author: rsmith
Date: Thu Jan 12 20:14:39 2012
New Revision: 148088

URL: http://llvm.org/viewvc/llvm-project?rev=148088&view=rev
Log:
Don't crash while trying to diagnose a function declared at block scope with an
incomplete return type.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaFixItUtils.cpp
    cfe/trunk/test/SemaCXX/decl-expr-ambiguity.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=148088&r1=148087&r2=148088&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Jan 12 20:14:39 2012
@@ -4945,7 +4945,8 @@
         // Empty parens mean value-initialization, and no parens mean default
         // initialization. These are equivalent if the default constructor is
         // user-provided, or if zero-initialization is a no-op.
-        if (RD && (RD->isEmpty() || RD->hasUserProvidedDefaultConstructor()))
+        if (RD && RD->hasDefinition() &&
+            (RD->isEmpty() || RD->hasUserProvidedDefaultConstructor()))
           Diag(C.Loc, diag::note_empty_parens_default_ctor)
             << FixItHint::CreateRemoval(ParenRange);
         else if (const char *Init = getFixItZeroInitializerForType(T))

Modified: cfe/trunk/lib/Sema/SemaFixItUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaFixItUtils.cpp?rev=148088&r1=148087&r2=148088&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaFixItUtils.cpp (original)
+++ cfe/trunk/lib/Sema/SemaFixItUtils.cpp Thu Jan 12 20:14:39 2012
@@ -180,9 +180,11 @@
   if (T->isScalarType())
     return " = 0";
   const CXXRecordDecl *RD = T->getAsCXXRecordDecl();
-  if (LangOpts.CPlusPlus0x && RD && !RD->hasUserProvidedDefaultConstructor())
+  if (!RD || !RD->hasDefinition())
+    return 0;
+  if (LangOpts.CPlusPlus0x && !RD->hasUserProvidedDefaultConstructor())
     return "{}";
-  if (T->isAggregateType())
+  if (RD->isAggregate())
     return " = {}";
   return 0;
 }

Modified: cfe/trunk/test/SemaCXX/decl-expr-ambiguity.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/decl-expr-ambiguity.cpp?rev=148088&r1=148087&r2=148088&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/decl-expr-ambiguity.cpp (original)
+++ cfe/trunk/test/SemaCXX/decl-expr-ambiguity.cpp Thu Jan 12 20:14:39 2012
@@ -50,10 +50,14 @@
 
 void func();
 namespace N {
+  struct S;
+
   void emptyParens() {
     RAII raii(); // expected-warning {{function declaration}} expected-note {{remove parentheses to declare a variable}}
     int a, b, c, d, e, // expected-note {{change this ',' to a ';' to call 'func'}}
     func(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
+
+    S s(); // expected-warning {{function declaration}}
   }
 }
 





More information about the cfe-commits mailing list