From 738e7f1231949ec248c1d8d154783338215613d1 Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Tue, 16 Nov 2021 07:09:17 -0500 Subject: [PATCH] Fix false positive in `bugprone-throw-keyword-missing` check Fixes PR#52400. The tests for bugprone-throw-keyword-missing actually already contain exceptions as class members, but not as members with initializers, which was probably just an oversight. --- clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp | 2 +- .../test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp index 462a33a..5327a0c 100644 --- a/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp @@ -26,7 +26,7 @@ void ThrowKeywordMissingCheck::registerMatchers(MatchFinder *Finder) { isSameOrDerivedFrom(matchesName("[Ee]xception|EXCEPTION")))), unless(anyOf(hasAncestor(stmt( anyOf(cxxThrowExpr(), callExpr(), returnStmt()))), - hasAncestor(varDecl()), + hasAncestor(decl(anyOf(varDecl(), fieldDecl()))), allOf(hasAncestor(CtorInitializerList), unless(hasAncestor(cxxCatchStmt())))))) .bind("temporary-exception-not-thrown"), 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 index 5fae036..dff600c 100644 --- 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 @@ -118,6 +118,7 @@ void localVariableInitTest() { class CtorInitializerListTest { RegularException exc; + RegularException exc2{}; CtorInitializerListTest() : exc(RegularException()) {} -- 2.7.4