xref: /minix3/external/bsd/llvm/dist/clang/test/Parser/cxx0x-member-initializers.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc // Make sure we don't run off the end of the stream when parsing a deferred
4*f4a2713aSLionel Sambuc // initializer.
5*f4a2713aSLionel Sambuc int a; // expected-note {{previous}}
6*f4a2713aSLionel Sambuc struct S {
7*f4a2713aSLionel Sambuc   int n = 4 + ; // expected-error {{expected expression}}
8*f4a2713aSLionel Sambuc } a; // expected-error {{redefinition}}
9*f4a2713aSLionel Sambuc 
10*f4a2713aSLionel Sambuc // Make sure we use all of the tokens.
11*f4a2713aSLionel Sambuc struct T {
12*f4a2713aSLionel Sambuc   int a = 1 // expected-error {{expected ';' at end of declaration list}}
13*f4a2713aSLionel Sambuc   int b = 2;
14*f4a2713aSLionel Sambuc   int c = b; // expected-error {{undeclared identifier}}
15*f4a2713aSLionel Sambuc };
16*f4a2713aSLionel Sambuc 
17*f4a2713aSLionel Sambuc // Test recovery for bad constructor initializers
18*f4a2713aSLionel Sambuc 
19*f4a2713aSLionel Sambuc struct R1 {
20*f4a2713aSLionel Sambuc   int a;
21*f4a2713aSLionel Sambuc   R1() : a {}
22*f4a2713aSLionel Sambuc }; // expected-error {{expected '{' or ','}}
23*f4a2713aSLionel Sambuc 
24*f4a2713aSLionel Sambuc // Test correct parsing.
25*f4a2713aSLionel Sambuc 
26*f4a2713aSLionel Sambuc struct V1 {
27*f4a2713aSLionel Sambuc   int a, b;
28*f4a2713aSLionel Sambuc   V1() : a(), b{} {}
29*f4a2713aSLionel Sambuc };
30*f4a2713aSLionel Sambuc 
31*f4a2713aSLionel Sambuc template <typename, typename> struct T1 { enum {V};};
32*f4a2713aSLionel Sambuc template <int, int> struct T2 { enum {V};};
33*f4a2713aSLionel Sambuc struct A {
34*f4a2713aSLionel Sambuc   T1<int, int> a1 = T1<int, int>(), *a2 = new T1<int,int>;
35*f4a2713aSLionel Sambuc   T2<0,0> b1 = T2<0,0>(), b2 = T2<0,0>(), b3;
36*f4a2713aSLionel Sambuc   bool c1 = 1 < 2, c2 = 2 < 1, c3 = false;
37*f4a2713aSLionel Sambuc   bool d1 = T1<int, T1<int, int>>::V < 3, d2;
38*f4a2713aSLionel Sambuc   T1<int, int()> e = T1<int, int()>();
39*f4a2713aSLionel Sambuc };
40