r195577 - Parse Microsoft __declspec appearing after class body

Alp Toker alp at nuanti.com
Sun Nov 24 12:24:54 PST 2013


Author: alp
Date: Sun Nov 24 14:24:54 2013
New Revision: 195577

URL: http://llvm.org/viewvc/llvm-project?rev=195577&view=rev
Log:
Parse Microsoft __declspec appearing after class body

MSVC applies these to the following declaration only if present, otherwise
silently ignores them whereas we'll issue a warning.

Handling differs from ordinary attributes appearing in the same place, so add a
Sema test to make sure we get it right.

Modified:
    cfe/trunk/lib/Parse/ParseDeclCXX.cpp
    cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp

Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=195577&r1=195576&r2=195577&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Sun Nov 24 14:24:54 2013
@@ -1021,6 +1021,7 @@ bool Parser::isValidAfterTypeSpecifier(b
   case tok::l_paren:            // struct foo {...} (         x);
   case tok::comma:              // __builtin_offsetof(struct foo{...} ,
   case tok::kw_operator:        // struct foo       operator  ++() {...}
+  case tok::kw___declspec:      // struct foo {...} __declspec(...)
     return true;
   case tok::colon:
     return CouldBeBitfield;     // enum E { ... }   :         2;

Modified: cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp?rev=195577&r1=195576&r2=195577&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp (original)
+++ cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp Sun Nov 24 14:24:54 2013
@@ -410,3 +410,14 @@ struct SealedType sealed : SomeBase {
 
 // expected-error at +1 {{base 'SealedType' is marked 'sealed'}}
 struct InheritFromSealed : SealedType {};
+
+void AfterClassBody() {
+  // expected-warning at +1 {{attribute 'deprecated' is ignored, place it after "struct" to apply attribute to type declaration}}
+  struct D {} __declspec(deprecated);
+
+  struct __declspec(align(4)) S {} __declspec(align(8)) s1;
+  S s2;
+  _Static_assert(__alignof(S) == 4, "");
+  _Static_assert(__alignof(s1) == 8, "");
+  _Static_assert(__alignof(s2) == 4, "");
+}





More information about the cfe-commits mailing list