[clang-tools-extra] e326ff2 - [clang-tidy] Fix FP on cppcoreguidelines-pro-type-member-init with forward decl (#190521)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 5 22:42:30 PDT 2026
Author: Baranov Victor
Date: 2026-04-06T08:42:24+03:00
New Revision: e326ff2a88d5ca4037c6c1b7be05e406f5408026
URL: https://github.com/llvm/llvm-project/commit/e326ff2a88d5ca4037c6c1b7be05e406f5408026
DIFF: https://github.com/llvm/llvm-project/commit/e326ff2a88d5ca4037c6c1b7be05e406f5408026.diff
LOG: [clang-tidy] Fix FP on cppcoreguidelines-pro-type-member-init with forward decl (#190521)
Fixes https://github.com/llvm/llvm-project/issues/155416.
Added:
Modified:
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
index a259d03724d24..07d71968a07b8 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -572,7 +572,8 @@ void ProTypeMemberInitCheck::checkMissingBaseClassInitializer(
for (const CXXCtorInitializer *Init : Ctor->inits())
if (Init->isBaseInitializer() && Init->isWritten())
- BasesToInit.erase(Init->getBaseClass()->getAsCXXRecordDecl());
+ BasesToInit.erase(
+ Init->getBaseClass()->getAsCXXRecordDecl()->getCanonicalDecl());
}
if (BasesToInit.empty())
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index ad2ee2ae4b35e..02315415b975f 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -291,6 +291,11 @@ Changes in existing checks
<clang-tidy/checks/cppcoreguidelines/missing-std-forward>` check by fixing
a false positive for constrained template parameters.
+- Improved :doc:`cppcoreguidelines-pro-type-member-init
+ <clang-tidy/checks/cppcoreguidelines/pro-type-member-init>` check by fixing
+ a false positive when a base class has a forward declaration before its
+ definition.
+
- Improved :doc:`cppcoreguidelines-pro-type-vararg
<clang-tidy/checks/cppcoreguidelines/pro-type-vararg>` check by no longer
warning on builtins with custom type checking (e.g., type-generic builtins
diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp
index 890d1d262066b..7468ce04434b0 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp
@@ -611,3 +611,27 @@ namespace PR37250 {
const V v;
const S s{v};
}
+
+namespace PR155416 {
+ struct S;
+
+ struct S {
+ int a;
+ };
+
+ struct C : S {
+ C() : S{0} {}
+ };
+
+ template<typename T>
+ struct St;
+
+ template<typename T>
+ struct St{
+ T a;
+ };
+
+ struct Ct : St<int> {
+ Ct() : St{0} {}
+ };
+}
More information about the cfe-commits
mailing list