From 0778fc61cf6933981705c2258d59ae82e79c9e24 Mon Sep 17 00:00:00 2001 From: Serge Pavlov Date: Sun, 4 Aug 2019 10:08:51 +0000 Subject: [Parser] Emit descriptive diagnostic for misplaced pragma If a class or struct or union declaration contains a pragma that is not valid in this context, compiler issues generic error like "expected member name or ';' after declaration specifiers". With this change the error tells that this pragma cannot appear in this declaration. Differential Revision: https://reviews.llvm.org/D64932 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@367779 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Parse/ParseDecl.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/Parse/ParseDecl.cpp') diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 63a7de454c..5fc36e86b1 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -4148,6 +4148,14 @@ void Parser::ParseStructUnionBody(SourceLocation RecordLoc, continue; } + if (tok::isPragmaAnnotation(Tok.getKind())) { + Diag(Tok.getLocation(), diag::err_pragma_misplaced_in_decl) + << DeclSpec::getSpecifierName( + TagType, Actions.getASTContext().getPrintingPolicy()); + ConsumeAnnotationToken(); + continue; + } + if (!Tok.is(tok::at)) { auto CFieldCallback = [&](ParsingFieldDeclarator &FD) { // Install the declarator into the current TagDecl. -- cgit v1.2.1