Clean up some error messages with anonymous structs/unions and member declaration parsing. Fixes PR3680
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66305 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/DiagnosticParseKinds.def b/include/clang/Basic/DiagnosticParseKinds.def
index dc08aed..ab56766 100644
--- a/include/clang/Basic/DiagnosticParseKinds.def
+++ b/include/clang/Basic/DiagnosticParseKinds.def
@@ -112,6 +112,8 @@
"expected ';' at end of declaration list")
DIAG(ext_expected_semi_decl_list, EXTENSION,
"expected ';' at end of declaration list")
+DIAG(err_expected_member_name_or_semi, ERROR,
+ "expected member name or ';' after declaration specifiers")
DIAG(err_function_declared_typedef, ERROR,
"function definition declared 'typedef'")
DIAG(err_expected_fn_body, ERROR,
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index 50b6716..bbe074a 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -1868,7 +1868,10 @@
// portion is empty), if an abstract-declarator is allowed.
D.SetIdentifier(0, Tok.getLocation());
} else {
- if (getLang().CPlusPlus)
+ if (D.getContext() == Declarator::MemberContext)
+ Diag(Tok, diag::err_expected_member_name_or_semi)
+ << D.getDeclSpec().getSourceRange();
+ else if (getLang().CPlusPlus)
Diag(Tok, diag::err_expected_unqualified_id);
else
Diag(Tok, diag::err_expected_ident_lparen);
diff --git a/test/Parser/cxx-using-directive.cpp b/test/Parser/cxx-using-directive.cpp
index b894360..bf89bb1 100644
--- a/test/Parser/cxx-using-directive.cpp
+++ b/test/Parser/cxx-using-directive.cpp
@@ -13,7 +13,7 @@
class C {
- using namespace B ; // expected-error{{expected unqualified-id}}
+ using namespace B ; // expected-error{{expected member name or ';' after declaration specifiers}}
//FIXME: this needs better error message
};
diff --git a/test/Sema/anonymous-struct-union.c b/test/Sema/anonymous-struct-union.c
index d8a445c..9784236 100644
--- a/test/Sema/anonymous-struct-union.c
+++ b/test/Sema/anonymous-struct-union.c
@@ -88,4 +88,11 @@
};
};
+// PR3680
struct {}; // expected-error{{declaration does not declare anything}}
+
+struct s2 {
+ union {
+ int a;
+ }
+}; // expected-error{{expected member name or ';' after declaration specifiers}}