fixit-c++2a.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // RUN: %clang_cc1 -verify -std=c++2a -pedantic-errors %s
  2. // RUN: cp %s %t
  3. // RUN: not %clang_cc1 -x c++ -std=c++2a -fixit %t
  4. // RUN: %clang_cc1 -Wall -pedantic-errors -x c++ -std=c++2a %t
  5. // RUN: cat %t | FileCheck %s
  6. /* This is a test of the various code modification hints that only
  7. apply in C++2a. */
  8. template<typename ...T> void init_capture_pack(T ...a) {
  9. [x... = a]{}; // expected-error {{must appear before the name}}
  10. [x = a...]{}; // expected-error {{must appear before the name}}
  11. [...&x = a]{}; // expected-error {{must appear before the name}}
  12. [...a]{}; // expected-error {{must appear after the name}}
  13. [&...a]{}; // expected-error {{must appear after the name}}
  14. [...&a]{}; // expected-error {{must appear after the name}}
  15. }
  16. namespace constinit_mismatch {
  17. extern thread_local constinit int a; // expected-note {{declared constinit here}}
  18. thread_local int a = 123; // expected-error {{'constinit' specifier missing on initializing declaration of 'a'}}
  19. // CHECK: {{^}} constinit thread_local int a = 123;
  20. int b = 123; // expected-note {{add the 'constinit' specifier}}
  21. extern constinit int b; // expected-error {{'constinit' specifier added after initialization of variable}}
  22. // CHECK: {{^}} extern int b;
  23. template<typename> struct X {
  24. template<int> static constinit int n; // expected-note {{constinit}}
  25. };
  26. template<typename T> template<int N>
  27. int X<T>::n = 123; // expected-error {{missing}}
  28. // CHECK: {{^}} constinit int X<T>::n = 123;
  29. #define ABSL_CONST_INIT [[clang::require_constant_initialization]]
  30. extern constinit int c; // expected-note {{constinit}}
  31. int c; // expected-error {{missing}}
  32. // CHECK: {{^}} ABSL_CONST_INIT int c;
  33. #define MY_CONST_INIT constinit
  34. extern constinit int d; // expected-note {{constinit}}
  35. int d; // expected-error {{missing}}
  36. // CHECK: {{^}} MY_CONST_INIT int d;
  37. #undef MY_CONST_INIT
  38. extern constinit int e; // expected-note {{constinit}}
  39. int e; // expected-error {{missing}}
  40. // CHECK: {{^}} ABSL_CONST_INIT int e;
  41. #undef ABSL_CONST_INIT
  42. }