]> granicus.if.org Git - clang/commitdiff
Parse Microsoft __declspec appearing after class body
authorAlp Toker <alp@nuanti.com>
Sun, 24 Nov 2013 20:24:54 +0000 (20:24 +0000)
committerAlp Toker <alp@nuanti.com>
Sun, 24 Nov 2013 20:24:54 +0000 (20:24 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@195577 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseDeclCXX.cpp
test/SemaCXX/MicrosoftExtensions.cpp

index d2d9b220fd73cac1a776b30613651451ef94bac3..32e151cf2c29eb240a33040cad920b3407c9d8d4 100644 (file)
@@ -1021,6 +1021,7 @@ bool Parser::isValidAfterTypeSpecifier(bool CouldBeBitfield) {
   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;
index c5b45a2905c8bbf3e2fddaf1e52502ebc2f63257..5c51331500b5352d4980bac1f72571810f926c5b 100644 (file)
@@ -410,3 +410,14 @@ struct SealedType sealed : SomeBase {
 
 // expected-error@+1 {{base 'SealedType' is marked 'sealed'}}
 struct InheritFromSealed : SealedType {};
+
+void AfterClassBody() {
+  // expected-warning@+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, "");
+}