From 222e2a7620e6520ffaf4fc4e69d79c18da31542e Mon Sep 17 00:00:00 2001 From: "Zancanaro; Carlo" Date: Mon, 24 Sep 2012 09:58:17 +1000 Subject: Add the clang library to the repo (with some of my changes, too). --- clang/test/SemaCXX/implicit-exception-spec.cpp | 89 ++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 clang/test/SemaCXX/implicit-exception-spec.cpp (limited to 'clang/test/SemaCXX/implicit-exception-spec.cpp') diff --git a/clang/test/SemaCXX/implicit-exception-spec.cpp b/clang/test/SemaCXX/implicit-exception-spec.cpp new file mode 100644 index 0000000..25316f8 --- /dev/null +++ b/clang/test/SemaCXX/implicit-exception-spec.cpp @@ -0,0 +1,89 @@ +// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -std=c++11 -Wall %s + +template struct ExceptionIf { static int f(); }; +template<> struct ExceptionIf { typedef int f; }; + +// The exception specification of a defaulted default constructor depends on +// the contents of in-class member initializers. However, the in-class member +// initializers can depend on the exception specification of the constructor, +// since the class is considered complete within them. We reject any such cases. +namespace InClassInitializers { + // Noexcept::Noexcept() is implicitly declared as noexcept(false), because it + // directly invokes ThrowSomething(). However... + // + // If noexcept(Noexcept()) is false, then Noexcept() is a constant expression, + // so noexcept(Noexcept()) is true. But if noexcept(Noexcept()) is true, then + // Noexcept::Noexcept is not declared constexpr, therefore noexcept(Noexcept()) + // is false. + bool ThrowSomething() noexcept(false); + struct ConstExpr { + bool b = noexcept(ConstExpr()) && ThrowSomething(); // expected-error {{exception specification is not available until end of class definition}} + }; + // We can use it now. + bool w = noexcept(ConstExpr()); + + // Much more obviously broken: we can't parse the initializer without already + // knowing whether it produces a noexcept expression. + struct TemplateArg { + int n = ExceptionIf::f(); // expected-error {{exception specification is not available until end of class definition}} + }; + bool x = noexcept(TemplateArg()); + + // And within a nested class. + struct Nested { + struct Inner { + int n = ExceptionIf::f(); // expected-error {{exception specification is not available until end of class definition}} + } inner; + }; + bool y = noexcept(Nested()); + bool z = noexcept(Nested::Inner()); +} + +namespace ExceptionSpecification { + // A type is permitted to be used in a dynamic exception specification when it + // is still being defined, but isn't complete within such an exception + // specification. + struct Nested { // expected-note {{not complete}} + struct T { + T() noexcept(!noexcept(Nested())); // expected-error{{incomplete type}} + } t; + }; +} + +namespace DefaultArgument { + struct Default { + struct T { + T(int = ExceptionIf