summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/implicit-exception-spec.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2017-02-25 23:53:05 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2017-02-25 23:53:05 +0000
commitdf054d3d22673c7c8000083011cfa61e67b102e3 (patch)
treedf38d1ddb7e786edd4fb6e2b054758ec96ad5926 /clang/test/SemaCXX/implicit-exception-spec.cpp
parent4897cea4edb4f2211ddf515a834e4e11779e2827 (diff)
downloadbcm5719-llvm-df054d3d22673c7c8000083011cfa61e67b102e3.tar.gz
bcm5719-llvm-df054d3d22673c7c8000083011cfa61e67b102e3.zip
C++ DR1611, 1658, 2180: implement "potentially constructed subobject" rules for special member functions.
Essentially, as a base class constructor does not construct virtual bases, such a constructor for an abstract class does not need the corresponding base class construction to be valid, and likewise for destructors. This creates an awkward situation: clang will sometimes generate references to the complete object and deleting destructors for an abstract class (it puts them in the construction vtable for a derived class). But we can't generate a "correct" version of these because we can't generate references to base class constructors any more (if they're template specializations, say, we might not have instantiated them and can't assume any other TU will emit a copy). Fortunately, we don't need to, since no correct program can ever invoke them, so instead emit symbols that just trap. We should stop emitting references to these symbols, but still need to emit definitions for compatibility. llvm-svn: 296275
Diffstat (limited to 'clang/test/SemaCXX/implicit-exception-spec.cpp')
-rw-r--r--clang/test/SemaCXX/implicit-exception-spec.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/implicit-exception-spec.cpp b/clang/test/SemaCXX/implicit-exception-spec.cpp
index fc86d1810ba..f400c222de8 100644
--- a/clang/test/SemaCXX/implicit-exception-spec.cpp
+++ b/clang/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<bool NE> 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<bool NE> struct B : virtual A<NE> {};
+
+ template<bool NE> struct C : virtual A<NE> {
+ virtual void f() = 0; // expected-note 2{{unimplemented}}
+ };
+
+ template<bool NE> struct D final : C<NE> {
+ void f();
+ };
+
+ template<typename T, bool A, bool B, bool C, bool D, bool E, bool F> void check() {
+ T *p = nullptr;
+ T &a = *p;
+ static_assert(noexcept(a = a) == D, "");
+ static_assert(noexcept(a = static_cast<T&&>(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<T&&>(a))) == C, "");
+ }
+
+ template void check<A<false>, 0, 0, 0, 0, 0, 0>();
+ template void check<A<true >, 1, 1, 1, 1, 1, 1>();
+ template void check<B<false>, 0, 0, 0, 0, 0, 0>();
+ template void check<B<true >, 1, 1, 1, 1, 1, 1>();
+ template void check<C<false>, 1, 1, 1, 0, 0, 0>(); // expected-note {{instantiation}}
+ template void check<C<true >, 1, 1, 1, 1, 1, 1>(); // expected-note {{instantiation}}
+ template void check<D<false>, 0, 0, 0, 0, 0, 0>();
+ template void check<D<true >, 1, 1, 1, 1, 1, 1>();
+
+ // ... the above trick doesn't work for this case...
+ struct Cfalse : virtual A<false> {
+ 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;
+}
OpenPOWER on IntegriCloud