brintos

brintos / llvm-project-archived public Read only

0
0
Text · 12.5 KiB · aa87f5a Raw
382 lines · cpp
1// RUN: %clang_cc1 -std=c++98 -pedantic-errors %s -verify=expected,cxx982// RUN: %clang_cc1 -std=c++11 -pedantic-errors %s -verify=expected,since-cxx11,cxx113// RUN: %clang_cc1 -std=c++14 -pedantic-errors %s -verify=expected,since-cxx114// RUN: %clang_cc1 -std=c++17 -pedantic-errors %s -verify=expected,since-cxx115// RUN: %clang_cc1 -std=c++20 -pedantic-errors %s -verify=expected,since-cxx11,since-cxx206// RUN: %clang_cc1 -std=c++23 -pedantic-errors %s -verify=expected,since-cxx11,since-cxx20,since-cxx237// RUN: %clang_cc1 -std=c++2c -pedantic-errors %s -verify=expected,since-cxx11,since-cxx20,since-cxx238 9#if __cplusplus == 199711L10#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)11// cxx98-error@-1 {{variadic macros are a C99 feature}}12#endif13 14namespace std {15#if __cplusplus >= 202002L16  struct strong_ordering {17    int n;18    constexpr operator int() const { return n; }19    static const strong_ordering less, equal, greater;20  };21  constexpr strong_ordering strong_ordering::less{-1},22      strong_ordering::equal{0}, strong_ordering::greater{1};23#endif24 25  typedef short int16_t;26  typedef unsigned short uint16_t;27  typedef int int32_t;28  typedef unsigned uint32_t;29  typedef long long int64_t;30  // cxx98-error@-1 {{'long long' is a C++11 extension}}31  typedef unsigned long long uint64_t;32  // cxx98-error@-1 {{'long long' is a C++11 extension}}33  static_assert(sizeof(int16_t) == 2 && sizeof(int32_t) == 4 && sizeof(int64_t) == 8, "Some tests rely on these sizes");34 35  template<typename T> T declval();36} // namespace std37 38namespace cwg2621 { // cwg2621: sup 287739#if __cplusplus >= 202002L40enum class E { a };41namespace One {42using E_t = E;43using enum E_t; // typedef ok44auto v = a;45}46namespace Two {47using cwg2621::E;48int E; // ignored by type-only lookup49using enum E;50}51#endif52} // namespace cwg262153 54namespace cwg2627 { // cwg2627: 2055#if __cplusplus >= 202002L56struct C {57  long long i : 8;58  friend auto operator<=>(C, C) = default;59};60 61void f() {62  C x{1}, y{2};63  static_cast<void>(x <=> y);64  static_cast<void>(x.i <=> y.i);65}66 67template<typename T>68struct CDependent {69  T i : 8;70  friend auto operator<=>(CDependent, CDependent) = default;71};72 73template<typename T>74concept three_way_comparable = requires(T t) { { t <=> t }; };75template<typename T>76concept bf_three_way_comparable = requires(T t) { { t.i <=> t.i }; };77static_assert(three_way_comparable<CDependent<long long>>);78static_assert(bf_three_way_comparable<CDependent<long long>>);79#endif80 81#if __cplusplus >= 201103L82template<typename T, int N>83struct D {84  T i : N;85};86 87template<typename T, int N>88D<T, N> d();89 90std::int32_t d1{ d<std::int64_t, 31>().i };91std::int32_t d2{ d<std::int64_t, 32>().i };92std::int32_t d3{ d<std::int64_t, 33>().i };93// since-cxx11-error@-1 {{non-constant-expression cannot be narrowed from type 'long long' to 'std::int32_t' (aka 'int') in initializer list}}94//   since-cxx11-note@-2 {{insert an explicit cast to silence this issue}}95 96std::int16_t d6{ d<int, 16>().i };97std::int16_t d7{ d<unsigned, 15>().i };98std::int16_t d8{ d<unsigned, 16>().i };99// since-cxx11-error@-1 {{non-constant-expression cannot be narrowed from type 'unsigned int' to 'std::int16_t' (aka 'short') in initializer list}}100//   since-cxx11-note@-2 {{insert an explicit cast to silence this issue}}101std::uint16_t d9{ d<unsigned, 16>().i };102std::uint16_t da{ d<int, 1>().i };103// since-cxx11-error@-1 {{non-constant-expression cannot be narrowed from type 'int' to 'std::uint16_t' (aka 'unsigned short') in initializer list}}104//   since-cxx11-note@-2 {{insert an explicit cast to silence this issue}}105 106bool db{ d<unsigned, 1>().i };107bool dc{ d<int, 1>().i };108// since-cxx11-error@-1 {{non-constant-expression cannot be narrowed from type 'int' to 'bool' in initializer list}}109//   since-cxx11-note@-2 {{insert an explicit cast to silence this issue}}110 111template<typename Target, typename Source>112constexpr decltype(Target{ std::declval<Source>().i }, false) is_narrowing(int) { return false; }113template<typename Target, typename Source>114constexpr bool is_narrowing(long) { return true; }115 116static_assert(!is_narrowing<std::int16_t, D<int, 16>>(0), "");117static_assert(!is_narrowing<std::int16_t, D<unsigned, 15>>(0), "");118static_assert(is_narrowing<std::int16_t, D<unsigned, 16>>(0), "");119static_assert(!is_narrowing<std::uint16_t, D<unsigned, 16>>(0), "");120static_assert(is_narrowing<std::uint16_t, D<int, 1>>(0), "");121static_assert(!is_narrowing<bool, D<unsigned, 1>>(0), "");122static_assert(is_narrowing<bool, D<int, 1>>(0), "");123 124template<int N>125struct E {126  signed int x : N;127  decltype(std::int16_t{ x }) dependent_narrowing;128  decltype(unsigned{ x }) always_narrowing;129  // since-cxx11-error@-1 {{non-constant-expression cannot be narrowed from type 'int' to 'unsigned int' in initializer list}}130  //   since-cxx11-note@-2 {{insert an explicit cast to silence this issue}}131};132#endif133} // namespace cwg2627134 135namespace cwg2628 { // cwg2628: 20136#if __cplusplus >= 202002L137template <bool A = false, bool B = false>138struct foo {139  constexpr foo() requires (!A && !B) = delete; // #cwg2628-ctor140  constexpr foo() requires (A || B) = delete;141};142 143void f() {144  foo fooable; // #cwg2628-fooable145  // since-cxx20-error@#cwg2628-fooable {{call to deleted}}146  //   since-cxx20-note@#cwg2628-ctor {{marked deleted here}}147}148#endif149} // namespace cwg2628150 151// cwg2630 is in cwg2630.cpp152 153namespace cwg2631 { // cwg2631: 16154#if __cplusplus >= 202002L155  constexpr int g();156  consteval int f() {157    return g();158  }159  int k(int x = f()) {160    return x;161  }162  constexpr int g() {163    return 42;164  }165  int test() {166    return k();167  }168#endif169} // namespace cwg2631170 171namespace cwg2635 { // cwg2635: 16172#if __cplusplus >= 202002L173template<typename T>174concept UnaryC = true;175template<typename T, typename U>176concept BinaryC = true;177 178struct S{ int i, j; };179S get_S();180 181template<typename T>182T get_T();183 184void use() {185  UnaryC auto [a, b] = get_S();186  // since-cxx20-error@-1 {{structured binding declaration cannot be declared with constrained 'auto'}}187  BinaryC<int> auto [c, d] = get_S();188  // since-cxx20-error@-1 {{structured binding declaration cannot be declared with constrained 'auto'}}189}190 191template<typename T>192void TemplUse() {193  UnaryC auto [a, b] = get_T<T>();194  // since-cxx20-error@-1 {{structured binding declaration cannot be declared with constrained 'auto'}}195  BinaryC<T> auto [c, d] = get_T<T>();196  // since-cxx20-error@-1 {{structured binding declaration cannot be declared with constrained 'auto'}}197}198#endif199} // namespace cwg2635200 201// cwg2636: na202 203namespace cwg2640 { // cwg2640: 16204 205int \N{Λ} = 0;206// expected-error@-1 {{'Λ' is not a valid Unicode character name}}207// expected-error@-2 {{expected unqualified-id}}208const char* emoji = "\N{🤡}";209// expected-error@-1 {{'🤡' is not a valid Unicode character name}}210//   expected-note@-2 {{did you mean OX ('🐂' U+1F402)?}}211//   expected-note@-3 {{did you mean ANT ('🐜' U+1F41C)?}}212//   expected-note@-4 {{did you mean ARC ('⌒' U+2312)?}}213//   expected-note@-5 {{did you mean AXE ('🪓' U+1FA93)?}}214//   expected-note@-6 {{did you mean BAT ('🦇' U+1F987)?}}215 216#define z(x) 0217#define cwg2640_a z(218int x = cwg2640_a\N{abc});219// expected-error@-1 {{'abc' is not a valid Unicode character name}}220int y = cwg2640_a\N{LOTUS});221// expected-error@-1 {{character <U+1FAB7> not allowed in an identifier}}222// expected-error@-2 {{use of undeclared identifier 'cwg2640_a🪷'}}223} // namespace cwg2640224 225// cwg2642: na226 227namespace cwg2644 { // cwg2644: 8228#if __cplusplus >= 201103L229auto z = [a = 42](int a) {230// cxx11-error@-1 {{initialized lambda captures are a C++14 extension}}231// since-cxx11-error@-2 {{a lambda parameter cannot shadow an explicitly captured entity}}232//   since-cxx11-note@-3 {{variable 'a' is explicitly captured here}}233     return 1;234};235#endif236} // namespace cwg2644237 238namespace cwg2650 { // cwg2650: 17239#if __cplusplus >= 202302L240template <class T, T> struct S {};241template <class T> int f(S<T, T{}>*); // #cwg2650-f242class X {243  int m;244};245int i0 = f<X>(0);246// since-cxx23-error@-1 {{no matching function for call to 'f'}}247//   since-cxx23-note@#cwg2650-f {{type 'X' of non-type template parameter is not a structural type}}248#endif249} // namespace cwg2650250 251namespace cwg2653 { // cwg2653: 18252#if __cplusplus >= 202302L253  struct Test { void f(this const auto& = Test{}); };254  // since-cxx23-error@-1 {{the explicit object parameter cannot have a default argument}}255  auto L = [](this const auto& = Test{}){};256  // since-cxx23-error@-1 {{the explicit object parameter cannot have a default argument}}257#endif258} // namespace cwg2653259 260namespace cwg2654 { // cwg2654: 16261void f() {262    int neck, tail;263    volatile int brachiosaur;264    brachiosaur += neck;                // OK265    brachiosaur -= neck;                // OK266    brachiosaur |= neck;                // OK267}268} // namespace cwg2654269 270namespace cwg2681 { // cwg2681: 17271#if __cplusplus >= 202002L272using size_t = decltype(sizeof(int));273 274template<class T, size_t N>275struct H {276  T array[N];277};278template<class T, size_t N>279struct I {280  volatile T array[N];281};282template<size_t N>283struct J { // #cwg2681-J284  unsigned char array[N];285};286 287H h = { "abc" };288I i = { "def" };289static_assert(__is_same(decltype(h), H<char, 4>));  // Not H<const char, 4>290static_assert(__is_same(decltype(i), I<char, 4>));291 292J j = { "ghi" };293// since-cxx20-error@-1 {{no viable constructor or deduction guide}}294//   since-cxx20-note@#cwg2681-J {{candidate template ignored: could not match 'cwg2681::J<N>' against 'const char *'}}295//   since-cxx20-note@#cwg2681-J {{implicit deduction guide declared as 'template <size_t N> J(cwg2681::J<N>) -> cwg2681::J<N>'}}296//   since-cxx20-note@#cwg2681-J {{candidate template ignored: could not match 'const unsigned char' against 'const char'}}297//   since-cxx20-note@#cwg2681-J {{implicit deduction guide declared as 'template <size_t N> J(const unsigned char (&)[N]) -> cwg2681::J<N>'}}298//   since-cxx20-note@#cwg2681-J {{candidate function template not viable: requires 0 arguments, but 1 was provided}}299//   since-cxx20-note@#cwg2681-J {{implicit deduction guide declared as 'template <size_t N> J() -> cwg2681::J<N>'}}300#endif301} // namespace cwg2681302 303namespace cwg2672 { // cwg2672: 18304#if __cplusplus >= 202002L305template <class T>306void f(T) requires requires { []() { T::invalid; } (); };307// since-cxx20-error@-1 {{type 'int' cannot be used prior to '::' because it has no members}}308//   since-cxx20-note@-2 {{while substituting into a lambda expression here}}309//   since-cxx20-note@-3 {{in instantiation of requirement here}}310//   since-cxx20-note@-4 {{while substituting template arguments into constraint expression here}}311//   since-cxx20-note@#cwg2672-f-0 {{while checking constraint satisfaction for template 'f<int>' required here}}312//   since-cxx20-note@#cwg2672-f-0 {{while substituting deduced template arguments into function template 'f' [with T = int]}}313void f(...);314 315template <class T>316void bar(T) requires requires {317   []() -> decltype(T::foo()) {};318};319void bar(...);320 321void m() {322  f(0); // #cwg2672-f-0323  bar(0);324}325#endif326} // namespace cwg2672327 328namespace cwg2687 { // cwg2687: 18329#if __cplusplus >= 202302L330struct S{331    void f(int);332    static void g(int);333    void h(this const S&, int);334};335 336void test() {337    (&S::f)(1);338    // since-cxx23-error@-1 {{called object type 'void (S::*)(int)' is not a function or function pointer}}339    (&S::g)(1);340    (&S::h)(S(), 1);341}342#endif343} // namespace cwg2687344 345namespace cwg2692 { // cwg2692: 19346#if __cplusplus >= 202302L347 348struct A {349    static void f(A); // #cwg2692-1350    void f(this A); // #cwg2692-2351 352    template <typename T>353    static void g(T); // #cwg2692-3354    template <typename T>355    void g(this T); // #cwg2692-4356 357    void test();358};359 360void A::test() {361    (&A::f)(A());362    // since-cxx23-error@-1 {{call to 'f' is ambiguous}}363    //   since-cxx23-note@#cwg2692-1 {{candidate function}}364    //   since-cxx23-note@#cwg2692-2 {{candidate function}}365    (&A::f)();366    // since-cxx23-error@-1 {{no matching function for call to 'f'}}367    //   since-cxx23-note@#cwg2692-1 {{candidate function not viable: requires 1 argument, but 0 were provided}}368    //   since-cxx23-note@#cwg2692-2 {{candidate function not viable: requires 1 argument, but 0 were provided}}369 370 371    (&A::g)(A());372    // since-cxx23-error@-1 {{call to 'g' is ambiguous}}373    //   since-cxx23-note@#cwg2692-3 {{candidate function}}374    //   since-cxx23-note@#cwg2692-4 {{candidate function}}375    (&A::g<A>)();376    // since-cxx23-error@-1 {{no matching function for call to 'g'}}377    //   since-cxx23-note@#cwg2692-3 {{candidate function template not viable: requires 1 argument, but 0 were provided}}378    //   since-cxx23-note@#cwg2692-4 {{candidate function [with T = cwg2692::A] not viable: requires 1 argument, but 0 were provided}}379}380#endif381} // namespace cwg2692382