blob: 7bd82e8220becc1ba85a515a3f9da4b18eeec4c5 [file] [log] [blame]
Richard Smith6da24a22013-04-13 00:34:48 +00001// RUN: %clang_cc1 -verify -fsyntax-only -std=c++11 -pedantic-errors -triple x86_64-linux-gnu %s
Richard Smith09f76ee2011-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 Smithbfdb1082012-03-12 08:56:40 +00009
10struct S {};
Richard Smith87f5dc52012-07-23 05:45:25 +000011enum E { e, };
Richard Smithbfdb1082012-03-12 08:56:40 +000012
13auto f() -> struct S {
14 return S();
15}
16auto g() -> enum E {
17 return E();
18}
Richard Smith87f5dc52012-07-23 05:45:25 +000019
Richard Smith83c2ecf2016-02-02 23:34:49 +000020int decltype(f())::*ptr_mem_decltype;
21
Richard Smith87f5dc52012-07-23 05:45:25 +000022class ExtraSemiAfterMemFn {
23 // Due to a peculiarity in the C++11 grammar, a deleted or defaulted function
24 // is permitted to be followed by either one or two semicolons.
25 void f() = delete // expected-error {{expected ';' after delete}}
26 void g() = delete; // ok
27 void h() = delete;; // ok
Richard Smith87e79512012-10-17 23:31:46 +000028 void i() = delete;;; // expected-error {{extra ';' after member function definition}}
Richard Smith87f5dc52012-07-23 05:45:25 +000029};
Richard Smith7ac3c6a2012-07-24 20:24:58 +000030
Richard Smith87e79512012-10-17 23:31:46 +000031int *const const p = 0; // expected-error {{duplicate 'const' declaration specifier}}
32const const int *q = 0; // expected-error {{duplicate 'const' declaration specifier}}
33
34struct MultiCV {
35 void f() const const; // expected-error {{duplicate 'const' declaration specifier}}
36};
Richard Smith76965712012-09-13 19:12:50 +000037
38static_assert(something, ""); // expected-error {{undeclared identifier}}
Richard Smith2603b092012-11-15 22:54:20 +000039
40// PR9903
41struct SS {
42 typedef void d() = default; // expected-error {{function definition declared 'typedef'}} expected-error {{only special member functions may be defaulted}}
43};
Richard Smith5f044ad2013-01-08 22:43:49 +000044
45using PR14855 = int S::; // expected-error {{expected ';' after alias declaration}}
Richard Smith01141a92013-01-14 01:55:13 +000046
47// Ensure that 'this' has a const-qualified type in a trailing return type for
48// a constexpr function.
49struct ConstexprTrailingReturn {
50 int n;
Richard Smith034185c2013-04-21 01:08:50 +000051 constexpr auto f() const -> decltype((n));
Richard Smith01141a92013-01-14 01:55:13 +000052};
53constexpr const int &ConstexprTrailingReturn::f() const { return n; }
Richard Smith1ac67d12013-01-19 03:48:05 +000054
55namespace TestIsValidAfterTypeSpecifier {
56struct s {} v;
57
Richard Smith1ac67d12013-01-19 03:48:05 +000058struct s
Richard Smithb4a9e862013-04-12 22:46:28 +000059thread_local tl;
Richard Smith1ac67d12013-01-19 03:48:05 +000060
61struct s
62&r0 = v;
63
64struct s
65&&r1 = s();
66
67struct s
68bitand r2 = v;
69
70struct s
71and r3 = s();
72
73enum E {};
74enum E
75[[]] e;
76
77}
Richard Smith9ce302e2013-07-11 05:10:21 +000078
79namespace PR5066 {
80 using T = int (*f)(); // expected-error {{type-id cannot have a name}}
81 template<typename T> using U = int (*f)(); // expected-error {{type-id cannot have a name}}
Richard Smithe303e352018-02-02 22:24:54 +000082 auto f() -> int (*f)(); // expected-error {{only variables can be initialized}} expected-error {{expected ';'}}
Richard Smith9ce302e2013-07-11 05:10:21 +000083 auto g = []() -> int (*f)() {}; // expected-error {{type-id cannot have a name}}
84}
Richard Smithf39720b2013-10-13 22:12:28 +000085
86namespace FinalOverride {
87 struct Base {
Alexander Potapenkoe2e8b0e2014-10-03 09:02:53 +000088 virtual void *f();
Richard Smithf39720b2013-10-13 22:12:28 +000089 virtual void *g();
90 virtual void *h();
91 virtual void *i();
92 };
93 struct Derived : Base {
Alexander Potapenkoe2e8b0e2014-10-03 09:02:53 +000094 virtual auto f() -> void *final;
Richard Smithf39720b2013-10-13 22:12:28 +000095 virtual auto g() -> void *override;
96 virtual auto h() -> void *final override;
97 virtual auto i() -> void *override final;
98 };
99}
Richard Smith37a45dd2013-10-24 01:21:09 +0000100
101namespace UsingDeclAttrs {
102 using T __attribute__((aligned(1))) = int;
103 using T [[gnu::aligned(1)]] = int;
104 static_assert(alignof(T) == 1, "");
105
106 using [[gnu::aligned(1)]] T = int; // expected-error {{an attribute list cannot appear here}}
107 using T = int [[gnu::aligned(1)]]; // expected-error {{'aligned' attribute cannot be applied to types}}
108}
Richard Smithc0a5d5b2014-01-10 21:27:55 +0000109
110namespace DuplicateSpecifier {
111 constexpr constexpr int f(); // expected-warning {{duplicate 'constexpr' declaration specifier}}
112 constexpr int constexpr a = 0; // expected-warning {{duplicate 'constexpr' declaration specifier}}
113
114 struct A {
115 friend constexpr int constexpr friend f(); // expected-warning {{duplicate 'friend' declaration specifier}} \
116 // expected-warning {{duplicate 'constexpr' declaration specifier}}
117 friend struct A friend; // expected-warning {{duplicate 'friend'}} expected-error {{'friend' must appear first}}
118 };
119}
Richard Smith72553fc2014-01-23 23:53:27 +0000120
Richard Smitha9d10012014-10-04 01:57:39 +0000121namespace ColonColonDecltype {
122 struct S { struct T {}; };
123 ::decltype(S())::T invalid; // expected-error {{expected unqualified-id}}
124}
125
Richard Smithaf3b3252017-05-18 19:21:48 +0000126namespace AliasDeclEndLocation {
127 template<typename T> struct A {};
128 // Ensure that we correctly determine the end of this declaration to be the
129 // end of the annotation token, not the beginning.
130 using B = AliasDeclEndLocation::A<int
131 > // expected-error {{expected ';' after alias declaration}}
132 +;
Richard Smithaf3b3252017-05-18 19:21:48 +0000133 using C = AliasDeclEndLocation::A<int
134 >\
135> // expected-error {{expected ';' after alias declaration}}
136 ;
Richard Smith74639b12017-05-19 01:54:59 +0000137 using D = AliasDeclEndLocation::A<int
138 > // expected-error {{expected ';' after alias declaration}}
Richard Smithb5f81712018-04-30 05:25:48 +0000139 // FIXME: After splitting this >> into two > tokens, we incorrectly determine
140 // the end of the template-id to be after the *second* '>'.
141 using E = AliasDeclEndLocation::A<int>>;
142#define GGG >>>
143 using F = AliasDeclEndLocation::A<int GGG;
144 // expected-error@-1 {{expected ';' after alias declaration}}
Richard Smith74639b12017-05-19 01:54:59 +0000145 B something_else;
Richard Smithaf3b3252017-05-18 19:21:48 +0000146}
147
Richard Smith72553fc2014-01-23 23:53:27 +0000148struct Base { virtual void f() = 0; virtual void g() = 0; virtual void h() = 0; };
149struct MemberComponentOrder : Base {
150 void f() override __asm__("foobar") __attribute__(( )) {}
Richard Smith4b5a9492014-01-24 22:34:35 +0000151 void g() __attribute__(( )) override;
152 void h() __attribute__(( )) override {}
Richard Smith72553fc2014-01-23 23:53:27 +0000153};
Richard Smith843f18f2014-08-13 02:13:15 +0000154
155void NoMissingSemicolonHere(struct S
156 [3]);
157template<int ...N> void NoMissingSemicolonHereEither(struct S
158 ... [N]);
Richard Smithc7ae3e02015-07-21 00:23:34 +0000159
160// This must be at the end of the file; we used to look ahead past the EOF token here.
Richard Smith6f1daa42016-12-16 00:58:48 +0000161// expected-error@+1 {{expected unqualified-id}} expected-error@+1{{expected ';'}}
Richard Smithc7ae3e02015-07-21 00:23:34 +0000162using