r211654 - Fix parsing nested __if_exists blocks
Reid Kleckner
reid at kleckner.net
Tue Jun 24 17:28:35 PDT 2014
Author: rnk
Date: Tue Jun 24 19:28:35 2014
New Revision: 211654
URL: http://llvm.org/viewvc/llvm-project?rev=211654&view=rev
Log:
Fix parsing nested __if_exists blocks
Rather than having kw___if_exists be a special case of
ParseCompoundStatementBody, we can look for kw___if_exists in the big
switch over for valid statement tokens in ParseStatementOrDeclaration.
Nested __if_exists blocks are used in the DECLARE_REGISTRY_RESOURCEID
macro from atlcom.h.
Modified:
cfe/trunk/lib/Parse/ParseStmt.cpp
cfe/trunk/test/Parser/ms-if-exists.cpp
Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=211654&r1=211653&r2=211654&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Tue Jun 24 19:28:35 2014
@@ -273,6 +273,14 @@ Retry:
break;
}
+ case tok::kw___if_exists:
+ case tok::kw___if_not_exists:
+ ProhibitAttributes(Attrs);
+ ParseMicrosoftIfExistsStatement(Stmts);
+ // An __if_exists block is like a compound statement, but it doesn't create
+ // a new scope.
+ return StmtEmpty();
+
case tok::kw_try: // C++ 15: try-block
return ParseCXXTryBlock();
@@ -914,12 +922,6 @@ StmtResult Parser::ParseCompoundStatemen
continue;
}
- if (getLangOpts().MicrosoftExt && (Tok.is(tok::kw___if_exists) ||
- Tok.is(tok::kw___if_not_exists))) {
- ParseMicrosoftIfExistsStatement(Stmts);
- continue;
- }
-
StmtResult R;
if (Tok.isNot(tok::kw___extension__)) {
R = ParseStatementOrDeclaration(Stmts, false);
Modified: cfe/trunk/test/Parser/ms-if-exists.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/ms-if-exists.cpp?rev=211654&r1=211653&r2=211654&view=diff
==============================================================================
--- cfe/trunk/test/Parser/ms-if-exists.cpp (original)
+++ cfe/trunk/test/Parser/ms-if-exists.cpp Tue Jun 24 19:28:35 2014
@@ -1,7 +1,5 @@
// RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -Wmicrosoft -verify -fms-extensions
-// expected-no-diagnostics
-
class MayExist {
private:
typedef int Type;
@@ -101,3 +99,19 @@ class IfExistsClassScope {
int var244;
}
};
+
+void test_nested_if_exists() {
+ __if_exists(MayExist::Type) {
+ int x = 42;
+ __if_not_exists(MayExist::Type_not) {
+ x++;
+ }
+ }
+}
+
+void test_attribute_on_if_exists() {
+ [[clang::fallthrough]] // expected-error {{an attribute list cannot appear here}}
+ __if_exists(MayExist::Type) {
+ int x;
+ }
+}
More information about the cfe-commits
mailing list