blob: 994104fc9dfbb1601ff23e680651a43ae73063bf [file] [log] [blame]
Richard Smith3a0f7ac2013-04-13 00:34:48 +00001// RUN: %clang_cc1 -verify -fsyntax-only -std=c++11 -pedantic-errors -triple x86_64-linux-gnu %s
Richard Smith0706df42011-10-19 21:33:05 +00002
3// Make sure we know these are legitimate commas and not typos for ';'.
4namespace Commas {
5 int a,
6 b [[ ]],
7 c alignas(double);
8}
Richard Smith7796eb52012-03-12 08:56:40 +00009
10struct S {};
Richard Smitheab9d6f2012-07-23 05:45:25 +000011enum E { e, };
Richard Smith7796eb52012-03-12 08:56:40 +000012
13auto f() -> struct S {
14 return S();
15}
16auto g() -> enum E {
17 return E();
18}
Richard Smitheab9d6f2012-07-23 05:45:25 +000019
20class ExtraSemiAfterMemFn {
21 // Due to a peculiarity in the C++11 grammar, a deleted or defaulted function
22 // is permitted to be followed by either one or two semicolons.
23 void f() = delete // expected-error {{expected ';' after delete}}
24 void g() = delete; // ok
25 void h() = delete;; // ok
Richard Smithd654f2d2012-10-17 23:31:46 +000026 void i() = delete;;; // expected-error {{extra ';' after member function definition}}
Richard Smitheab9d6f2012-07-23 05:45:25 +000027};
Richard Smith42926a02012-07-24 20:24:58 +000028
Richard Smithd654f2d2012-10-17 23:31:46 +000029int *const const p = 0; // expected-error {{duplicate 'const' declaration specifier}}
30const const int *q = 0; // expected-error {{duplicate 'const' declaration specifier}}
31
32struct MultiCV {
33 void f() const const; // expected-error {{duplicate 'const' declaration specifier}}
34};
Richard Smith3686c712012-09-13 19:12:50 +000035
36static_assert(something, ""); // expected-error {{undeclared identifier}}
Richard Smith6f9a4452012-11-15 22:54:20 +000037
38// PR9903
39struct SS {
40 typedef void d() = default; // expected-error {{function definition declared 'typedef'}} expected-error {{only special member functions may be defaulted}}
41};
Richard Smith6a502c42013-01-08 22:43:49 +000042
43using PR14855 = int S::; // expected-error {{expected ';' after alias declaration}}
Richard Smith7b19cb12013-01-14 01:55:13 +000044
45// Ensure that 'this' has a const-qualified type in a trailing return type for
46// a constexpr function.
47struct ConstexprTrailingReturn {
48 int n;
Richard Smith84046262013-04-21 01:08:50 +000049 constexpr auto f() const -> decltype((n));
Richard Smith7b19cb12013-01-14 01:55:13 +000050};
51constexpr const int &ConstexprTrailingReturn::f() const { return n; }
Richard Smithba65f502013-01-19 03:48:05 +000052
53namespace TestIsValidAfterTypeSpecifier {
54struct s {} v;
55
Richard Smithba65f502013-01-19 03:48:05 +000056struct s
Richard Smithec642442013-04-12 22:46:28 +000057thread_local tl;
Richard Smithba65f502013-01-19 03:48:05 +000058
59struct s
60&r0 = v;
61
62struct s
63&&r1 = s();
64
65struct s
66bitand r2 = v;
67
68struct s
69and r3 = s();
70
71enum E {};
72enum E
73[[]] e;
74
75}
Richard Smitha38253c2013-07-11 05:10:21 +000076
77namespace PR5066 {
78 using T = int (*f)(); // expected-error {{type-id cannot have a name}}
79 template<typename T> using U = int (*f)(); // expected-error {{type-id cannot have a name}}
80 auto f() -> int (*f)(); // expected-error {{type-id cannot have a name}}
81 auto g = []() -> int (*f)() {}; // expected-error {{type-id cannot have a name}}
82}
Richard Smith8d1ab8a2013-10-13 22:12:28 +000083
84namespace FinalOverride {
85 struct Base {
86 virtual void *f();
87 virtual void *g();
88 virtual void *h();
89 virtual void *i();
90 };
91 struct Derived : Base {
92 virtual auto f() -> void *final;
93 virtual auto g() -> void *override;
94 virtual auto h() -> void *final override;
95 virtual auto i() -> void *override final;
96 };
97}
Richard Smithdf1cce52013-10-24 01:21:09 +000098
99namespace UsingDeclAttrs {
100 using T __attribute__((aligned(1))) = int;
101 using T [[gnu::aligned(1)]] = int;
102 static_assert(alignof(T) == 1, "");
103
104 using [[gnu::aligned(1)]] T = int; // expected-error {{an attribute list cannot appear here}}
105 using T = int [[gnu::aligned(1)]]; // expected-error {{'aligned' attribute cannot be applied to types}}
106}
Stephen Hines651f13c2014-04-23 16:59:28 -0700107
108namespace DuplicateSpecifier {
109 constexpr constexpr int f(); // expected-warning {{duplicate 'constexpr' declaration specifier}}
110 constexpr int constexpr a = 0; // expected-warning {{duplicate 'constexpr' declaration specifier}}
111
112 struct A {
113 friend constexpr int constexpr friend f(); // expected-warning {{duplicate 'friend' declaration specifier}} \
114 // expected-warning {{duplicate 'constexpr' declaration specifier}}
115 friend struct A friend; // expected-warning {{duplicate 'friend'}} expected-error {{'friend' must appear first}}
116 };
117}
118
Stephen Hines176edba2014-12-01 14:53:08 -0800119namespace ColonColonDecltype {
120 struct S { struct T {}; };
121 ::decltype(S())::T invalid; // expected-error {{expected unqualified-id}}
122}
123
Stephen Hines651f13c2014-04-23 16:59:28 -0700124struct Base { virtual void f() = 0; virtual void g() = 0; virtual void h() = 0; };
125struct MemberComponentOrder : Base {
126 void f() override __asm__("foobar") __attribute__(( )) {}
127 void g() __attribute__(( )) override;
128 void h() __attribute__(( )) override {}
129};
Stephen Hines176edba2014-12-01 14:53:08 -0800130
131void NoMissingSemicolonHere(struct S
132 [3]);
133template<int ...N> void NoMissingSemicolonHereEither(struct S
134 ... [N]);