]> granicus.if.org Git - clang/commitdiff
parser: improve diagnostics for MS attributes
authorSaleem Abdulrasool <compnerd@compnerd.org>
Mon, 15 Jun 2015 20:57:04 +0000 (20:57 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Mon, 15 Jun 2015 20:57:04 +0000 (20:57 +0000)
Switch to using BalancedDelimiterTracker to get better diagnostics for
unbalanced delimiters.  This still does not handle any of the attributes, simply
improves the parsing.

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

lib/Parse/ParseDeclCXX.cpp
test/Parser/MicrosoftExtensions.c

index 55909de0928bdf63246faca9f9357c3ff969095d..9ed797f881dc506d3c02d2311dd1f77838a094af 100644 (file)
@@ -3780,7 +3780,7 @@ SourceLocation Parser::SkipCXX11Attributes() {
   return EndLoc;
 }
 
-/// ParseMicrosoftAttributes - Parse a Microsoft attribute [Attr]
+/// ParseMicrosoftAttributes - Parse Microsoft attributes [Attr]
 ///
 /// [MS] ms-attribute:
 ///             '[' token-seq ']'
@@ -3792,13 +3792,15 @@ void Parser::ParseMicrosoftAttributes(ParsedAttributes &attrs,
                                       SourceLocation *endLoc) {
   assert(Tok.is(tok::l_square) && "Not a Microsoft attribute list");
 
-  while (Tok.is(tok::l_square)) {
+  do {
     // FIXME: If this is actually a C++11 attribute, parse it as one.
-    ConsumeBracket();
+    BalancedDelimiterTracker T(*this, tok::l_square);
+    T.consumeOpen();
     SkipUntil(tok::r_square, StopAtSemi | StopBeforeMatch);
-    if (endLoc) *endLoc = Tok.getLocation();
-    ExpectAndConsume(tok::r_square);
-  }
+    T.consumeClose();
+    if (endLoc)
+      *endLoc = T.getCloseLocation();
+  } while (Tok.is(tok::l_square));
 }
 
 void Parser::ParseMicrosoftIfExistsClassDeclaration(DeclSpec::TST TagType,
index 40a9510d6e2443bdeafa5d184cdaf6307bc492b2..a29f6c0b54927a443c71eaed45f795f62eed85c4 100644 (file)
@@ -52,6 +52,9 @@ void deprecated_enum_test(void) {
 [returnvalue:SA_Post( attr=1)]
 int foo1([SA_Post(attr=1)] void *param);
 
+[unbalanced(attribute) /* expected-note {{to match this '['}} */
+void f(void); /* expected-error {{expected ']'}} */
+
 void ms_intrinsics(int a) {
   __noop();
   __assume(a);