Author: aaronballman Date: Thu Nov 19 14:45:35 2015 New Revision: 253598 URL: http://llvm.org/viewvc/llvm-project?rev=253598&view=rev Log: Test to ensure the function does not have an unresolved or unevaluated exception specification before testing whether the function throws or not. Fixes PR25574.
Modified: clang-tools-extra/trunk/clang-tidy/cert/ThrownExceptionTypeCheck.cpp clang-tools-extra/trunk/test/clang-tidy/cert-throw-exception-type.cpp Modified: clang-tools-extra/trunk/clang-tidy/cert/ThrownExceptionTypeCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cert/ThrownExceptionTypeCheck.cpp?rev=253598&r1=253597&r2=253598&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/cert/ThrownExceptionTypeCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/cert/ThrownExceptionTypeCheck.cpp Thu Nov 19 14:45:35 2015 @@ -19,9 +19,12 @@ AST_MATCHER(CXXConstructorDecl, isNoThro if (!Node.isCopyConstructor()) return false; - if (const auto *FnTy = Node.getType()->getAs<FunctionProtoType>()) - return FnTy->isNothrow(Node.getASTContext()); - llvm_unreachable("Copy constructor with no prototype"); + const auto *FnTy = Node.getType()->getAs<FunctionProtoType>(); + // Assume the best for any unresolved exception specification. + if (isUnresolvedExceptionSpec(FnTy->getExceptionSpecType())) + return true; + + return FnTy->isNothrow(Node.getASTContext()); } } // end namespace @@ -36,7 +39,6 @@ void ThrownExceptionTypeCheck::registerM isCopyConstructor(), unless(isNoThrowCopyConstructor())))) .bind("expr"))), this); - } void ThrownExceptionTypeCheck::check(const MatchFinder::MatchResult &Result) { Modified: clang-tools-extra/trunk/test/clang-tidy/cert-throw-exception-type.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cert-throw-exception-type.cpp?rev=253598&r1=253597&r2=253598&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/cert-throw-exception-type.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/cert-throw-exception-type.cpp Thu Nov 19 14:45:35 2015 @@ -108,5 +108,20 @@ void f() { throw Allocates(); // match, copy constructor throws // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: thrown exception type is not nothrow copy constructible throw OptionallyAllocates(); // ok +} + +namespace PR25574 { +struct B { + B(const B&) noexcept; +}; +struct D : B { + D(); + virtual ~D() noexcept; +}; + +template <typename T> +void f() { + throw D(); +} } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits