cxx0x-decl.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // RUN: %clang_cc1 -verify -fsyntax-only -std=c++11 -pedantic-errors -triple x86_64-linux-gnu %s
  2. // Make sure we know these are legitimate commas and not typos for ';'.
  3. namespace Commas {
  4. int a,
  5. b [[ ]],
  6. c alignas(double);
  7. }
  8. struct S {};
  9. enum E { e, };
  10. auto f() -> struct S {
  11. return S();
  12. }
  13. auto g() -> enum E {
  14. return E();
  15. }
  16. class ExtraSemiAfterMemFn {
  17. // Due to a peculiarity in the C++11 grammar, a deleted or defaulted function
  18. // is permitted to be followed by either one or two semicolons.
  19. void f() = delete // expected-error {{expected ';' after delete}}
  20. void g() = delete; // ok
  21. void h() = delete;; // ok
  22. void i() = delete;;; // expected-error {{extra ';' after member function definition}}
  23. };
  24. int *const const p = 0; // expected-error {{duplicate 'const' declaration specifier}}
  25. const const int *q = 0; // expected-error {{duplicate 'const' declaration specifier}}
  26. struct MultiCV {
  27. void f() const const; // expected-error {{duplicate 'const' declaration specifier}}
  28. };
  29. static_assert(something, ""); // expected-error {{undeclared identifier}}
  30. // PR9903
  31. struct SS {
  32. typedef void d() = default; // expected-error {{function definition declared 'typedef'}} expected-error {{only special member functions may be defaulted}}
  33. };
  34. using PR14855 = int S::; // expected-error {{expected ';' after alias declaration}}
  35. // Ensure that 'this' has a const-qualified type in a trailing return type for
  36. // a constexpr function.
  37. struct ConstexprTrailingReturn {
  38. int n;
  39. constexpr auto f() const -> decltype((n));
  40. };
  41. constexpr const int &ConstexprTrailingReturn::f() const { return n; }
  42. namespace TestIsValidAfterTypeSpecifier {
  43. struct s {} v;
  44. struct s
  45. thread_local tl;
  46. struct s
  47. &r0 = v;
  48. struct s
  49. &&r1 = s();
  50. struct s
  51. bitand r2 = v;
  52. struct s
  53. and r3 = s();
  54. enum E {};
  55. enum E
  56. [[]] e;
  57. }
  58. namespace PR5066 {
  59. using T = int (*f)(); // expected-error {{type-id cannot have a name}}
  60. template<typename T> using U = int (*f)(); // expected-error {{type-id cannot have a name}}
  61. auto f() -> int (*f)(); // expected-error {{type-id cannot have a name}}
  62. auto g = []() -> int (*f)() {}; // expected-error {{type-id cannot have a name}}
  63. }
  64. namespace FinalOverride {
  65. struct Base {
  66. virtual void *f();
  67. virtual void *g();
  68. virtual void *h();
  69. virtual void *i();
  70. };
  71. struct Derived : Base {
  72. virtual auto f() -> void *final;
  73. virtual auto g() -> void *override;
  74. virtual auto h() -> void *final override;
  75. virtual auto i() -> void *override final;
  76. };
  77. }
  78. namespace UsingDeclAttrs {
  79. using T __attribute__((aligned(1))) = int;
  80. using T [[gnu::aligned(1)]] = int;
  81. static_assert(alignof(T) == 1, "");
  82. using [[gnu::aligned(1)]] T = int; // expected-error {{an attribute list cannot appear here}}
  83. using T = int [[gnu::aligned(1)]]; // expected-error {{'aligned' attribute cannot be applied to types}}
  84. }
  85. namespace DuplicateSpecifier {
  86. constexpr constexpr int f(); // expected-warning {{duplicate 'constexpr' declaration specifier}}
  87. constexpr int constexpr a = 0; // expected-warning {{duplicate 'constexpr' declaration specifier}}
  88. struct A {
  89. friend constexpr int constexpr friend f(); // expected-warning {{duplicate 'friend' declaration specifier}} \
  90. // expected-warning {{duplicate 'constexpr' declaration specifier}}
  91. friend struct A friend; // expected-warning {{duplicate 'friend'}} expected-error {{'friend' must appear first}}
  92. };
  93. }
  94. namespace ColonColonDecltype {
  95. struct S { struct T {}; };
  96. ::decltype(S())::T invalid; // expected-error {{expected unqualified-id}}
  97. }
  98. struct Base { virtual void f() = 0; virtual void g() = 0; virtual void h() = 0; };
  99. struct MemberComponentOrder : Base {
  100. void f() override __asm__("foobar") __attribute__(( )) {}
  101. void g() __attribute__(( )) override;
  102. void h() __attribute__(( )) override {}
  103. };
  104. void NoMissingSemicolonHere(struct S
  105. [3]);
  106. template<int ...N> void NoMissingSemicolonHereEither(struct S
  107. ... [N]);