brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.4 KiB · 03a9228 Raw
167 lines · cpp
1// RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98-14,cxx98 -fexceptions -fcxx-exceptions -pedantic-errors2// RUN: %clang_cc1 -std=c++11 %s -verify=expected,cxx98-14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors3// RUN: %clang_cc1 -std=c++14 %s -verify=expected,cxx98-14,since-cxx14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors4// RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx17,since-cxx14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors5// RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx17,since-cxx14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors6// RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx17,since-cxx14,since-cxx11,since-cxx23 -fexceptions -fcxx-exceptions -pedantic-errors7// RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx17,since-cxx14,since-cxx11,since-cxx23 -fexceptions -fcxx-exceptions -pedantic-errors8 9// cwg1200: na10 11namespace cwg1213 { // cwg1213: 712#if __cplusplus >= 201103L13  using T = int[3];14  int &&r = T{}[1];15 16  using T = decltype((T{}));17  using U = decltype((T{}[2]));18  using U = int &&;19 20  // Same thing but in a case where we consider overloaded operator[].21  struct ConvertsToInt {22    operator int();23  };24  struct X { int array[1]; };25  using U = decltype(X().array[ConvertsToInt()]);26 27  // We apply the same rule to vector subscripting.28  typedef int V4Int __attribute__((__vector_size__(sizeof(int) * 4)));29  typedef int EV4Int __attribute__((__ext_vector_type__(4)));30  using U = decltype(V4Int()[0]);31  using U = decltype(EV4Int()[0]);32#endif33} // namespace cwg121334 35namespace cwg1223 { // cwg1223: 1736#if __cplusplus >= 201103L37struct M;38template <typename T>39struct V;40struct S {41  S* operator()();42  int N;43  int M;44#if __cplusplus >= 202302L45  template <typename T>46  static constexpr auto V = 0;47  void f(char);48  void f(int);49  void mem(S s) {50    auto(s)()->M;51    // since-cxx23-warning@-1 {{expression result unused}}52    auto(s)()->V<int>;53    // since-cxx23-warning@-1 {{expression result unused}}54    auto(s)()->f(0);55  }56#endif57};58void f(S s) {59  {60#if __cplusplus >= 202302L61    auto(s)()->N;62    //since-cxx23-warning@-1 {{expression result unused}}63#endif64    auto(s)()->M;65  }66  {67    S(s)()->N;68    // since-cxx11-warning@-1 {{expression result unused}}69    S(s)()->M;70    // since-cxx11-warning@-1 {{expression result unused}}71  }72}73 74struct A {75    A(int*);76    A *operator()();77};78typedef struct BB { int C[2]; } *B, C;79void g() {80    A a(B ()->C);81    A b(auto ()->C);82    static_assert(sizeof(B ()->C[1] == sizeof(int)), "");83    sizeof(auto () -> C[1]);84    // since-cxx11-error@-1 {{function cannot return array type 'C[1]' (aka 'struct BB[1]')}}85}86#endif87} // namespace cwg122388 89namespace cwg1227 { // cwg1227: 3.090#if __cplusplus >= 201103L91template <class T> struct A { using X = typename T::X; };92// since-cxx11-error@-1 {{type 'int' cannot be used prior to '::' because it has no members}}93//   since-cxx11-note@#cwg1227-g {{in instantiation of template class 'cwg1227::A<int>' requested here}}94//   since-cxx11-note@#cwg1227-g-int {{while substituting explicitly-specified template arguments into function template 'g'}}95template <class T> typename T::X f(typename A<T>::X);96template <class T> void f(...) { }97template <class T> auto g(typename A<T>::X) -> typename T::X; // #cwg1227-g98template <class T> void g(...) { }99 100void h() {101  f<int>(0); // OK, substituting return type causes deduction to fail102  g<int>(0); // #cwg1227-g-int103}104#endif105} // namespace cwg1227106 107namespace cwg1250 { // cwg1250: 3.9108struct Incomplete;109 110struct Base {111  virtual const Incomplete *meow() = 0;112};113 114struct Derived : Base {115  virtual Incomplete *meow();116};117} // namespace cwg1250118 119namespace cwg1265 { // cwg1265: 5120#if __cplusplus >= 201103L121  auto a = 0, b() -> int;122  // since-cxx11-error@-1 {{declaration with trailing return type must be the only declaration in its group}}123  auto b() -> int, d = 0;124  // since-cxx11-error@-1 {{declaration with trailing return type must be the only declaration in its group}}125  auto e() -> int, f() -> int;126  // since-cxx11-error@-1 {{declaration with trailing return type must be the only declaration in its group}}127#endif128 129#if __cplusplus >= 201402L130  auto g(), h = 0;131  // since-cxx14-error@-1 {{function with deduced return type must be the only declaration in its group}}132  auto i = 0, j();133  // since-cxx14-error@-1 {{function with deduced return type must be the only declaration in its group}}134  auto k(), l();135  // since-cxx14-error@-1 {{function with deduced return type must be the only declaration in its group}}136#endif137} // namespace cwg1265138 139// cwg1291: na140 141namespace cwg1295 { // cwg1295: 4142  struct X {143    unsigned bitfield : 4;144  };145 146  X x = {1};147 148  unsigned const &r1 = static_cast<X &&>(x).bitfield;149  // cxx98-error@-1 {{rvalue references are a C++11 extension}}150  unsigned const &r2 = static_cast<unsigned &&>(x.bitfield);151  // cxx98-error@-1 {{rvalue references are a C++11 extension}}152 153  template<unsigned &r> struct Y {}; // #cwg1295-Y154  Y<x.bitfield> y; // #cwg1295-y155  // cxx98-14-error@-1 {{non-type template argument does not refer to any declaration}}156  //   cxx98-14-note@#cwg1295-Y {{template parameter is declared here}}157  // since-cxx17-error@#cwg1295-y {{reference cannot bind to bit-field in converted constant expression}}158  //   since-cxx17-note@#cwg1295-Y {{template parameter is declared here}}159 160 161#if __cplusplus >= 201103L162  const unsigned other = 0;163  using T = decltype(true ? other : x.bitfield);164  using T = unsigned;165#endif166} // namespace cwg1295167