[clang-tools-extra] Fix false positive in bugprone-throw-keyword-missing (PR #115302)

2024-11-09 Thread LLVM Continuous Integration via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-aarch64-linux-bootstrap-asan` running on `sanitizer-buildbot7` while 
building `clang-tools-extra` at step 2 "annotate".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/24/builds/2580


Here is the relevant piece of the build log for the reference

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 83643 of 83644 tests, 48 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
FAIL: lld :: ELF/riscv-attributes.s (82787 of 83643)
 TEST 'lld :: ELF/riscv-attributes.s' FAILED 

Exit Code: 1

Command Output (stderr):
--
RUN: at line 3: rm -rf 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/ELF/Output/riscv-attributes.s.tmp
 && split-file 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/lld/test/ELF/riscv-attributes.s
 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/ELF/Output/riscv-attributes.s.tmp
 && cd 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/ELF/Output/riscv-attributes.s.tmp
+ rm -rf 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/ELF/Output/riscv-attributes.s.tmp
+ split-file 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/lld/test/ELF/riscv-attributes.s
 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/ELF/Output/riscv-attributes.s.tmp
+ cd 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/ELF/Output/riscv-attributes.s.tmp
RUN: at line 4: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-mc
 -filetype=obj -triple=riscv64 a.s -o a.o
+ 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-mc
 -filetype=obj -triple=riscv64 a.s -o a.o
RUN: at line 5: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld.lld 
-e 0 a.o -o out 2>&1 | 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/count 0
+ 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld.lld 
-e 0 a.o -o out
+ 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/count 0
RUN: at line 6: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-readelf
 -S -l --arch-specific out | 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck
 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/lld/test/ELF/riscv-attributes.s
 --check-prefixes=HDR,CHECK
+ 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-readelf
 -S -l --arch-specific out
+ 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck
 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/lld/test/ELF/riscv-attributes.s
 --check-prefixes=HDR,CHECK
RU

[clang-tools-extra] Fix false positive in bugprone-throw-keyword-missing (PR #115302)

2024-11-09 Thread LLVM Continuous Integration via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-x86_64-linux-bootstrap-asan` running on `sanitizer-buildbot1` while 
building `clang-tools-extra` at step 2 "annotate".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/52/builds/3602


Here is the relevant piece of the build log for the reference

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 87034 of 87035 tests, 88 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
FAIL: lld :: MachO/why-live.s (86731 of 87034)
 TEST 'lld :: MachO/why-live.s' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 3: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-mc 
-filetype=obj -triple=x86_64-apple-macos 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/lld/test/MachO/why-live.s
 -o 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/MachO/Output/why-live.s.tmp.o
+ 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-mc 
-filetype=obj -triple=x86_64-apple-macos 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/lld/test/MachO/why-live.s
 -o 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/MachO/Output/why-live.s.tmp.o
RUN: at line 4: ld64.lld -arch x86_64 -platform_version macos 11.0 11.0 
-syslibroot 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/lld/test/MachO/Inputs/MacOSX.sdk
 -lSystem -fatal_warnings -lSystem -dead_strip -why_live _foo -why_live _undef 
-U _undef-why_live _support -why_live _support_refs_dylib_fun-why_live 
_abs 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/MachO/Output/why-live.s.tmp.o
 -o /dev/null 2>&1 | 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck
 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/lld/test/MachO/why-live.s
+ ld64.lld -arch x86_64 -platform_version macos 11.0 11.0 -syslibroot 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/lld/test/MachO/Inputs/MacOSX.sdk
 -lSystem -fatal_warnings -lSystem -dead_strip -why_live _foo -why_live _undef 
-U _undef -why_live _support -why_live _support_refs_dylib_fun -why_live _abs 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/MachO/Output/why-live.s.tmp.o
 -o /dev/null
+ 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck
 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/lld/test/MachO/why-live.s
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/lld/test/MachO/why-live.s:25:15:
 error: CHECK-EMPTY: is not on the line after the previous match
# CHECK-EMPTY:
  ^
:11:1: note: 'next' match was here

^
:9:124: note: previous match ended here
 _foo from 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/

[clang-tools-extra] Fix false positive in bugprone-throw-keyword-missing (PR #115302)

2024-11-09 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp closed 
https://github.com/llvm/llvm-project/pull/115302
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Fix false positive in bugprone-throw-keyword-missing (PR #115302)

2024-11-09 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/115302

>From c6ad9d042612c63cb9862782f17082e07277fc2a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 6 Nov 2024 08:52:06 +
Subject: [PATCH 1/2] Fix false positive in bugprone-throw-keyword-missing

Fixes #115055
---
 .../clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp  | 5 +
 clang-tools-extra/docs/ReleaseNotes.rst   | 4 
 .../checkers/bugprone/throw-keyword-missing.cpp   | 8 
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
index 64c155c29cf8b9..17d2e75e4f666f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
@@ -15,9 +15,6 @@ using namespace clang::ast_matchers;
 namespace clang::tidy::bugprone {
 
 void ThrowKeywordMissingCheck::registerMatchers(MatchFinder *Finder) {
-  auto CtorInitializerList =
-  cxxConstructorDecl(hasAnyConstructorInitializer(anything()));
-
   Finder->addMatcher(
   cxxConstructExpr(
   hasType(cxxRecordDecl(
@@ -27,7 +24,7 @@ void ThrowKeywordMissingCheck::registerMatchers(MatchFinder 
*Finder) {
   stmt(anyOf(cxxThrowExpr(), callExpr(), returnStmt(,
   hasAncestor(decl(anyOf(varDecl(), fieldDecl(,
   hasAncestor(expr(cxxNewExpr(hasAnyPlacementArg(anything(),
-  allOf(hasAncestor(CtorInitializerList),
+  allOf(hasAncestor(cxxConstructorDecl()),
 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
index 51ba157ab05deb..e3294c12896357 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -177,6 +177,10 @@ Changes in existing checks
   usages of ``sizeof()``, ``alignof()``, and ``offsetof()`` when adding or
   subtracting from a pointer directly or when used to scale a numeric value.
 
+- Improved :doc:`bugprone-throw-keyword-missing
+  ` by fixing a false 
positive
+  when using non-static member initializers and a constructor.
+
 - Improved :doc:`bugprone-unchecked-optional-access
   ` to support
   `bsl::optional` and `bdlb::NullableValue` from
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 49233c0deefdf0..aa4bccb109f3f3 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
@@ -139,6 +139,14 @@ CtorInitializerListTest::CtorInitializerListTest(float) 
try : exc(RegularExcepti
   RegularException();
 }
 
+// https://github.com/llvm/llvm-project/issues/115055
+class CtorInitializerListTest2 {
+ public:
+  CtorInitializerListTest2(){}
+ private:
+  RegularException exc{};
+};
+
 RegularException funcReturningExceptionTest(int i) {
   return RegularException();
 }

>From 9c4caf2ad8b13c721d9b64c96b86da4384edeb35 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Sat, 9 Nov 2024 20:46:23 +
Subject: [PATCH 2/2] Fix review comments

---
 .../clang-tidy/checkers/bugprone/throw-keyword-missing.cpp   | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

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 aa4bccb109f3f3..bafd3d19b5a319 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
@@ -139,13 +139,14 @@ CtorInitializerListTest::CtorInitializerListTest(float) 
try : exc(RegularExcepti
   RegularException();
 }
 
-// https://github.com/llvm/llvm-project/issues/115055
+namespace GH115055 {
 class CtorInitializerListTest2 {
  public:
-  CtorInitializerListTest2(){}
+  CtorInitializerListTest2() {}
  private:
   RegularException exc{};
 };
+}  // namespace GH115055
 
 RegularException funcReturningExceptionTest(int i) {
   return RegularException();

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Fix false positive in bugprone-throw-keyword-missing (PR #115302)

2024-11-09 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL approved this pull request.


https://github.com/llvm/llvm-project/pull/115302
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Fix false positive in bugprone-throw-keyword-missing (PR #115302)

2024-11-08 Thread Congcong Cai via cfe-commits


@@ -139,6 +139,14 @@ CtorInitializerListTest::CtorInitializerListTest(float) 
try : exc(RegularExcepti
   RegularException();
 }
 
+// https://github.com/llvm/llvm-project/issues/115055

HerrCai0907 wrote:

use a namspace GH (issue number)


https://github.com/llvm/llvm-project/pull/115302
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Fix false positive in bugprone-throw-keyword-missing (PR #115302)

2024-11-08 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 edited 
https://github.com/llvm/llvm-project/pull/115302
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Fix false positive in bugprone-throw-keyword-missing (PR #115302)

2024-11-08 Thread Congcong Cai via cfe-commits


@@ -139,6 +139,14 @@ CtorInitializerListTest::CtorInitializerListTest(float) 
try : exc(RegularExcepti
   RegularException();
 }
 
+// https://github.com/llvm/llvm-project/issues/115055
+class CtorInitializerListTest2 {
+ public:
+  CtorInitializerListTest2(){}

HerrCai0907 wrote:

```suggestion
  CtorInitializerListTest2() {}
```


https://github.com/llvm/llvm-project/pull/115302
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Fix false positive in bugprone-throw-keyword-missing (PR #115302)

2024-11-08 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 approved this pull request.

lgtm


https://github.com/llvm/llvm-project/pull/115302
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Fix false positive in bugprone-throw-keyword-missing (PR #115302)

2024-11-08 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti approved this pull request.

LGTM

---

I filed #115540 because I noticed how the `hasAncestor` matcher in the `unless` 
part means that we are excluding quite some cases. (unrelated to this PRI)

https://github.com/llvm/llvm-project/pull/115302
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Fix false positive in bugprone-throw-keyword-missing (PR #115302)

2024-11-07 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp created 
https://github.com/llvm/llvm-project/pull/115302

Fixes #115055

>From c6ad9d042612c63cb9862782f17082e07277fc2a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 6 Nov 2024 08:52:06 +
Subject: [PATCH] Fix false positive in bugprone-throw-keyword-missing

Fixes #115055
---
 .../clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp  | 5 +
 clang-tools-extra/docs/ReleaseNotes.rst   | 4 
 .../checkers/bugprone/throw-keyword-missing.cpp   | 8 
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
index 64c155c29cf8b9..17d2e75e4f666f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
@@ -15,9 +15,6 @@ using namespace clang::ast_matchers;
 namespace clang::tidy::bugprone {
 
 void ThrowKeywordMissingCheck::registerMatchers(MatchFinder *Finder) {
-  auto CtorInitializerList =
-  cxxConstructorDecl(hasAnyConstructorInitializer(anything()));
-
   Finder->addMatcher(
   cxxConstructExpr(
   hasType(cxxRecordDecl(
@@ -27,7 +24,7 @@ void ThrowKeywordMissingCheck::registerMatchers(MatchFinder 
*Finder) {
   stmt(anyOf(cxxThrowExpr(), callExpr(), returnStmt(,
   hasAncestor(decl(anyOf(varDecl(), fieldDecl(,
   hasAncestor(expr(cxxNewExpr(hasAnyPlacementArg(anything(),
-  allOf(hasAncestor(CtorInitializerList),
+  allOf(hasAncestor(cxxConstructorDecl()),
 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
index 51ba157ab05deb..e3294c12896357 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -177,6 +177,10 @@ Changes in existing checks
   usages of ``sizeof()``, ``alignof()``, and ``offsetof()`` when adding or
   subtracting from a pointer directly or when used to scale a numeric value.
 
+- Improved :doc:`bugprone-throw-keyword-missing
+  ` by fixing a false 
positive
+  when using non-static member initializers and a constructor.
+
 - Improved :doc:`bugprone-unchecked-optional-access
   ` to support
   `bsl::optional` and `bdlb::NullableValue` from
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 49233c0deefdf0..aa4bccb109f3f3 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
@@ -139,6 +139,14 @@ CtorInitializerListTest::CtorInitializerListTest(float) 
try : exc(RegularExcepti
   RegularException();
 }
 
+// https://github.com/llvm/llvm-project/issues/115055
+class CtorInitializerListTest2 {
+ public:
+  CtorInitializerListTest2(){}
+ private:
+  RegularException exc{};
+};
+
 RegularException funcReturningExceptionTest(int i) {
   return RegularException();
 }

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Fix false positive in bugprone-throw-keyword-missing (PR #115302)

2024-11-07 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-tidy

@llvm/pr-subscribers-clang-tools-extra

Author: Carlos Galvez (carlosgalvezp)


Changes

Fixes #115055

---
Full diff: https://github.com/llvm/llvm-project/pull/115302.diff


3 Files Affected:

- (modified) clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp 
(+1-4) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/throw-keyword-missing.cpp 
(+8) 


``diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
index 64c155c29cf8b9..17d2e75e4f666f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
@@ -15,9 +15,6 @@ using namespace clang::ast_matchers;
 namespace clang::tidy::bugprone {
 
 void ThrowKeywordMissingCheck::registerMatchers(MatchFinder *Finder) {
-  auto CtorInitializerList =
-  cxxConstructorDecl(hasAnyConstructorInitializer(anything()));
-
   Finder->addMatcher(
   cxxConstructExpr(
   hasType(cxxRecordDecl(
@@ -27,7 +24,7 @@ void ThrowKeywordMissingCheck::registerMatchers(MatchFinder 
*Finder) {
   stmt(anyOf(cxxThrowExpr(), callExpr(), returnStmt(,
   hasAncestor(decl(anyOf(varDecl(), fieldDecl(,
   hasAncestor(expr(cxxNewExpr(hasAnyPlacementArg(anything(),
-  allOf(hasAncestor(CtorInitializerList),
+  allOf(hasAncestor(cxxConstructorDecl()),
 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
index 51ba157ab05deb..e3294c12896357 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -177,6 +177,10 @@ Changes in existing checks
   usages of ``sizeof()``, ``alignof()``, and ``offsetof()`` when adding or
   subtracting from a pointer directly or when used to scale a numeric value.
 
+- Improved :doc:`bugprone-throw-keyword-missing
+  ` by fixing a false 
positive
+  when using non-static member initializers and a constructor.
+
 - Improved :doc:`bugprone-unchecked-optional-access
   ` to support
   `bsl::optional` and `bdlb::NullableValue` from
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 49233c0deefdf0..aa4bccb109f3f3 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
@@ -139,6 +139,14 @@ CtorInitializerListTest::CtorInitializerListTest(float) 
try : exc(RegularExcepti
   RegularException();
 }
 
+// https://github.com/llvm/llvm-project/issues/115055
+class CtorInitializerListTest2 {
+ public:
+  CtorInitializerListTest2(){}
+ private:
+  RegularException exc{};
+};
+
 RegularException funcReturningExceptionTest(int i) {
   return RegularException();
 }

``




https://github.com/llvm/llvm-project/pull/115302
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits