brintos

brintos / llvm-project-archived public Read only

0
0
Text · 12.5 KiB · d0ee191 Raw
393 lines · cpp
1// RUN: %clang_cc1 -std=c++98 -pedantic-errors -verify=expected,cxx98 %s2// RUN: %clang_cc1 -std=c++11 -pedantic-errors -verify=expected,since-cxx11,cxx11-23 %s3// RUN: %clang_cc1 -std=c++14 -pedantic-errors -verify=expected,since-cxx11,cxx11-23 %s4// RUN: %clang_cc1 -std=c++17 -pedantic-errors -verify=expected,since-cxx11,cxx11-23 %s5// RUN: %clang_cc1 -std=c++20 -pedantic-errors -verify=expected,since-cxx11,cxx11-23,since-cxx20 %s6// RUN: %clang_cc1 -std=c++23 -pedantic-errors -verify=expected,since-cxx11,cxx11-23,since-cxx20,since-cxx23 %s7// RUN: %clang_cc1 -std=c++2c -pedantic-errors -verify=expected,since-cxx11,since-cxx20,since-cxx23,since-cxx26 %s8 9 10int main() {} // required for cwg281111 12namespace cwg2811 { // cwg2811: 3.513#if __cplusplus >= 201103L14void f() {15  (void)[&] {16    using T = decltype(main);17    // since-cxx11-error@-1 {{referring to 'main' within an expression is a Clang extension}}18  };19  using T2 = decltype(main);20  // since-cxx11-error@-1 {{referring to 'main' within an expression is a Clang extension}}21}22 23using T = decltype(main);24// since-cxx11-error@-1 {{referring to 'main' within an expression is a Clang extension}}25 26int main();27 28using U = decltype(main);29using U2 = decltype(&main);30#endif31} // namespace cwg281132 33namespace cwg2813 { // cwg2813: 2034#if __cplusplus >= 202302L35struct X {36  X() = default;37 38  X(const X&) = delete;39  X& operator=(const X&) = delete;40 41  void f(this X self) { }42};43 44void f() {45  X{}.f();46}47#endif48} // namespace cwg281349 50namespace cwg2819 { // cwg2819: 19 c++2651#if __cplusplus >= 201103L52  // CWG 2024-04-19: This issue is not a DR.53  constexpr void* p = nullptr;54  constexpr int* q = static_cast<int*>(p); // #cwg2819-q55  // cxx11-23-error@-1 {{constexpr variable 'q' must be initialized by a constant expression}}56  //   cxx11-23-note@-2 {{cast from 'void *' is not allowed in a constant expression}}57  static_assert(q == nullptr, "");58  // cxx11-23-error@-1 {{static assertion expression is not an integral constant expression}}59  //   cxx11-23-note@-2 {{initializer of 'q' is not a constant expression}}60  //   cxx11-23-note@#cwg2819-q {{declared here}}61#endif62} // namespace cwg281963 64namespace cwg2823 { // cwg2823: no65#if __cplusplus >= 201103L66  constexpr int *p = 0;67  constexpr int *q1 = &*p;68  // expected-error@-1 {{constexpr variable 'q1' must be initialized by a constant expression}}69  //   expected-note@-2 {{dereferencing a null pointer is not allowed in a constant expression}}70  // FIXME: invalid: dereferencing a null pointer.71  constexpr int *q2 = &p[0];72 73  int arr[32];74  constexpr int *r = arr;75  // FIXME: invalid: dereferencing a past-the-end pointer.76  constexpr int *s1 = &*(r + 32);77  // FIXME: invalid: dereferencing a past-the-end pointer.78  constexpr int *s2 = &r[32];79#endif80}81 82namespace cwg2847 { // cwg2847: 19 review 2024-03-0183 84#if __cplusplus >= 202002L85 86template<typename>87void i();88 89struct A {90  template<typename>91  void f() requires true;92 93  template<>94  void f<int>() requires true;95  // since-cxx20-error@-1 {{explicit specialization cannot have a trailing requires clause unless it declares a function template}}96 97  friend void i<int>() requires true;98  // since-cxx20-error@-1 {{friend specialization cannot have a trailing requires clause unless it declares a function template}}99};100 101template<typename>102struct B {103  void f() requires true;104 105  template<typename>106  void g() requires true;107 108  template<typename>109  void h() requires true;110 111  template<>112  void h<int>() requires true;113  // since-cxx20-error@-1 {{explicit specialization cannot have a trailing requires clause unless it declares a function template}}114 115  friend void i<int>() requires true;116  // since-cxx20-error@-1 {{friend specialization cannot have a trailing requires clause unless it declares a function template}}117};118 119template<>120void B<int>::f() requires true;121// since-cxx20-error@-1 {{explicit specialization cannot have a trailing requires clause unless it declares a function template}}122 123template<>124template<typename T>125void B<int>::g() requires true;126 127#endif128 129} // namespace cwg2847130 131namespace cwg2857 { // cwg2857: no132struct A {};133template <typename>134struct D;135namespace N {136  struct B {};137  void adl_only(A*, D<int>*); // #cwg2857-adl_only138}139 140void f(A* a, D<int>* d) {141  adl_only(a, d);142  // expected-error@-1 {{use of undeclared identifier 'adl_only'; did you mean 'N::adl_only'?}}143  //   expected-note@#cwg2857-adl_only {{'N::adl_only' declared here}}144}145 146#if __cplusplus >= 201103L147template <typename>148struct D : N::B {149  // FIXME: ADL shouldn't associate it's base B and N since D is not complete here150  decltype(adl_only((A*) nullptr, (D*) nullptr)) f;151};152#endif153} // namespace cwg2857154 155namespace cwg2858 { // cwg2858: 19156 157#if __cplusplus > 202302L158 159template<typename... Ts>160struct A {161  // FIXME: The nested-name-specifier in the following friend declarations are declarative,162  // but we don't treat them as such (yet).163  friend void Ts...[0]::f();164  template<typename U>165  friend void Ts...[0]::g();166 167  friend struct Ts...[0]::B;168  // FIXME: The index of the pack-index-specifier is printed as a memory address in the diagnostic.169  template<typename U>170  friend struct Ts...[0]::C;171  // since-cxx26-warning@-1 {{dependent nested name specifier 'Ts...[0]' for friend template declaration is not supported; ignoring this friend declaration}}172};173 174#endif175 176} // namespace cwg2858177 178namespace cwg2877 { // cwg2877: 19179#if __cplusplus >= 202002L180enum E { x };181void f() {182  int E;183  using enum E;   // OK184}185using F = E;186using enum F;     // OK187template<class T> using EE = T;188void g() {189  using enum EE<E>;  // OK190}191#endif192} // namespace cwg2877193 194namespace cwg2881 { // cwg2881: 19195#if __cplusplus >= 202302L196template <typename T> struct A : T {};197template <typename T> struct B : T {};198template <typename T> struct C : virtual T { C(T t) : T(t) {} };199template <typename T> struct D : virtual T { D(T t) : T(t) {} };200 201template <typename Ts>202struct O1 : A<Ts>, B<Ts> {203  using A<Ts>::operator();204  using B<Ts>::operator();205};206 207template <typename Ts> struct O2 : protected Ts { // #cwg2881-O2208  using Ts::operator();209  O2(Ts ts) : Ts(ts) {}210};211 212template <typename Ts> struct O3 : private Ts { // #cwg2881-O3213  using Ts::operator();214  O3(Ts ts) : Ts(ts) {}215};216 217// Not ambiguous because of virtual inheritance.218template <typename Ts>219struct O4 : C<Ts>, D<Ts> {220  using C<Ts>::operator();221  using D<Ts>::operator();222  O4(Ts t) : Ts(t), C<Ts>(t), D<Ts>(t) {}223};224 225// This still has a public path to the lambda, and it's also not226// ambiguous because of virtual inheritance.227template <typename Ts>228struct O5 : private C<Ts>, D<Ts> {229  using C<Ts>::operator();230  using D<Ts>::operator();231  O5(Ts t) : Ts(t), C<Ts>(t), D<Ts>(t) {}232};233 234// This is only invalid if we call T's call operator.235template <typename T, typename U>236struct O6 : private T, U { // #cwg2881-O6237  using T::operator();238  using U::operator();239  O6(T t, U u) : T(t), U(u) {}240};241 242void f() {243  int x;244  auto L1 = [=](this auto&& self) { (void) &x; };245  auto L2 = [&](this auto&& self) { (void) &x; };246  O1<decltype(L1)>{L1, L1}();247  /* since-cxx23-error-re@-1 {{inaccessible due to ambiguity:248    struct cwg2881::O1<class (lambda at {{.+}})> -> A<class (lambda at {{.+}})> -> class (lambda at {{.+}})249    struct cwg2881::O1<class (lambda at {{.+}})> -> B<class (lambda at {{.+}})> -> class (lambda at {{.+}})}}*/250  O1<decltype(L2)>{L2, L2}();251  /* since-cxx23-error-re@-1 {{inaccessible due to ambiguity:252    struct cwg2881::O1<class (lambda at {{.+}})> -> A<class (lambda at {{.+}})> -> class (lambda at {{.+}})253    struct cwg2881::O1<class (lambda at {{.+}})> -> B<class (lambda at {{.+}})> -> class (lambda at {{.+}})}}*/254  O2{L1}();255  // since-cxx23-error-re@-1 {{invalid explicit object parameter type 'cwg2881::O2<(lambda at {{.+}})>' in lambda with capture; the type must derive publicly from the lambda}}256  //   since-cxx23-note@#cwg2881-O2 {{declared protected here}}257  O3{L1}();258  // since-cxx23-error-re@-1 {{invalid explicit object parameter type 'cwg2881::O3<(lambda at {{.+}})>' in lambda with capture; the type must derive publicly from the lambda}}259  //   since-cxx23-note@#cwg2881-O3 {{declared private here}}260  O4{L1}();261  O5{L1}();262  O6 o{L1, L2};263  o.decltype(L1)::operator()();264  // since-cxx23-error-re@-1 {{invalid explicit object parameter type 'cwg2881::O6<(lambda at {{.+}}), (lambda at {{.+}})>' in lambda with capture; the type must derive publicly from the lambda}}265  //   since-cxx23-note@#cwg2881-O6 {{declared private here}}266  o.decltype(L1)::operator()(); // No error here because we've already diagnosed this method.267  o.decltype(L2)::operator()();268}269 270void f2() {271  int x = 0;272  auto lambda = [x] (this auto self) { return x; };273  using Lambda = decltype(lambda);274  struct D : private Lambda { // #cwg2881-D275    D(Lambda l) : Lambda(l) {}276    using Lambda::operator();277    friend Lambda;278  } d(lambda);279  d();280  // since-cxx23-error@-1 {{invalid explicit object parameter type 'D' in lambda with capture; the type must derive publicly from the lambda}}281  //   since-cxx23-note@#cwg2881-D {{declared private here}}282}283 284template <typename L>285struct Private : private L {286  using L::operator();287  Private(L l) : L(l) {}288};289 290template<typename T>291struct Indirect : T {292  using T::operator();293};294 295template<typename T>296struct Ambiguous : Indirect<T>, T {297/* since-cxx23-warning-re@-1 {{direct base '(lambda at {{.+}})' is inaccessible due to ambiguity:298    struct cwg2881::Ambiguous<class (lambda at {{.+}})> -> Indirect<class (lambda at {{.+}})> -> class (lambda at {{.+}})299    struct cwg2881::Ambiguous<class (lambda at {{.+}})> -> class (lambda at {{.+}})}}*/300//   since-cxx23-note-re@#cwg2881-f4 {{in instantiation of template class 'cwg2881::Ambiguous<(lambda at {{.+}})>' requested here}}301//   since-cxx34-note-re@#cwg2881-f4-call {{while substituting deduced template arguments into function template 'f4' [with L = (lambda at {{.+}})]}}302  using Indirect<T>::operator();303};304 305template <typename L>306constexpr auto f3(L l) -> decltype(Private<L>{l}()) { return l(); } // #cwg2881-f3307 308template <typename L>309constexpr auto f4(L l) -> decltype(Ambiguous<L>{{l}, l}()) { return l(); } // #cwg2881-f4310 311template<typename T>312concept is_callable = requires(T t) { { t() }; };313 314void g() {315  int x = 0;316  auto lambda = [x](this auto self) {};317  f3(lambda);318  // since-cxx23-error@-1 {{no matching function for call to 'f3'}}319  //   since-cxx23-note-re@#cwg2881-f3 {{candidate template ignored: substitution failure [with L = (lambda at {{.+}})]: invalid explicit object parameter type 'cwg2881::Private<(lambda at {{.+}})>' in lambda with capture; the type must derive publicly from the lambda}}320  f4(lambda); // #cwg2881-f4-call321  // expected-error@-1 {{no matching function for call to 'f4'}}322  //   expected-note-re@-2 {{while substituting deduced template arguments into function template 'f4' [with L = (lambda at {{.+}})]}}323  /*   expected-note-re@#cwg2881-f4 {{candidate template ignored: substitution failure [with L = (lambda at {{.+}})]: lambda '(lambda at {{.+}})' is inaccessible due to ambiguity:324    struct cwg2881::Ambiguous<class (lambda at {{.+}})> -> Indirect<class (lambda at {{.+}})> -> class (lambda at {{.+}})325    struct cwg2881::Ambiguous<class (lambda at {{.+}})> -> class (lambda at {{.+}})}}*/326  static_assert(!is_callable<Private<decltype(lambda)>>);327  static_assert(!is_callable<Ambiguous<decltype(lambda)>>);328}329#endif330} // namespace cwg2881331 332namespace cwg2882 { // cwg2882: 2.7333struct C {334  operator void() = delete;335  // expected-warning@-1 {{conversion function converting 'cwg2882::C' to 'void' will never be used}}336  // cxx98-error@-2 {{deleted function definitions are a C++11 extension}}337};338 339void f(C c) {340  (void)c;341}342} // namespace cwg2882343 344namespace cwg2883 { // cwg2883: no345#if __cplusplus >= 201103L346void f() {347  int x;348  (void)[&] {349    return x;350  };351}352#endif353#if __cplusplus >= 202002L354struct A {355  A() = default;356  A(const A &) = delete; // #cwg2883-A-copy-ctor357  constexpr operator int() { return 42; }358};359void g() {360  constexpr A a;361  // FIXME: OK, not odr-usable from a default template argument, and not odr-used362  (void)[=]<typename T, int = a> {};363  // since-cxx20-error@-1 {{call to deleted constructor of 'const A'}}364  //   since-cxx20-note@#cwg2883-A-copy-ctor {{'A' has been explicitly marked deleted here}}365}366#endif367} // namespace cwg2883368 369namespace cwg2885 { // cwg2885: 16 review 2024-05-31370#if __cplusplus >= 202002L371template <class T>372struct A {373  A() requires (false) = default;374  A() : t(42) {}375  T t;376};377 378struct B : A<int> {};379static_assert(!__is_trivially_constructible(B));380#endif381} // namespace cwg2885382 383namespace cwg2886 { // cwg2886: 9384#if __cplusplus >= 201103L385struct C {386  C() = default;387  ~C() noexcept(false) = default;388};389 390static_assert(noexcept(C()), "");391#endif392} // namespace cwg2886393