parser: diagnose empty attribute blocks
authorSaleem Abdulrasool <compnerd@compnerd.org>
Tue, 16 Jun 2015 20:03:47 +0000 (20:03 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Tue, 16 Jun 2015 20:03:47 +0000 (20:03 +0000)
MS attributes do not permit empty attribute blocks.  Correctly diagnose those.
We continue to parse to ensure that we recover correctly.  Because the block is
empty, we do not need to skip any tokens.

Bonus: tweak the comment that I updated but forgot to remove the function name
in a previous commit.

llvm-svn: 239846

clang/include/clang/Basic/DiagnosticParseKinds.td
clang/lib/Parse/ParseDeclCXX.cpp
clang/test/Parser/MicrosoftExtensions.c

index c119c4a..39a0ec8 100644 (file)
@@ -1000,6 +1000,9 @@ def err_pragma_invalid_keyword : Error<
 def warn_pragma_unroll_cuda_value_in_parens : Warning<
   "argument to '#pragma unroll' should not be in parentheses in CUDA C/C++">,
   InGroup<CudaCompat>;
+
+def err_empty_attribute_block : Error<"empty attribute block is not allowed">;
+
 } // end of Parse Issue category.
 
 let CategoryName = "Modules Issue" in {
index 9ed797f..f8992e8 100644 (file)
@@ -3780,7 +3780,7 @@ SourceLocation Parser::SkipCXX11Attributes() {
   return EndLoc;
 }
 
-/// ParseMicrosoftAttributes - Parse Microsoft attributes [Attr]
+/// Parse one or more Microsoft-style attributes [Attr]
 ///
 /// [MS] ms-attribute:
 ///             '[' token-seq ']'
@@ -3796,6 +3796,8 @@ void Parser::ParseMicrosoftAttributes(ParsedAttributes &attrs,
     // FIXME: If this is actually a C++11 attribute, parse it as one.
     BalancedDelimiterTracker T(*this, tok::l_square);
     T.consumeOpen();
+    if (Tok.is(tok::r_square))
+      Diag(T.getOpenLocation(), diag::err_empty_attribute_block);
     SkipUntil(tok::r_square, StopAtSemi | StopBeforeMatch);
     T.consumeClose();
     if (endLoc)
index a29f6c0..be46159 100644 (file)
@@ -55,6 +55,8 @@ int foo1([SA_Post(attr=1)] void *param);
 [unbalanced(attribute) /* expected-note {{to match this '['}} */
 void f(void); /* expected-error {{expected ']'}} */
 
+[] __interface I {}; /* expected-error {{empty attribute block is not allowed}} */
+
 void ms_intrinsics(int a) {
   __noop();
   __assume(a);