From e950d4bbb7c785c7a7abdd0ad98f372b8c7980b8 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 6 Mar 2009 23:28:18 +0000 Subject: [PATCH] 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 --- include/clang/Basic/DiagnosticParseKinds.def | 2 ++ lib/Parse/ParseDecl.cpp | 5 ++++- test/Parser/cxx-using-directive.cpp | 2 +- test/Sema/anonymous-struct-union.c | 7 +++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/clang/Basic/DiagnosticParseKinds.def b/include/clang/Basic/DiagnosticParseKinds.def index dc08aed29c..ab56766a0f 100644 --- a/include/clang/Basic/DiagnosticParseKinds.def +++ b/include/clang/Basic/DiagnosticParseKinds.def @@ -112,6 +112,8 @@ DIAG(err_expected_semi_decl_list, ERROR, "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 50b6716df8..bbe074a8fb 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -1868,7 +1868,10 @@ void Parser::ParseDirectDeclarator(Declarator &D) { // 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 b89436046b..bf89bb1921 100644 --- a/test/Parser/cxx-using-directive.cpp +++ b/test/Parser/cxx-using-directive.cpp @@ -13,7 +13,7 @@ namespace D { 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 d8a445c649..9784236c8b 100644 --- a/test/Sema/anonymous-struct-union.c +++ b/test/Sema/anonymous-struct-union.c @@ -88,4 +88,11 @@ struct s1 { }; }; +// PR3680 struct {}; // expected-error{{declaration does not declare anything}} + +struct s2 { + union { + int a; + } +}; // expected-error{{expected member name or ';' after declaration specifiers}} -- 2.40.0