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

Richard Smith richard at metafoo.co.uk
Sat Apr 12 21:41:31 PDT 2014


On Fri, Apr 4, 2014 at 9:17 AM, Faisal Vali <faisalv at yahoo.com> wrote:

> 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.
>

It's not been voted into anything yet, but I agree we should probably go
ahead with this sooner rather than later.

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.
>

I fixed it by changing it to reuse the correct lambda recognition code we
already have elsewhere (rather than inventing its own disambiguation
logic), in r206128.


> 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 --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140412/5f337e34/attachment.html>


More information about the cfe-commits mailing list