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
5 const char const *x10
; // expected-error {{duplicate 'const' declaration specifier}}
7 int x(*g
); // expected-error {{use of undeclared identifier 'g'}}
9 private int cplusplus_is_not_opencl
; // expected-error {{expected unqualified-id}}
15 typedef char bool; // expected-error {{redeclaration of C++ built-in type 'bool'}}
17 // PR4451 - We should recover well from the typo of '::' as ':' in a2.
24 y
:a a2
; // expected-error {{unexpected ':' in nested name specifier}}
43 return 1 ? P
->x
: P
->y
;
47 class asm_class_test
{
48 void foo() __asm__("baz");
51 enum { fooenum
= 1, };
52 #if __cplusplus <= 199711L
53 // expected-error@-2 {{commas at the end of enumerator lists are a C++11 extension}}
60 void test(struct Type
*P
) {
62 Type
= 1 ? P
->Type
: Type
;
64 Type
= (y
:b
) 4; // expected-error {{unexpected ':' in nested name specifier}}
66 (y
:b
) // expected-error {{unexpected ':' in nested name specifier}}
71 int x
// expected-error {{expected ';' at end of declaration list}}
73 int z
// expected-error {{expected ';' at end of declaration list}}
76 // Make sure we know these are legitimate commas and not typos for ';'.
85 __attribute__(()) global2
,
86 (global5
), // expected-warning {{redundant parentheses surrounding declarator}}
89 &&global8
= static_cast<int&&>(global1
),
90 #if __cplusplus <= 199711L
91 // expected-error@-2 2{{rvalue references are a C++11 extension}}
97 global11
== 0, // expected-error {{did you mean '='}}
98 global12
__attribute__(()),
105 b
__asm__("ebx"), // expected-error {{expected ';' at end of declaration}}
112 ::new(static_cast<void*>(0)) test5
; // expected-error {{expected unqualified-id}}
120 } // expected-error {{expected ';' after class}}
122 typedef Class1
<Class2
> Type1
;
124 struct CodeCompleteConsumer
{
127 void CodeCompleteConsumer::() { // expected-error {{xpected unqualified-id}}
133 void f(sqrgl
); // expected-error {{unknown type name 'sqrgl'}}
137 typedef void a() { }; // expected-error {{function definition declared 'typedef'}}
138 typedef void c() try { } catch(...) { } // expected-error {{function definition declared 'typedef'}}
140 typedef S() : n(1), m(2) { } // expected-error {{function definition declared 'typedef'}}
144 namespace TestIsValidAfterTypeSpecifier
{
148 struct s
operator++(struct s a
)
153 // The newline after s should make no difference.
155 operator++(struct s a
)
177 void test (DIE die
, DIE
*Die
, DIE INT
, DIE
*FLOAT
) {
178 DIE
.foo(); // expected-error {{cannot use dot operator on a type}}
181 DIE
->foo(); // expected-error {{cannot use arrow operator on a type}}
184 int.foo(); // expected-error {{cannot use dot operator on a type}}
187 float->foo(); // expected-error {{cannot use arrow operator on a type}}
192 template<typename T
= struct X
{ int i
; }> struct S
{}; // expected-error {{'PR15017::X' cannot be defined in a type specifier}}
195 // Ensure we produce at least some diagnostic for attributes in C++98.
196 [[]] struct S
; // expected-error {{misplaced attributes}}
197 #if __cplusplus < 201103L
198 // expected-error@-2 {{[[]] attributes are a C++11 extension}}
212 void Foo:: // expected-error {{expected unqualified-id}}
218 // This used to crash.
219 (&o
)->(); // expected-error{{expected unqualified-id}}
223 template<typename T
> struct X
{};
224 X
<int N
> x
; // expected-error {{type-id cannot have a name}}
226 using T
= int (*T
)(); // expected-error {{type-id cannot have a name}}
227 #if __cplusplus <= 199711L
228 // expected-error@-2 {{alias declarations are a C++11 extensio}}
235 typename
A::template B
<> c
; // expected-error {{use of undeclared identifier 'A'}}
236 #if __cplusplus <= 199711L
237 // expected-error@-2 {{'template' keyword outside of a template}}
243 struct Foobar
{ // expected-note 2{{declared here}}
244 FooBar(); // 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}}
247 FooBar::FooBar() {} // expected-error {{undeclared}} expected-error {{missing return type}}
248 FooBar::~FooBar() {} // expected-error 2{{undeclared}}
251 namespace DuplicateFriend
{
253 friend void friend f(); // expected-warning {{duplicate 'friend' declaration specifier}}
254 friend struct B
friend; // expected-warning {{duplicate 'friend' declaration specifier}}
260 namespace B
{ extern A C1
, C2
, *C3
, C4
[], C5
; }
261 // Do not produce a redundant parentheses warning here; removing these parens
262 // changes the meaning of the program.
264 A (NNS::B::C2
); // expected-warning {{redundant parentheses surrounding declarator}}
265 A (*::NNS::B::C3
); // expected-warning {{redundant parentheses surrounding declarator}}
267 // Removing one of these sets of parentheses would be reasonable.
268 A ((::NNS::B::C5
)); // expected-warning {{redundant parentheses surrounding declarator}}
271 // FIXME: A vexing-parse warning here would be useful.
272 A(::NNS::B::C1
); // expected-error {{definition or redeclaration}}
273 A(NNS::B::C1
); // expected-warning {{redundant paren}} expected-error {{definition or redeclaration}}
277 inline namespace ParensAroundFriend
{ // expected-error 0-1{{C++11}}
285 // No warning here: while this could be written as
286 // friend (::B::C)();
287 // we do need parentheses *somewhere* here.
293 namespace rdar37099386
{
294 class A typename A
; // expected-error {{expected a qualified name after 'typename'}}
295 // expected-error@-1 {{cannot combine with previous 'class' declaration specifier}}
299 extern "" // expected-error {{unknown linkage language}}
300 test6a
{ ;// expected-error {{a type specifier is required for all declarations}}
301 #if __cplusplus <= 199711L
302 // expected-error@-2 {{expected ';' after top level declarator}}
304 // expected-error@-4 {{expected expression}}
305 // expected-note@-5 {{to match this}}
309 #if __cplusplus >= 201103L
310 // expected-error@+3 {{expected}}
311 // expected-error@-3 {{expected ';' after top level declarator}}