[PATCH] PR 19339 - Parser confusion between lambda and designated initializer

Faisal Vali faisalv at yahoo.com
Fri Apr 4 09:17:28 PDT 2014


Hi rsmith, krememek,

http://llvm.org/bugs/show_bug.cgi?id=19339

Here is a reduced test case:

  struct Foo {
    template<class T> Foo(T) {}
  };

  Foo f3 { [i{0}]{} };

The Parser gets confused in bool Parser::MayBeDesignationStart() in trying to distinguish between a lambda or a designated initializer when parsing
[i{0}]

FYI: Sema does not yet implement (recently voted into C++14? or is it C++17 I forget) the proper deduction for one element in a brace initializer yet.


This is a very cursory rough stab (includes a use of goto) at addressing this - just to draw attention to where i think  the problem lies. I will leave it to those who grok the Parser better than me to either help me refine it - or conjure up their own fix.

http://llvm-reviews.chandlerc.com/D3290

Files:
  lib/Parse/ParseInit.cpp

Index: lib/Parse/ParseInit.cpp
===================================================================
--- lib/Parse/ParseInit.cpp
+++ lib/Parse/ParseInit.cpp
@@ -75,11 +75,24 @@
     case tok::amp:
     case tok::identifier:
     case tok::kw_this:
+    case tok::numeric_constant:
       // These tokens can occur in a capture list or a constant-expression.
       // Keep looking.
       ConsumeToken();
       continue;
-      
+
+    case tok::l_brace:
+    case tok::r_brace:
+      if (PP.getLangOpts().CPlusPlus11) {
+        // These tokens can occur in a capture list or a constant-expression.
+        // Keep looking.
+        // Vec{[i{0}]() { }};
+        // int a[10] = { [Literal{}] = 3, 4 };
+        ConsumeBrace();
+        continue;
+      } else {
+        goto default_label;
+      }
     case tok::comma:
       // Since a comma cannot occur in a constant-expression, this must
       // be a lambda.
@@ -99,11 +112,13 @@
     }
       
     default:
+    default_label:
       // Anything else cannot occur in a lambda capture list, so it
       // must be a designator.
       Tentative.Revert();
       return true;
     }
+
   }
 }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3290.1.patch
Type: text/x-patch
Size: 1158 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140404/16b436c4/attachment.bin>


More information about the cfe-commits mailing list