diff --git a/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp --- a/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp @@ -24,11 +24,13 @@ cxxConstructExpr( hasType(cxxRecordDecl( isSameOrDerivedFrom(matchesName("[Ee]xception|EXCEPTION")))), - unless(anyOf(hasAncestor(stmt( - anyOf(cxxThrowExpr(), callExpr(), returnStmt()))), - hasAncestor(decl(anyOf(varDecl(), fieldDecl()))), - allOf(hasAncestor(CtorInitializerList), - unless(hasAncestor(cxxCatchStmt())))))) + unless(anyOf( + hasAncestor( + stmt(anyOf(cxxThrowExpr(), callExpr(), returnStmt()))), + hasAncestor(decl(anyOf(varDecl(), fieldDecl()))), + hasAncestor(expr(cxxNewExpr(hasAnyPlacementArg(anything())))), + allOf(hasAncestor(CtorInitializerList), + unless(hasAncestor(cxxCatchStmt())))))) .bind("temporary-exception-not-thrown"), this); } diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -148,6 +148,10 @@ - Fixed a false positive in :doc:`fuchsia-trailing-return ` for C++17 deduction guides. + +- Fixed a false positive in :doc:`bugprone-throw-keyword-missing + ` when creating an exception object + using placement new Removed checks ^^^^^^^^^^^^^^ diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp @@ -175,3 +175,14 @@ void exceptionRAIITest() { ExceptionRAII E; } + +namespace std { +typedef decltype(sizeof(void*)) size_t; +} + +void* operator new(std::size_t, void*); + +void placeMentNewTest() { + alignas(RegularException) unsigned char expr[sizeof(RegularException)]; + new (expr) RegularException{}; +}