brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.4 KiB · 087561e Raw
212 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -std=c++11 -Wall %s2 3struct Bitfield {4  int n : 3 = 7; // expected-warning {{C++20 extension}} expected-warning {{changes value from 7 to -1}}5};6 7int a;8class NoWarning {9  int &n = a;10public:11  int &GetN() { return n; }12};13 14bool b();15int k;16struct Recurse { // expected-error {{initializer for 'n' needed}}17  int &n = // expected-note {{declared here}}18      b() ?19      Recurse().n : // expected-note {{in evaluation of exception spec}}20      k;21};22 23struct UnknownBound {24  int as[] = { 1, 2, 3 }; // expected-error {{array bound cannot be deduced from a default member initializer}}25  int bs[4] = { 4, 5, 6, 7 };26  int cs[] = { 8, 9, 10 }; // expected-error {{array bound cannot be deduced from a default member initializer}}27};28 29template<int n> struct T { static const int B; };30template<> struct T<2> { template<int C, int D> using B = int; };31const int C = 0, D = 0;32struct S {33  int as[] = { decltype(x)::B<C, D>(0) }; // expected-error {{array bound cannot be deduced from a default member initializer}}34  T<sizeof(as) / sizeof(int)> x;35  // test that we handle invalid array bound deductions without crashing when the declarator name is itself invalid36  operator int[](){}; // expected-error {{'operator int' cannot be the name of a variable or data member}} \37                      // expected-error {{array bound cannot be deduced from a default member initializer}}38};39 40struct ThrowCtor { ThrowCtor(int) noexcept(false); };41struct NoThrowCtor { NoThrowCtor(int) noexcept(true); };42 43struct Throw { ThrowCtor tc = 42; };44struct NoThrow { NoThrowCtor tc = 42; };45 46static_assert(!noexcept(Throw()), "incorrect exception specification");47static_assert(noexcept(NoThrow()), "incorrect exception specification");48 49struct CheckExcSpec {50  CheckExcSpec() noexcept(true) = default;51  int n = 0;52};53struct CheckExcSpecFail {54  CheckExcSpecFail() noexcept(true) = default; // ok, but calls terminate() on exception55  ThrowCtor tc = 123;56};57 58struct TypedefInit {59  typedef int A = 0; // expected-error {{illegal initializer}}60};61 62// PR1057863namespace PR10578 {64  template<typename T>65  struct X { 66    X() {67      T* x = 1; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}} expected-warning {{unused variable}}68    }69  };70 71  struct Y : X<int> {72    Y();73  };74 75  Y::Y() try { // expected-note{{in instantiation of member function 'PR10578::X<int>::X' requested here}}76  } catch(...) {77  }78}79 80namespace PR14838 {81  struct base { ~base() {} };82  class function : base {83    ~function() {} // expected-note {{implicitly declared private here}}84  public:85    function(...) {}86  };87  struct thing {};88  struct another {89    another() : r(thing()) {} // expected-error {{binds to a temporary object}}90    // expected-error@-1 {{temporary of type 'function' has private destructor}}91    const function &r; // expected-note {{reference member declared here}}92  } af;93}94 95namespace rdar14084171 {96  struct Point { // expected-note 3 {{candidate constructor}}97    double x;98    double y;99  };100  struct Sprite {101    Point location = Point(0,0); // expected-error {{no matching constructor for initialization of 'Point'}}102  };103  void f(Sprite& x) { x = x; } // expected-warning {{explicitly assigning value of variable}}104}105 106namespace PR18560 {107  struct X { int m; };108 109  template<typename T = X,110           typename U = decltype(T::m)>111  int f();112 113  struct Y { int b = f(); };114}115 116namespace template_valid {117// Valid, we shouldn't build a CXXDefaultInitExpr until A's ctor definition.118struct A {119  A();120  template <typename T>121  struct B { int m1 = sizeof(A) + sizeof(T); };122  B<int> m2;123};124A::A() {}125}126 127namespace template_default_ctor {128struct A {129  template <typename T>130  struct B { // expected-error {{initializer for 'm1' needed}}131    int m1 = 0; // expected-note {{declared here}}132  };133  enum { NOE = noexcept(B<int>()) }; // expected-note {{in evaluation of exception spec}}134};135}136 137namespace default_ctor {138struct A {139  struct B { // expected-error {{initializer for 'm1' needed}}140    int m1 = 0; // expected-note {{declared here}}141  };142  enum { NOE = noexcept(B()) }; // expected-note {{in evaluation of exception spec}}143};144}145 146namespace member_template {147struct A {148  template <typename T>149  struct B {150    struct C { // expected-error {{initializer for 'm1' needed}}151      int m1 = 0; // expected-note {{declared here}}152    };153    template <typename U>154    struct D { // expected-error {{initializer for 'm1' needed}}155      int m1 = 0; // expected-note {{declared here}}156    };157  };158  enum {159    NOE1 = noexcept(B<int>::C()), // expected-note {{in evaluation of exception spec}}160    NOE2 = noexcept(B<int>::D<int>()) // expected-note {{in evaluation of exception spec}}161  };162};163}164 165namespace explicit_instantiation {166template<typename T> struct X {167  X();168  int n = T::error; // expected-error {{type 'float' cannot be used prior to '::' because it has no members}}169};170template struct X<int>; // ok171template<typename T> X<T>::X() {} // expected-note {{in instantiation of default member initializer 'explicit_instantiation::X<float>::n' requested here}}172template struct X<float>; // expected-note {{in instantiation of member function 'explicit_instantiation::X<float>::X' requested here}}173}174 175namespace local_class {176template<typename T> void f() {177  struct X { // expected-note {{in instantiation of default member initializer 'local_class::f()::X::n' requested here}}178    int n = T::error; // expected-error {{type 'int' cannot be used prior to '::' because it has no members}}179  };180}181void g() { f<int>(); } // expected-note {{in instantiation of function template specialization 'local_class::f<int>' requested here}}182}183 184namespace PR22056 {185template <int N>186struct S {187  int x[3] = {[N] = 3}; // expected-warning {{C99 extension}}188};189}190 191namespace PR28060 {192template <class T>193void foo(T v) {194  struct s {195    T *s = 0;196  };197}198template void foo(int);199}200 201namespace GH26057 {202template<typename T>203struct S {204  S();205  int dm = T::error; // expected-error {{type 'int' cannot be used prior to '::' because it has no members}}206};207template<typename T>208S<T>::S() = default; // expected-note {{in instantiation of default member initializer 'GH26057::S<int>::dm' requested here}} \209                     // expected-note {{in evaluation of exception specification for 'GH26057::S<int>::S' needed here}}210template struct S<int>; // expected-note {{in instantiation of member function 'GH26057::S<int>::S' requested here}}211}212