Richard Smith | 3a0f7ac | 2013-04-13 00:34:48 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify -fsyntax-only -std=c++11 -pedantic-errors -triple x86_64-linux-gnu %s |
Richard Smith | 0706df4 | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 2 | |
| 3 | // Make sure we know these are legitimate commas and not typos for ';'. |
| 4 | namespace Commas { |
| 5 | int a, |
| 6 | b [[ ]], |
| 7 | c alignas(double); |
| 8 | } |
Richard Smith | 7796eb5 | 2012-03-12 08:56:40 +0000 | [diff] [blame] | 9 | |
| 10 | struct S {}; |
Richard Smith | eab9d6f | 2012-07-23 05:45:25 +0000 | [diff] [blame] | 11 | enum E { e, }; |
Richard Smith | 7796eb5 | 2012-03-12 08:56:40 +0000 | [diff] [blame] | 12 | |
| 13 | auto f() -> struct S { |
| 14 | return S(); |
| 15 | } |
| 16 | auto g() -> enum E { |
| 17 | return E(); |
| 18 | } |
Richard Smith | eab9d6f | 2012-07-23 05:45:25 +0000 | [diff] [blame] | 19 | |
| 20 | class 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 Smith | d654f2d | 2012-10-17 23:31:46 +0000 | [diff] [blame] | 26 | void i() = delete;;; // expected-error {{extra ';' after member function definition}} |
Richard Smith | eab9d6f | 2012-07-23 05:45:25 +0000 | [diff] [blame] | 27 | }; |
Richard Smith | 42926a0 | 2012-07-24 20:24:58 +0000 | [diff] [blame] | 28 | |
Richard Smith | d654f2d | 2012-10-17 23:31:46 +0000 | [diff] [blame] | 29 | int *const const p = 0; // expected-error {{duplicate 'const' declaration specifier}} |
| 30 | const const int *q = 0; // expected-error {{duplicate 'const' declaration specifier}} |
| 31 | |
| 32 | struct MultiCV { |
| 33 | void f() const const; // expected-error {{duplicate 'const' declaration specifier}} |
| 34 | }; |
Richard Smith | 3686c71 | 2012-09-13 19:12:50 +0000 | [diff] [blame] | 35 | |
| 36 | static_assert(something, ""); // expected-error {{undeclared identifier}} |
Richard Smith | 6f9a445 | 2012-11-15 22:54:20 +0000 | [diff] [blame] | 37 | |
| 38 | // PR9903 |
| 39 | struct SS { |
| 40 | typedef void d() = default; // expected-error {{function definition declared 'typedef'}} expected-error {{only special member functions may be defaulted}} |
| 41 | }; |
Richard Smith | 6a502c4 | 2013-01-08 22:43:49 +0000 | [diff] [blame] | 42 | |
| 43 | using PR14855 = int S::; // expected-error {{expected ';' after alias declaration}} |
Richard Smith | 7b19cb1 | 2013-01-14 01:55:13 +0000 | [diff] [blame] | 44 | |
| 45 | // Ensure that 'this' has a const-qualified type in a trailing return type for |
| 46 | // a constexpr function. |
| 47 | struct ConstexprTrailingReturn { |
| 48 | int n; |
Richard Smith | 8404626 | 2013-04-21 01:08:50 +0000 | [diff] [blame] | 49 | constexpr auto f() const -> decltype((n)); |
Richard Smith | 7b19cb1 | 2013-01-14 01:55:13 +0000 | [diff] [blame] | 50 | }; |
| 51 | constexpr const int &ConstexprTrailingReturn::f() const { return n; } |
Richard Smith | ba65f50 | 2013-01-19 03:48:05 +0000 | [diff] [blame] | 52 | |
| 53 | namespace TestIsValidAfterTypeSpecifier { |
| 54 | struct s {} v; |
| 55 | |
Richard Smith | ba65f50 | 2013-01-19 03:48:05 +0000 | [diff] [blame] | 56 | struct s |
Richard Smith | ec64244 | 2013-04-12 22:46:28 +0000 | [diff] [blame] | 57 | thread_local tl; |
Richard Smith | ba65f50 | 2013-01-19 03:48:05 +0000 | [diff] [blame] | 58 | |
| 59 | struct s |
| 60 | &r0 = v; |
| 61 | |
| 62 | struct s |
| 63 | &&r1 = s(); |
| 64 | |
| 65 | struct s |
| 66 | bitand r2 = v; |
| 67 | |
| 68 | struct s |
| 69 | and r3 = s(); |
| 70 | |
| 71 | enum E {}; |
| 72 | enum E |
| 73 | [[]] e; |
| 74 | |
| 75 | } |
Richard Smith | a38253c | 2013-07-11 05:10:21 +0000 | [diff] [blame] | 76 | |
| 77 | namespace 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 Smith | 8d1ab8a | 2013-10-13 22:12:28 +0000 | [diff] [blame] | 83 | |
| 84 | namespace 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 Smith | df1cce5 | 2013-10-24 01:21:09 +0000 | [diff] [blame] | 98 | |
| 99 | namespace 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 Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame^] | 107 | |
| 108 | namespace 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 | |
| 119 | struct Base { virtual void f() = 0; virtual void g() = 0; virtual void h() = 0; }; |
| 120 | struct MemberComponentOrder : Base { |
| 121 | void f() override __asm__("foobar") __attribute__(( )) {} |
| 122 | void g() __attribute__(( )) override; |
| 123 | void h() __attribute__(( )) override {} |
| 124 | }; |