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