fixit-cxx0x.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // RUN: %clang_cc1 -verify -std=c++11 -Wno-anonymous-pack-parens %s
  2. // RUN: cp %s %t
  3. // RUN: not %clang_cc1 -x c++ -std=c++11 -fixit %t
  4. // RUN: %clang_cc1 -Wall -pedantic -x c++ -std=c++11 %t
  5. /* This is a test of the various code modification hints that only
  6. apply in C++0x. */
  7. struct A {
  8. explicit operator int(); // expected-note{{conversion to integral type}}
  9. };
  10. void x() {
  11. switch(A()) { // expected-error{{explicit conversion to}}
  12. }
  13. }
  14. using ::T = void; // expected-error {{name defined in alias declaration must be an identifier}}
  15. using typename U = void; // expected-error {{name defined in alias declaration must be an identifier}}
  16. using typename ::V = void; // expected-error {{name defined in alias declaration must be an identifier}}
  17. namespace SemiCommaTypo {
  18. int m {},
  19. n [[]], // expected-error {{expected ';' at end of declaration}}
  20. int o;
  21. struct Base {
  22. virtual void f2(), f3();
  23. };
  24. struct MemberDeclarator : Base {
  25. int k : 4,
  26. //[[]] : 1, FIXME: test this once we support attributes here
  27. : 9, // expected-error {{expected ';' at end of declaration}}
  28. char c, // expected-error {{expected ';' at end of declaration}}
  29. typedef void F(), // expected-error {{expected ';' at end of declaration}}
  30. F f1,
  31. f2 final,
  32. f3 override, // expected-error {{expected ';' at end of declaration}}
  33. };
  34. }
  35. namespace ScopedEnum {
  36. enum class E { a };
  37. enum class E b = E::a; // expected-error {{must use 'enum' not 'enum class'}}
  38. struct S {
  39. friend enum class E; // expected-error {{must use 'enum' not 'enum class'}}
  40. };
  41. }
  42. struct S2 {
  43. void f(int i);
  44. void g(int i);
  45. };
  46. void S2::f(int i) {
  47. (void)[&, &i, &i]{}; // expected-error 2{{'&' cannot precede a capture when the capture default is '&'}}
  48. (void)[=, this]{ this->g(5); }; // expected-error{{'this' cannot be explicitly captured}}
  49. (void)[i, i]{ }; // expected-error{{'i' can appear only once in a capture list}}
  50. (void)[&, i, i]{ }; // expected-error{{'i' can appear only once in a capture list}}
  51. (void)[] mutable { }; // expected-error{{lambda requires '()' before 'mutable'}}
  52. (void)[] -> int { }; // expected-error{{lambda requires '()' before return type}}
  53. }
  54. #define bar "bar"
  55. const char *p = "foo"bar; // expected-error {{requires a space between}}
  56. #define ord - '0'
  57. int k = '4'ord; // expected-error {{requires a space between}}
  58. void operator"x" _y(char); // expected-error {{must be '""'}}
  59. void operator L"" _z(char); // expected-error {{encoding prefix}}
  60. void operator "x" "y" U"z" ""_whoops "z" "y"(char); // expected-error {{must be '""'}}
  61. void f() {
  62. 'b'_y;
  63. 'c'_z;
  64. 'd'_whoops;
  65. }
  66. template<typename ...Ts> struct MisplacedEllipsis {
  67. int a(Ts ...(x)); // expected-error {{'...' must immediately precede declared identifier}}
  68. int b(Ts ...&x); // expected-error {{'...' must immediately precede declared identifier}}
  69. int c(Ts ...&); // expected-error {{'...' must be innermost component of anonymous pack declaration}}
  70. int d(Ts ...(...&...)); // expected-error 2{{'...' must be innermost component of anonymous pack declaration}}
  71. int e(Ts ...*[]); // expected-error {{'...' must be innermost component of anonymous pack declaration}}
  72. int f(Ts ...(...*)()); // expected-error 2{{'...' must be innermost component of anonymous pack declaration}}
  73. int g(Ts ...()); // ok
  74. };
  75. namespace TestMisplacedEllipsisRecovery {
  76. MisplacedEllipsis<int, char> me;
  77. int i; char k;
  78. int *ip; char *kp;
  79. int ifn(); char kfn();
  80. int a = me.a(i, k);
  81. int b = me.b(i, k);
  82. int c = me.c(i, k);
  83. int d = me.d(i, k);
  84. int e = me.e(&ip, &kp);
  85. int f = me.f(ifn, kfn);
  86. int g = me.g(ifn, kfn);
  87. }
  88. template<template<typename> ...Foo, // expected-error {{template template parameter requires 'class' after the parameter list}}
  89. template<template<template<typename>>>> // expected-error 3 {{template template parameter requires 'class' after the parameter list}}
  90. void func();
  91. template<int *ip> struct IP { }; // expected-note{{declared here}}
  92. IP<0> ip0; // expected-error{{null non-type template argument must be cast to template parameter type 'int *'}}
  93. namespace MissingSemi {
  94. struct a // expected-error {{expected ';' after struct}}
  95. struct b // expected-error {{expected ';' after struct}}
  96. enum x : int { x1, x2, x3 } // expected-error {{expected ';' after enum}}
  97. struct c // expected-error {{expected ';' after struct}}
  98. enum x : int // expected-error {{expected ';' after enum}}
  99. // FIXME: The following gives a poor diagnostic (we parse the 'int' and the
  100. // 'struct' as part of the same enum-base.
  101. // enum x : int
  102. // struct y
  103. namespace N {
  104. struct d // expected-error {{expected ';' after struct}}
  105. }
  106. }
  107. namespace NonStaticConstexpr {
  108. struct foo {
  109. constexpr int i; // expected-error {{non-static data member cannot be constexpr; did you intend to make it const?}}
  110. constexpr int j = 7; // expected-error {{non-static data member cannot be constexpr; did you intend to make it static?}}
  111. constexpr const int k; // expected-error {{non-static data member cannot be constexpr; did you intend to make it const?}}
  112. foo() : i(3), k(4) {
  113. }
  114. static int get_j() {
  115. return j;
  116. }
  117. };
  118. }
  119. int RegisterVariable() {
  120. register int n; // expected-warning {{'register' storage class specifier is deprecated}}
  121. return n;
  122. }
  123. namespace MisplacedParameterPack {
  124. template <typename Args...> // expected-error {{'...' must immediately precede declared identifier}}
  125. void misplacedEllipsisInTypeParameter(Args...);
  126. template <typename... Args...> // expected-error {{'...' must immediately precede declared identifier}}
  127. void redundantEllipsisInTypeParameter(Args...);
  128. template <template <typename> class Args...> // expected-error {{'...' must immediately precede declared identifier}}
  129. void misplacedEllipsisInTemplateTypeParameter(Args<int>...);
  130. template <template <typename> class... Args...> // expected-error {{'...' must immediately precede declared identifier}}
  131. void redundantEllipsisInTemplateTypeParameter(Args<int>...);
  132. template <int N...> // expected-error {{'...' must immediately precede declared identifier}}
  133. void misplacedEllipsisInNonTypeTemplateParameter();
  134. template <int... N...> // expected-error {{'...' must immediately precede declared identifier}}
  135. void redundantEllipsisInNonTypeTemplateParameter();
  136. }
  137. namespace MisplacedDeclAndRefSpecAfterVirtSpec {
  138. struct B {
  139. virtual void f();
  140. virtual void f() volatile const;
  141. };
  142. struct D : B {
  143. virtual void f() override;
  144. virtual void f() override final const volatile; // expected-error {{'const' qualifier may not appear after the virtual specifier 'final'}} expected-error {{'volatile' qualifier may not appear after the virtual specifier 'final'}}
  145. };
  146. struct B2 {
  147. virtual void f() &;
  148. virtual void f() volatile const &&;
  149. };
  150. struct D2 : B2 {
  151. virtual void f() override &; // expected-error {{'&' qualifier may not appear after the virtual specifier 'override'}}
  152. virtual void f() override final const volatile &&; // expected-error {{'const' qualifier may not appear after the virtual specifier 'final'}} expected-error {{'volatile' qualifier may not appear after the virtual specifier 'final'}} expected-error {{'&&' qualifier may not appear after the virtual specifier 'final'}}
  153. };
  154. }