Example #1
0
void dr1891() { // dr1891: 4.0
#if __cplusplus >= 201103L
  int n;
  auto a = []{}; // expected-note 2{{candidate}} expected-note 2{{here}}
  auto b = [=]{ return n; }; // expected-note 2{{candidate}} expected-note 2{{here}}
  typedef decltype(a) A;
  typedef decltype(b) B;

  static_assert(!__has_trivial_constructor(A), "");
  static_assert(!__has_trivial_constructor(B), "");

  A x; // expected-error {{no matching constructor}}
  B y; // expected-error {{no matching constructor}}

  a = a; // expected-error {{copy assignment operator is implicitly deleted}}
  a = static_cast<A&&>(a); // expected-error {{copy assignment operator is implicitly deleted}}
  b = b; // expected-error {{copy assignment operator is implicitly deleted}}
  b = static_cast<B&&>(b); // expected-error {{copy assignment operator is implicitly deleted}}
#endif
}
bool nas4 = __has_nothrow_assign(void);
bool nas5 = __has_nothrow_assign(const void);

bool tas1 = __has_trivial_assign(I); // { dg-error "incomplete type" }
bool tas2 = __has_trivial_assign(C[]);
bool tas3 = __has_trivial_assign(I[]); // { dg-error "incomplete type" }
bool tas4 = __has_trivial_assign(void);
bool tas5 = __has_trivial_assign(const void);

bool nco1 = __has_nothrow_constructor(I); // { dg-error "incomplete type" }
bool nco2 = __has_nothrow_constructor(C[]);
bool nco3 = __has_nothrow_constructor(I[]); // { dg-error "incomplete type" }
bool nco4 = __has_nothrow_constructor(void);
bool nco5 = __has_nothrow_constructor(const void);

bool tco1 = __has_trivial_constructor(I); // { dg-error "incomplete type" }
bool tco2 = __has_trivial_constructor(C[]);
bool tco3 = __has_trivial_constructor(I[]); // { dg-error "incomplete type" }
bool tco4 = __has_trivial_constructor(void);
bool tco5 = __has_trivial_constructor(const void);

bool ncp1 = __has_nothrow_copy(I); // { dg-error "incomplete type" }
bool ncp2 = __has_nothrow_copy(C[]);
bool ncp3 = __has_nothrow_copy(I[]); // { dg-error "incomplete type" }
bool ncp4 = __has_nothrow_copy(void);
bool ncp5 = __has_nothrow_copy(const void);

bool tcp1 = __has_trivial_copy(I); // { dg-error "incomplete type" }
bool tcp2 = __has_trivial_copy(C[]);
bool tcp3 = __has_trivial_copy(I[]); // { dg-error "incomplete type" }
bool tcp4 = __has_trivial_copy(void);
Example #3
0
void test_delete(int *p) {
  // We can call the normal global deallocation function even though it has only
  // ever been explicitly declared in an unimported submodule.
  delete p;
}

void friend_1(HasFriends s) {
  s.private_thing();
}
void test_friends(HasFriends s) {
  friend_1(s);
  friend_2(s);
}

static_assert(!__is_trivial(HasNontrivialDefaultConstructor), "");
static_assert(!__has_trivial_constructor(HasNontrivialDefaultConstructor), "");

void use_implicit_new_again() { operator new[](3); }

int importMergeUsedFlag = getMergeUsedFlag();

int use_name_for_linkage(NameForLinkage &nfl) {
  return nfl.n + nfl.m;
}
int use_overrides_virtual_functions(OverridesVirtualFunctions ovf) { return 0; }

@import cxx_decls_merged;

NameForLinkage2Inner use_name_for_linkage2_inner;
NameForLinkage2 use_name_for_linkage2;
 bool
 f()
 { return !!__has_trivial_constructor(T); }
    bool
    f()
    { return !!__has_trivial_constructor(T); }
  };

template<typename T>
  class My2
  {
  public:
    static const bool trait = __has_trivial_constructor(T);
  };

template<typename T>
  const bool My2<T>::trait;

template<typename T, bool b = __has_trivial_constructor(T)>
  struct My3_help
  { static const bool trait = b; };

template<typename T, bool b>
  const bool My3_help<T, b>::trait;

template<typename T>
  class My3
  {
  public:
    bool
    f()
    { return My3_help<T>::trait; }
  };
Example #6
0
struct Deleted7f : virtual PrivateDtor {}; // expected-note {{here}}
Deleted7f d7f; // expected-error {{deleted constructor}}
struct Deleted7g { PrivateDtor a; }; // expected-note {{here}}
Deleted7g d7g; // expected-error {{deleted constructor}}
struct Deleted7h { PrivateDtor a = {}; }; // expected-note {{here}}
Deleted7h d7h; // expected-error {{deleted constructor}}
struct NotDeleted7i : Friend {};
NotDeleted7i d7i;
struct NotDeleted7j : virtual Friend {};
NotDeleted7j d7j;
struct NotDeleted7k { Friend a; };
NotDeleted7k d7k;


class Trivial { static const int n = 42; };
static_assert(__has_trivial_constructor(Trivial), "Trivial is nontrivial");

// A default constructor is trivial if it is not user-provided and if:
class NonTrivialDefCtor1 { NonTrivialDefCtor1(); };
static_assert(!__has_trivial_constructor(NonTrivialDefCtor1), "NonTrivialDefCtor1 is trivial");

// - its class has no virtual functions (10.3) and no virtual base classes (10.1), and
class NonTrivialDefCtor2 { virtual void f(); };
static_assert(!__has_trivial_constructor(NonTrivialDefCtor2), "NonTrivialDefCtor2 is trivial");
class NonTrivialDefCtor3 : virtual Trivial {};
static_assert(!__has_trivial_constructor(NonTrivialDefCtor3), "NonTrivialDefCtor3 is trivial");

// - no non-static data member of its class has a brace-or-equal-initializer, and
class NonTrivialDefCtor4 { int m = 52; };
static_assert(!__has_trivial_constructor(NonTrivialDefCtor4), "NonTrivialDefCtor4 is trivial");
Example #7
0
 concept bool Trivially_constructible() { return __has_trivial_constructor(T); }
  bar& operator = (const bar&);
  bar& operator = (bar&&);
  ~bar();
};

bar::bar() = default;
bar::bar(const bar&) = default;
bar::bar(bar&&) = default;
bar& bar::operator = (const bar&) = default;
bar& bar::operator = (bar&&) = default;
bar::~bar() = default;

static_assert(__is_trivial(foo), "foo should be trivial");

static_assert(!__has_trivial_destructor(bar), "bar's destructor isn't trivial");
static_assert(!__has_trivial_constructor(bar),
              "bar's default constructor isn't trivial");
static_assert(!__has_trivial_copy(bar), "bar has no trivial copy");
static_assert(!__has_trivial_assign(bar), "bar has no trivial assign");

void tester() {
  foo f, g(f);
  bar b, c(b);
  f = g;
  b = c;
}

template<typename T> struct S : T {
  constexpr S() = default;
  constexpr S(const S&) = default;
  constexpr S(S&&) = default;
Example #9
0
void test01()
{
  static_assert(__has_trivial_constructor(b), "default ctor not trivial");
}