summaryrefslogtreecommitdiffstats
path: root/clang/lib/Parse/ParseDecl.cpp
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2017-02-14 22:47:20 +0000
committerAaron Ballman <aaron@aaronballman.com>2017-02-14 22:47:20 +0000
commit52d0aaac139ae8804f31970fa96f5debbe94deee (patch)
treef8253020178f59b484defec797ede48e868e9902 /clang/lib/Parse/ParseDecl.cpp
parentc91daf1cf9a40155ded9e1c6d1072e572e065281 (diff)
downloadbcm5719-llvm-52d0aaac139ae8804f31970fa96f5debbe94deee.tar.gz
bcm5719-llvm-52d0aaac139ae8804f31970fa96f5debbe94deee.zip
Improve diagnostic reporting when using __declspec without enabling __declspec as a keyword.
Fixes PR31936. llvm-svn: 295114
Diffstat (limited to 'clang/lib/Parse/ParseDecl.cpp')
-rw-r--r--clang/lib/Parse/ParseDecl.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 7ffafe2dab7..e0347ccf2fb 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -2966,6 +2966,31 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
if (DS.hasTypeSpecifier())
goto DoneWithDeclSpec;
+ // If the token is an identifier named "__declspec" and Microsoft
+ // extensions are not enabled, it is likely that there will be cascading
+ // parse errors if this really is a __declspec attribute. Attempt to
+ // recognize that scenario and recover gracefully.
+ if (!getLangOpts().DeclSpecKeyword && Tok.is(tok::identifier) &&
+ Tok.getIdentifierInfo()->getName().equals("__declspec")) {
+ Diag(Loc, diag::err_ms_attributes_not_enabled);
+
+ // The next token should be an open paren. If it is, eat the entire
+ // attribute declaration and continue.
+ if (NextToken().is(tok::l_paren)) {
+ // Consume the __declspec identifier.
+ SourceLocation Loc = ConsumeToken();
+
+ // Eat the parens and everything between them.
+ BalancedDelimiterTracker T(*this, tok::l_paren);
+ if (T.consumeOpen()) {
+ assert(false && "Not a left paren?");
+ return;
+ }
+ T.skipToEnd();
+ continue;
+ }
+ }
+
// In C++, check to see if this is a scope specifier like foo::bar::, if
// so handle it as such. This is important for ctor parsing.
if (getLangOpts().CPlusPlus) {
OpenPOWER on IntegriCloud