2014-01-11 05:27:55 +08:00
|
|
|
// RUN: %clang_cc1 -verify -fsyntax-only -triple i386-linux -pedantic-errors -fcxx-exceptions -fexceptions %s
|
2009-04-13 06:23:27 +08:00
|
|
|
|
2014-01-11 05:27:55 +08:00
|
|
|
const char const *x10; // expected-error {{duplicate 'const' declaration specifier}}
|
2012-08-29 04:55:40 +08:00
|
|
|
|
2009-04-13 06:23:27 +08:00
|
|
|
int x(*g); // expected-error {{use of undeclared identifier 'g'}}
|
2009-12-07 09:36:53 +08:00
|
|
|
|
2009-12-10 10:02:58 +08:00
|
|
|
struct Type {
|
|
|
|
int Type;
|
|
|
|
};
|
2009-12-10 09:59:24 +08:00
|
|
|
|
2010-11-17 02:18:13 +08:00
|
|
|
// rdar://8365458
|
2011-04-20 05:42:37 +08:00
|
|
|
// rdar://9132143
|
|
|
|
typedef char bool; // expected-error {{redeclaration of C++ built-in type 'bool'}}
|
2009-12-07 09:36:53 +08:00
|
|
|
|
|
|
|
// PR4451 - We should recover well from the typo of '::' as ':' in a2.
|
|
|
|
namespace y {
|
2009-12-10 10:08:07 +08:00
|
|
|
struct a { };
|
|
|
|
typedef int b;
|
2009-12-07 09:36:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
y::a a1;
|
|
|
|
y:a a2; // expected-error {{unexpected ':' in nested name specifier}}
|
|
|
|
y::a a3 = a2;
|
|
|
|
|
|
|
|
// Some valid colons:
|
|
|
|
void foo() {
|
|
|
|
y: // label
|
|
|
|
y::a s;
|
|
|
|
|
|
|
|
int a = 4;
|
|
|
|
a = a ? a : a+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct b : y::a {};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
class someclass {
|
|
|
|
|
|
|
|
int bar() {
|
|
|
|
T *P;
|
|
|
|
return 1 ? P->x : P->y;
|
|
|
|
}
|
|
|
|
};
|
2009-12-10 09:59:24 +08:00
|
|
|
|
2010-06-13 13:34:18 +08:00
|
|
|
class asm_class_test {
|
|
|
|
void foo() __asm__("baz");
|
|
|
|
};
|
|
|
|
|
2014-01-11 05:27:55 +08:00
|
|
|
enum { fooenum = 1, }; // expected-error {{commas at the end of enumerator lists are a C++11 extension}}
|
2009-12-10 09:59:24 +08:00
|
|
|
|
|
|
|
struct a {
|
|
|
|
int Type : fooenum;
|
|
|
|
};
|
|
|
|
|
2009-12-10 10:02:58 +08:00
|
|
|
void test(struct Type *P) {
|
|
|
|
int Type;
|
|
|
|
Type = 1 ? P->Type : Type;
|
2009-12-10 10:08:07 +08:00
|
|
|
|
|
|
|
Type = (y:b) 4; // expected-error {{unexpected ':' in nested name specifier}}
|
|
|
|
Type = 1 ? (
|
|
|
|
(y:b) // expected-error {{unexpected ':' in nested name specifier}}
|
|
|
|
4) : 5;
|
2009-12-16 04:14:24 +08:00
|
|
|
}
|
2010-02-02 08:43:15 +08:00
|
|
|
|
|
|
|
struct test4 {
|
|
|
|
int x // expected-error {{expected ';' at end of declaration list}}
|
|
|
|
int y;
|
|
|
|
int z // expected-error {{expected ';' at end of declaration list}}
|
|
|
|
};
|
2010-03-02 02:20:46 +08:00
|
|
|
|
2011-10-20 05:33:05 +08:00
|
|
|
// Make sure we know these are legitimate commas and not typos for ';'.
|
|
|
|
namespace Commas {
|
|
|
|
struct S {
|
|
|
|
static int a;
|
|
|
|
int c,
|
|
|
|
operator()();
|
|
|
|
};
|
|
|
|
|
|
|
|
int global1,
|
|
|
|
__attribute__(()) global2,
|
|
|
|
(global5),
|
|
|
|
*global6,
|
|
|
|
&global7 = global1,
|
2014-01-11 05:27:55 +08:00
|
|
|
&&global8 = static_cast<int&&>(global1), // expected-error 2{{rvalue reference}}
|
2011-10-20 05:33:05 +08:00
|
|
|
S::a,
|
|
|
|
global9,
|
|
|
|
global10 = 0,
|
|
|
|
global11 == 0, // expected-error {{did you mean '='}}
|
|
|
|
global12 __attribute__(()),
|
|
|
|
global13(0),
|
|
|
|
global14[2],
|
|
|
|
global15;
|
|
|
|
|
|
|
|
void g() {
|
|
|
|
static int a,
|
|
|
|
b __asm__("ebx"), // expected-error {{expected ';' at end of declaration}}
|
|
|
|
Statics:return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-02 02:20:46 +08:00
|
|
|
// PR5825
|
|
|
|
struct test5 {};
|
|
|
|
::new(static_cast<void*>(0)) test5; // expected-error {{expected unqualified-id}}
|
2010-04-06 02:18:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
// PR6782
|
|
|
|
template<class T>
|
|
|
|
class Class1;
|
|
|
|
|
|
|
|
class Class2 {
|
2013-11-20 06:47:36 +08:00
|
|
|
} // expected-error {{expected ';' after class}}
|
2010-04-06 02:18:31 +08:00
|
|
|
|
2013-11-20 06:47:36 +08:00
|
|
|
typedef Class1<Class2> Type1;
|
2010-08-17 01:58:53 +08:00
|
|
|
|
|
|
|
// rdar : // 8307865
|
|
|
|
struct CodeCompleteConsumer {
|
|
|
|
};
|
|
|
|
|
|
|
|
void CodeCompleteConsumer::() { // expected-error {{xpected unqualified-id}}
|
|
|
|
}
|
2010-11-10 04:14:26 +08:00
|
|
|
|
|
|
|
;
|
|
|
|
|
2012-08-18 08:55:03 +08:00
|
|
|
// PR4111
|
|
|
|
void f(sqrgl); // expected-error {{unknown type name 'sqrgl'}}
|
|
|
|
|
2012-11-16 06:54:20 +08:00
|
|
|
// PR9903
|
|
|
|
struct S {
|
|
|
|
typedef void a() { }; // expected-error {{function definition declared 'typedef'}}
|
|
|
|
typedef void c() try { } catch(...) { } // expected-error {{function definition declared 'typedef'}}
|
|
|
|
int n, m;
|
|
|
|
typedef S() : n(1), m(2) { } // expected-error {{function definition declared 'typedef'}}
|
|
|
|
};
|
|
|
|
|
2013-01-19 02:41:42 +08:00
|
|
|
|
|
|
|
namespace TestIsValidAfterTypeSpecifier {
|
2013-01-19 11:48:05 +08:00
|
|
|
struct s {} v;
|
2013-01-19 02:41:42 +08:00
|
|
|
|
|
|
|
namespace a {
|
|
|
|
struct s operator++(struct s a)
|
|
|
|
{ return a; }
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace b {
|
|
|
|
// The newline after s should make no difference.
|
|
|
|
struct s
|
|
|
|
operator++(struct s a)
|
|
|
|
{ return a; }
|
|
|
|
}
|
|
|
|
|
2013-01-19 11:48:05 +08:00
|
|
|
struct X {
|
|
|
|
struct s
|
|
|
|
friend f();
|
|
|
|
struct s
|
|
|
|
virtual f();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct s
|
|
|
|
&r0 = v;
|
|
|
|
struct s
|
|
|
|
bitand r2 = v;
|
|
|
|
|
2013-01-19 02:41:42 +08:00
|
|
|
}
|
|
|
|
|
2013-01-26 10:31:38 +08:00
|
|
|
struct DIE {
|
|
|
|
void foo() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
void test (DIE die, DIE *Die, DIE INT, DIE *FLOAT) {
|
|
|
|
DIE.foo(); // expected-error {{cannot use dot operator on a type}}
|
|
|
|
die.foo();
|
|
|
|
|
|
|
|
DIE->foo(); // expected-error {{cannot use arrow operator on a type}}
|
|
|
|
Die->foo();
|
|
|
|
|
|
|
|
int.foo(); // expected-error {{cannot use dot operator on a type}}
|
|
|
|
INT.foo();
|
|
|
|
|
|
|
|
float->foo(); // expected-error {{cannot use arrow operator on a type}}
|
|
|
|
FLOAT->foo();
|
|
|
|
}
|
|
|
|
|
2013-01-29 12:13:32 +08:00
|
|
|
namespace PR15017 {
|
2014-03-08 06:36:23 +08:00
|
|
|
template<typename T = struct X { int i; }> struct S {}; // expected-error {{'PR15017::X' cannot be defined in a type specifier}}
|
2013-01-29 12:13:32 +08:00
|
|
|
}
|
|
|
|
|
2013-02-22 17:15:49 +08:00
|
|
|
// Ensure we produce at least some diagnostic for attributes in C++98.
|
|
|
|
[[]] struct S; // expected-error 2{{}}
|
|
|
|
|
2013-09-05 10:31:33 +08:00
|
|
|
namespace test7 {
|
|
|
|
struct Foo {
|
|
|
|
void a();
|
|
|
|
void b();
|
|
|
|
};
|
|
|
|
|
|
|
|
void Foo::
|
|
|
|
// Comment!
|
|
|
|
a() {}
|
|
|
|
|
|
|
|
|
|
|
|
void Foo:: // expected-error {{expected unqualified-id}}
|
|
|
|
// Comment!
|
|
|
|
}
|
|
|
|
|
2013-10-10 20:24:40 +08:00
|
|
|
void test8() {
|
|
|
|
struct {} o;
|
|
|
|
// This used to crash.
|
|
|
|
(&o)->(); // expected-error{{expected unqualified-id}}
|
|
|
|
}
|
|
|
|
|
2013-07-11 13:10:21 +08:00
|
|
|
namespace PR5066 {
|
|
|
|
template<typename T> struct X {};
|
|
|
|
X<int N> x; // expected-error {{type-id cannot have a name}}
|
|
|
|
|
2014-01-11 05:27:55 +08:00
|
|
|
using T = int (*T)(); // expected-error {{type-id cannot have a name}} expected-error {{C++11}}
|
2013-07-11 13:10:21 +08:00
|
|
|
}
|
|
|
|
|
2013-09-22 09:24:26 +08:00
|
|
|
namespace PR17255 {
|
|
|
|
void foo() {
|
|
|
|
typename A::template B<>; // expected-error {{use of undeclared identifier 'A'}} \
|
|
|
|
// expected-error {{expected a qualified name after 'typename'}} \
|
2014-01-11 05:27:55 +08:00
|
|
|
// expected-error {{'template' keyword outside of a template}}
|
2013-09-22 09:24:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-15 08:00:26 +08:00
|
|
|
namespace PR17567 {
|
|
|
|
struct Foobar { // expected-note 2{{declared here}}
|
|
|
|
FooBar(); // expected-error {{missing return type for function 'FooBar'; did you mean the constructor name 'Foobar'?}}
|
|
|
|
~FooBar(); // expected-error {{expected the class name after '~' to name a destructor}}
|
|
|
|
};
|
|
|
|
FooBar::FooBar() {} // expected-error {{undeclared}} expected-error {{missing return type}}
|
|
|
|
FooBar::~FooBar() {} // expected-error {{undeclared}} expected-error {{expected the class name}}
|
|
|
|
}
|
|
|
|
|
2014-01-11 05:27:55 +08:00
|
|
|
namespace DuplicateFriend {
|
|
|
|
struct A {
|
|
|
|
friend void friend f(); // expected-warning {{duplicate 'friend' declaration specifier}}
|
|
|
|
friend struct B friend; // expected-warning {{duplicate 'friend' declaration specifier}}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2010-11-10 04:14:26 +08:00
|
|
|
// PR8380
|
|
|
|
extern "" // expected-error {{unknown linkage language}}
|
|
|
|
test6a { ;// expected-error {{C++ requires a type specifier for all declarations}} \
|
|
|
|
// expected-error {{expected ';' after top level declarator}}
|
|
|
|
|
|
|
|
int test6b;
|