From 7442d6faa2719e4e7d33a7021c406c5a4facd74d Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sun, 16 Apr 2017 16:02:28 +0000 Subject: Vendor import of clang trunk r300422: https://llvm.org/svn/llvm-project/cfe/trunk@300422 --- test/SemaCXX/implicit-exception-spec.cpp | 58 ++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'test/SemaCXX/implicit-exception-spec.cpp') diff --git a/test/SemaCXX/implicit-exception-spec.cpp b/test/SemaCXX/implicit-exception-spec.cpp index fc86d1810ba5a..f400c222de83c 100644 --- a/test/SemaCXX/implicit-exception-spec.cpp +++ b/test/SemaCXX/implicit-exception-spec.cpp @@ -92,3 +92,61 @@ namespace ImplicitDtorExceptionSpec { } e; }; } + +struct nothrow_t {} nothrow; +void *operator new(decltype(sizeof(0)), nothrow_t) noexcept; + +namespace PotentiallyConstructed { + template struct A { + A() noexcept(NE); + A(const A&) noexcept(NE); + A(A&&) noexcept(NE); + A &operator=(const A&) noexcept(NE); + A &operator=(A&&) noexcept(NE); + ~A() noexcept(NE); + }; + + template struct B : virtual A {}; + + template struct C : virtual A { + virtual void f() = 0; // expected-note 2{{unimplemented}} + }; + + template struct D final : C { + void f(); + }; + + template void check() { + T *p = nullptr; + T &a = *p; + static_assert(noexcept(a = a) == D, ""); + static_assert(noexcept(a = static_cast(a)) == E, ""); + static_assert(noexcept(delete &a) == F, ""); // expected-warning 2{{abstract}} + + // These are last because the first failure here causes instantiation to bail out. + static_assert(noexcept(new (nothrow) T()) == A, ""); // expected-error 2{{abstract}} + static_assert(noexcept(new (nothrow) T(a)) == B, ""); + static_assert(noexcept(new (nothrow) T(static_cast(a))) == C, ""); + } + + template void check, 0, 0, 0, 0, 0, 0>(); + template void check, 1, 1, 1, 1, 1, 1>(); + template void check, 0, 0, 0, 0, 0, 0>(); + template void check, 1, 1, 1, 1, 1, 1>(); + template void check, 1, 1, 1, 0, 0, 0>(); // expected-note {{instantiation}} + template void check, 1, 1, 1, 1, 1, 1>(); // expected-note {{instantiation}} + template void check, 0, 0, 0, 0, 0, 0>(); + template void check, 1, 1, 1, 1, 1, 1>(); + + // ... the above trick doesn't work for this case... + struct Cfalse : virtual A { + virtual void f() = 0; + + Cfalse() noexcept; + Cfalse(const Cfalse&) noexcept; + Cfalse(Cfalse&&) noexcept; + }; + Cfalse::Cfalse() noexcept = default; + Cfalse::Cfalse(const Cfalse&) noexcept = default; + Cfalse::Cfalse(Cfalse&&) noexcept = default; +} -- cgit v1.2.3