r177480 - Teach statement / declaration disambiguation about C++11-style generalized initializers.

Richard Smith richard-llvm at metafoo.co.uk
Tue Mar 19 20:35:03 PDT 2013


Author: rsmith
Date: Tue Mar 19 22:35:02 2013
New Revision: 177480

URL: http://llvm.org/viewvc/llvm-project?rev=177480&view=rev
Log:
Teach statement / declaration disambiguation about C++11-style generalized initializers.

Modified:
    cfe/trunk/lib/Parse/ParseTentative.cpp
    cfe/trunk/test/Parser/cxx0x-ambig.cpp

Modified: cfe/trunk/lib/Parse/ParseTentative.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTentative.cpp?rev=177480&r1=177479&r2=177480&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseTentative.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTentative.cpp Tue Mar 19 22:35:02 2013
@@ -184,6 +184,9 @@ Parser::TPResult Parser::TryParseSimpleD
   return TPResult::Ambiguous();
 }
 
+/// Tentatively parse an init-declarator-list in order to disambiguate it from
+/// an expression.
+///
 ///       init-declarator-list:
 ///         init-declarator
 ///         init-declarator-list ',' init-declarator
@@ -192,14 +195,21 @@ Parser::TPResult Parser::TryParseSimpleD
 ///         declarator initializer[opt]
 /// [GNU]   declarator simple-asm-expr[opt] attributes[opt] initializer[opt]
 ///
-/// initializer:
-///   '=' initializer-clause
-///   '(' expression-list ')'
-///
-/// initializer-clause:
-///   assignment-expression
-///   '{' initializer-list ','[opt] '}'
-///   '{' '}'
+///       initializer:
+///         brace-or-equal-initializer
+///         '(' expression-list ')'
+///
+///       brace-or-equal-initializer:
+///         '=' initializer-clause
+/// [C++11] braced-init-list
+///
+///       initializer-clause:
+///         assignment-expression
+///         braced-init-list
+///
+///       braced-init-list:
+///         '{' initializer-list ','[opt] '}'
+///         '{' '}'
 ///
 Parser::TPResult Parser::TryParseInitDeclaratorList() {
   while (1) {
@@ -218,6 +228,10 @@ Parser::TPResult Parser::TryParseInitDec
       ConsumeParen();
       if (!SkipUntil(tok::r_paren))
         return TPResult::Error();
+    } else if (Tok.is(tok::l_brace)) {
+      // A left-brace here is sufficient to disambiguate the parse; an
+      // expression can never be followed directly by a braced-init-list.
+      return TPResult::True();
     } else if (Tok.is(tok::equal) || isTokIdentifier_in()) {
       // MSVC and g++ won't examine the rest of declarators if '=' is 
       // encountered; they just conclude that we have a declaration.

Modified: cfe/trunk/test/Parser/cxx0x-ambig.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx0x-ambig.cpp?rev=177480&r1=177479&r2=177480&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx0x-ambig.cpp (original)
+++ cfe/trunk/test/Parser/cxx0x-ambig.cpp Tue Mar 19 22:35:02 2013
@@ -133,3 +133,19 @@ namespace ellipsis {
     void l(int(S<int>::*...)(T)); // expected-warning {{ISO C++11 requires a parenthesized pack declaration to have a name}}
   };
 }
+
+namespace braced_init_list {
+  struct X {
+    void foo() {}
+  };
+
+  void (*pf1)() {};
+  void (X::*pmf1)() {&X::foo};
+  void (X::*pmf2)() = {&X::foo};
+
+  void test() {
+    void (*pf2)() {};
+    void (X::*pmf3)() {&X::foo};
+    void (X::*pmf4)() = {&X::foo};
+  }
+}





More information about the cfe-commits mailing list