[cfe-commits] r74266 - in /cfe/trunk: lib/Sema/SemaInit.cpp lib/Sema/SemaType.cpp test/SemaCXX/nested-name-spec.cpp

Chris Lattner sabre at nondot.org
Thu Jun 25 21:45:07 PDT 2009


Author: lattner
Date: Thu Jun 25 23:45:06 2009
New Revision: 74266

URL: http://llvm.org/viewvc/llvm-project?rev=74266&view=rev
Log:
Improve error recovery in C++: when we hit 'implicit int' cases in C++,
these are usually because the parser was thoroughly confused.  In addition
to typing the value being declared as an int and hoping for the best, we
mark the value as invalid so we don't get chains of errors when it is
used downstream.  In C, implicit int actually is valid, so typing the thing
as int is good and marking it invalid is bad. :)

Modified:
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/SemaCXX/nested-name-spec.cpp

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=74266&r1=74265&r2=74266&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Thu Jun 25 23:45:06 2009
@@ -200,10 +200,9 @@
       
       if (InitEntity)
         return Diag(InitLoc, diag::err_cannot_initialize_decl)
-        << InitEntity << (int)(Init->isLvalue(Context) == Expr::LV_Valid)
-        << Init->getType() << Init->getSourceRange();
-      else
-        return Diag(InitLoc, diag::err_cannot_initialize_decl_noname)
+          << InitEntity << (int)(Init->isLvalue(Context) == Expr::LV_Valid)
+          << Init->getType() << Init->getSourceRange();
+      return Diag(InitLoc, diag::err_cannot_initialize_decl_noname)
         << DeclType << (int)(Init->isLvalue(Context) == Expr::LV_Valid)
         << Init->getType() << Init->getSourceRange();
     }
@@ -211,7 +210,7 @@
     // C99 6.7.8p16.
     if (DeclType->isArrayType())
       return Diag(Init->getLocStart(), diag::err_array_init_list_required)
-      << Init->getSourceRange();
+        << Init->getSourceRange();
     
     return CheckSingleInitializer(Init, DeclType, DirectInit, *this);
   } 

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=74266&r1=74265&r2=74266&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu Jun 25 23:45:06 2009
@@ -121,16 +121,18 @@
       if (DeclLoc.isInvalid())
         DeclLoc = DS.getSourceRange().getBegin();
 
-      if (getLangOptions().CPlusPlus && !getLangOptions().Microsoft)
+      if (getLangOptions().CPlusPlus && !getLangOptions().Microsoft) {
         Diag(DeclLoc, diag::err_missing_type_specifier)
           << DS.getSourceRange();
-      else
+        
+        // When this occurs in C++ code, often something is very broken with the
+        // value being declared, poison it as invalid so we don't get chains of
+        // errors.
+        isInvalid = true;
+      } else {
         Diag(DeclLoc, diag::ext_missing_type_specifier)
           << DS.getSourceRange();
-
-      // FIXME: If we could guarantee that the result would be well-formed, it
-      // would be useful to have a code insertion hint here. However, after
-      // emitting this warning/error, we often emit other errors.
+      }
     }
       
     // FALL THROUGH.  

Modified: cfe/trunk/test/SemaCXX/nested-name-spec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/nested-name-spec.cpp?rev=74266&r1=74265&r2=74266&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/nested-name-spec.cpp (original)
+++ cfe/trunk/test/SemaCXX/nested-name-spec.cpp Thu Jun 25 23:45:06 2009
@@ -189,8 +189,7 @@
 foo<somens:a> a2;  // expected-error {{unexpected namespace name 'somens': expected expression}} \
 expected-error {{C++ requires a type specifier for all declarations}}
 
-// FIXME: This is bogus, there is no int here!
-somens::a a3 = a2; // expected-error {{cannot initialize 'a3' with an lvalue of type 'int'}}
+somens::a a3 = a2;
 
 
 





More information about the cfe-commits mailing list