summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-06-26 04:45:06 +0000
committerChris Lattner <sabre@nondot.org>2009-06-26 04:45:06 +0000
commitd86a13e02e5179cfc4756c57a04e7591f17fa93c (patch)
treebadf77b20fdf665d20e627ec2cf0719ea3300261 /clang
parent2dbc6476cb5c1054109ee86b6d726d7f4a3c51e9 (diff)
downloadbcm5719-llvm-d86a13e02e5179cfc4756c57a04e7591f17fa93c.tar.gz
bcm5719-llvm-d86a13e02e5179cfc4756c57a04e7591f17fa93c.zip
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. :) llvm-svn: 74266
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Sema/SemaInit.cpp9
-rw-r--r--clang/lib/Sema/SemaType.cpp14
-rw-r--r--clang/test/SemaCXX/nested-name-spec.cpp3
3 files changed, 13 insertions, 13 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 45085962d48..6b812e1968d 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -200,10 +200,9 @@ bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType,
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 @@ bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType,
// 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);
}
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 12077b06713..8a0ad089b68 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -121,16 +121,18 @@ QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS,
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.
diff --git a/clang/test/SemaCXX/nested-name-spec.cpp b/clang/test/SemaCXX/nested-name-spec.cpp
index c3e4eb18e22..8fff8a2b2cb 100644
--- a/clang/test/SemaCXX/nested-name-spec.cpp
+++ b/clang/test/SemaCXX/nested-name-spec.cpp
@@ -189,8 +189,7 @@ class foo {
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;
OpenPOWER on IntegriCloud