From cde3fd87e05cbf1e4f46efce6f8d22105d6f879a Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 4 Jul 2013 00:13:48 +0000 Subject: PR16480: Reimplement token-caching for constructor initializer lists. This previously didn't work if a mem-initializer-id had a template argument which contained parentheses or braces. We now implement a simple rule: just look for a ') {' or '} {' that is not nested. The '{' is assumed to start the function-body. There are still two cases which we misparse, where the ') {' comes from a compound literal or from a lambda. The former case is not valid C++, and the latter will probably not be valid C++ once DR1607 is resolved, so these seem to be of low value, and we do not regress on them with this change. EDG and g++ also misparse both of these cases. llvm-svn: 185598 --- clang/test/Parser/cxx-member-initializers.cpp | 72 +++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 3 deletions(-) (limited to 'clang/test/Parser/cxx-member-initializers.cpp') diff --git a/clang/test/Parser/cxx-member-initializers.cpp b/clang/test/Parser/cxx-member-initializers.cpp index 5c3906836c4..ff8c880a184 100644 --- a/clang/test/Parser/cxx-member-initializers.cpp +++ b/clang/test/Parser/cxx-member-initializers.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s struct x { x() : a(4) ; // expected-error {{expected '{'}} @@ -11,5 +11,71 @@ struct y { struct z { int a; - z() : a {} // expected-error {{expected '('}} -}; + z() : a {} +}; // expected-error {{expected '{'}} + +namespace PR16480 { + template struct X { + X(); + X(int); + }; + + struct A : X<0> { + A() : X{0}.n>() {} + + template struct a { + int n; + }; + + static const int b = 1; + }; + + struct B : X<0> { + B() : X{0} {} + + static const int a = 0, b = 0; + }; + + template struct a { + constexpr a(int) {} + constexpr operator int() const { return 0; } + }; + + struct C : X<0> { + C() : X(0)>() {} + + static const int b = 0; + }; + + struct D : X<0> { + D() : X(0) {} + + static const int a = 0, b = 0; + }; + + template struct E : X<0> { + E(X<0>) : X<(0)>{} {} + E(X<1>) : X{} {} + E(X<2>) : X<(0)>() {} + E(X<3>) : X() {} + }; + + // FIXME: This should be valid in the union of C99 and C++11. + struct F : X<0> { + F() : X().n + (T){}.n>{} {} // expected-error +{{}} + + struct T { int n; }; + template struct A { int n; }; + }; // expected-error +{{}} + + // FIXME: This is valid now, but may be made ill-formed by DR1607. + struct G : X<0> { + G() : X<0 && [](){return 0;}()>{} // expected-error +{{}} + }; // expected-error +{{}} + + struct Errs : X<0> { + Errs(X<0>) : decltype X<0>() {} // expected-error {{expected '(' after 'decltype'}} + Errs(X<1>) : what is this () {} // expected-error {{expected '(' or '{'}} + Errs(X<2>) : decltype(X<0> // expected-note {{to match this '('}} + }; // expected-error {{expected ')'}} +} -- cgit v1.2.3