llvm-project
312 строк · 7.7 Кб
1// RUN: %clang_cc1 -verify -fsyntax-only -triple i386-linux -Wredundant-parens -pedantic-errors -fcxx-exceptions -fexceptions %s
2// RUN: %clang_cc1 -verify -fsyntax-only -triple i386-linux -Wredundant-parens -pedantic-errors -fcxx-exceptions -fexceptions -std=c++98 %s
3// RUN: %clang_cc1 -verify -fsyntax-only -triple i386-linux -Wredundant-parens -pedantic-errors -fcxx-exceptions -fexceptions -std=c++11 %s
4
5const char const *x10; // expected-error {{duplicate 'const' declaration specifier}}6
7int x(*g); // expected-error {{use of undeclared identifier 'g'}}8
9private int cplusplus_is_not_opencl; // expected-error {{expected unqualified-id}}10
11struct Type {12int Type;13};14
15typedef char bool; // expected-error {{redeclaration of C++ built-in type 'bool'}}16
17// PR4451 - We should recover well from the typo of '::' as ':' in a2.
18namespace y {19struct a { };20typedef int b;21}
22
23y::a a1;24y:a a2; // expected-error {{unexpected ':' in nested name specifier}}25y::a a3 = a2;26
27// Some valid colons:
28void foo() {29y: // label30y::a s;31
32int a = 4;33a = a ? a : a+1;34}
35
36struct b : y::a {};37
38template <typename T>39class someclass {40
41int bar() {42T *P;43return 1 ? P->x : P->y;44}45};46
47class asm_class_test {48void foo() __asm__("baz");49};50
51enum { fooenum = 1, };52#if __cplusplus <= 199711L53// expected-error@-2 {{commas at the end of enumerator lists are a C++11 extension}}
54#endif55
56struct a {57int Type : fooenum;58};59
60void test(struct Type *P) {61int Type;62Type = 1 ? P->Type : Type;63
64Type = (y:b) 4; // expected-error {{unexpected ':' in nested name specifier}}65Type = 1 ? (66(y:b) // expected-error {{unexpected ':' in nested name specifier}}674) : 5;68}
69
70struct test4 {71int x // expected-error {{expected ';' at end of declaration list}}72int y;73int z // expected-error {{expected ';' at end of declaration list}}74};75
76// Make sure we know these are legitimate commas and not typos for ';'.
77namespace Commas {78struct S {79static int a;80int c,81operator()();82};83
84int global1,85__attribute__(()) global2,86(global5), // expected-warning {{redundant parentheses surrounding declarator}}87*global6,88&global7 = global1,89&&global8 = static_cast<int&&>(global1),90#if __cplusplus <= 199711L91// expected-error@-2 2{{rvalue references are a C++11 extension}}92#endif93
94S::a,95global9,96global10 = 0,97global11 == 0, // expected-error {{did you mean '='}}98global12 __attribute__(()),99global13(0),100global14[2],101global15;102
103void g() {104static int a,105b __asm__("ebx"), // expected-error {{expected ';' at end of declaration}}106Statics:return;107}108}
109
110// PR5825
111struct test5 {};112::new(static_cast<void*>(0)) test5; // expected-error {{expected unqualified-id}}113
114
115// PR6782
116template<class T>117class Class1;118
119class Class2 {120} // expected-error {{expected ';' after class}}121
122typedef Class1<Class2> Type1;123
124struct CodeCompleteConsumer {125};126
127void CodeCompleteConsumer::() { // expected-error {{xpected unqualified-id}}128}
129
130;
131
132// PR4111
133void f(sqrgl); // expected-error {{unknown type name 'sqrgl'}}134
135// PR9903
136struct S {137typedef void a() { }; // expected-error {{function definition declared 'typedef'}}138typedef void c() try { } catch(...) { } // expected-error {{function definition declared 'typedef'}}139int n, m;140typedef S() : n(1), m(2) { } // expected-error {{function definition declared 'typedef'}}141};142
143
144namespace TestIsValidAfterTypeSpecifier {145struct s {} v;146
147namespace a {148struct s operator++(struct s a)149{ return a; }150}
151
152namespace b {153// The newline after s should make no difference.
154struct s155operator++(struct s a)156{ return a; }157}
158
159struct X {160struct s161friend f();162struct s163virtual f();164};165
166struct s167&r0 = v;168struct s169bitand r2 = v;170
171}
172
173struct DIE {174void foo() {}175};176
177void test (DIE die, DIE *Die, DIE INT, DIE *FLOAT) {178DIE.foo(); // expected-error {{cannot use dot operator on a type}}179die.foo();180
181DIE->foo(); // expected-error {{cannot use arrow operator on a type}}182Die->foo();183
184int.foo(); // expected-error {{cannot use dot operator on a type}}185INT.foo();186
187float->foo(); // expected-error {{cannot use arrow operator on a type}}188FLOAT->foo();189}
190
191namespace PR15017 {192template<typename T = struct X { int i; }> struct S {}; // expected-error {{'PR15017::X' cannot be defined in a type specifier}}193}
194
195// Ensure we produce at least some diagnostic for attributes in C++98.
196[[]] struct S; // expected-error {{misplaced attributes}}197#if __cplusplus < 201103L198// expected-error@-2 {{[[]] attributes are a C++11 extension}}
199#endif200
201namespace test7 {202struct Foo {203void a();204void b();205};206
207void Foo::208// Comment!209a() {}210
211
212void Foo:: // expected-error {{expected unqualified-id}}213// Comment!214}
215
216void test8() {217struct {} o;218// This used to crash.219(&o)->(); // expected-error{{expected unqualified-id}}220}
221
222namespace PR5066 {223template<typename T> struct X {};224X<int N> x; // expected-error {{type-id cannot have a name}}225
226using T = int (*T)(); // expected-error {{type-id cannot have a name}}227#if __cplusplus <= 199711L228// expected-error@-2 {{alias declarations are a C++11 extensio}}229#endif230
231}
232
233namespace PR17255 {234void foo() {235typename A::template B<> c; // expected-error {{use of undeclared identifier 'A'}}236#if __cplusplus <= 199711L237// expected-error@-2 {{'template' keyword outside of a template}}238#endif239}
240}
241
242namespace PR17567 {243struct Foobar { // expected-note 2{{declared here}}244FooBar(); // expected-error {{missing return type for function 'FooBar'; did you mean the constructor name 'Foobar'?}}245~FooBar(); // expected-error {{undeclared identifier 'FooBar' in destructor name}}246};247FooBar::FooBar() {} // expected-error {{undeclared}} expected-error {{missing return type}}248FooBar::~FooBar() {} // expected-error 2{{undeclared}}249}
250
251namespace DuplicateFriend {252struct A {253friend void friend f(); // expected-warning {{duplicate 'friend' declaration specifier}}254friend struct B friend; // expected-warning {{duplicate 'friend' declaration specifier}}255};256}
257
258namespace NNS {259struct A {};260namespace B { extern A C1, C2, *C3, C4[], C5; }261// Do not produce a redundant parentheses warning here; removing these parens262// changes the meaning of the program.263A (::NNS::B::C1);264A (NNS::B::C2); // expected-warning {{redundant parentheses surrounding declarator}}265A (*::NNS::B::C3); // expected-warning {{redundant parentheses surrounding declarator}}266A (::NNS::B::C4[2]);267// Removing one of these sets of parentheses would be reasonable.268A ((::NNS::B::C5)); // expected-warning {{redundant parentheses surrounding declarator}}269
270void f() {271// FIXME: A vexing-parse warning here would be useful.272A(::NNS::B::C1); // expected-error {{definition or redeclaration}}273A(NNS::B::C1); // expected-warning {{redundant paren}} expected-error {{definition or redeclaration}}274}275}
276
277inline namespace ParensAroundFriend { // expected-error 0-1{{C++11}}278struct A {};279struct B {280static A C();281};282namespace X {283struct B {};284struct D {285// No warning here: while this could be written as286// friend (::B::C)();287// we do need parentheses *somewhere* here.288friend A (::B::C());289};290}291}
292
293namespace rdar37099386 {294class A typename A; // expected-error {{expected a qualified name after 'typename'}}295// expected-error@-1 {{cannot combine with previous 'class' declaration specifier}}296}
297
298// PR8380
299extern "" // expected-error {{unknown linkage language}}300test6a { ;// expected-error {{a type specifier is required for all declarations}}301#if __cplusplus <= 199711L302// expected-error@-2 {{expected ';' after top level declarator}}
303#else304// expected-error@-4 {{expected expression}}
305// expected-note@-5 {{to match this}}
306#endif307
308int test6b;309#if __cplusplus >= 201103L310// expected-error@+3 {{expected}}
311// expected-error@-3 {{expected ';' after top level declarator}}
312#endif313
314