summaryrefslogtreecommitdiffstats
path: root/clang/test/Parser/cxx-member-initializers.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2013-07-04 00:13:48 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2013-07-04 00:13:48 +0000
commitcde3fd87e05cbf1e4f46efce6f8d22105d6f879a (patch)
tree4e46c3f40c0df4a09c10dbe15a37c9037cd50f5a /clang/test/Parser/cxx-member-initializers.cpp
parent5b2ef2b1a6d6d29c590c8fee1fac0d49068d9b41 (diff)
downloadbcm5719-llvm-cde3fd87e05cbf1e4f46efce6f8d22105d6f879a.tar.gz
bcm5719-llvm-cde3fd87e05cbf1e4f46efce6f8d22105d6f879a.zip
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
Diffstat (limited to 'clang/test/Parser/cxx-member-initializers.cpp')
-rw-r--r--clang/test/Parser/cxx-member-initializers.cpp72
1 files changed, 69 insertions, 3 deletions
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<int n> struct X {
+ X();
+ X(int);
+ };
+
+ struct A : X<0> {
+ A() : X<a<b>{0}.n>() {}
+
+ template<int> struct a {
+ int n;
+ };
+
+ static const int b = 1;
+ };
+
+ struct B : X<0> {
+ B() : X<a<b>{0} {}
+
+ static const int a = 0, b = 0;
+ };
+
+ template<int> struct a {
+ constexpr a(int) {}
+ constexpr operator int() const { return 0; }
+ };
+
+ struct C : X<0> {
+ C() : X<a<b>(0)>() {}
+
+ static const int b = 0;
+ };
+
+ struct D : X<0> {
+ D() : X<a<b>(0) {}
+
+ static const int a = 0, b = 0;
+ };
+
+ template<typename T> struct E : X<0> {
+ E(X<0>) : X<(0)>{} {}
+ E(X<1>) : X<int{}>{} {}
+ E(X<2>) : X<(0)>() {}
+ E(X<3>) : X<int{}>() {}
+ };
+
+ // FIXME: This should be valid in the union of C99 and C++11.
+ struct F : X<0> {
+ F() : X<A<T>().n + (T){}.n>{} {} // expected-error +{{}}
+
+ struct T { int n; };
+ template<typename> 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 ')'}}
+}
OpenPOWER on IntegriCloud