[clang-tools-extra] [clang-tidy] Fix FP on cppcoreguidelines-pro-type-member-init with forward decl (PR #190521)
Baranov Victor via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 5 05:19:08 PDT 2026
https://github.com/vbvictor created https://github.com/llvm/llvm-project/pull/190521
Fixes https://github.com/llvm/llvm-project/issues/155416.
>From 23618c8f154e60e33acbaa46e69fa92835d93d2e Mon Sep 17 00:00:00 2001
From: Victor Baranov <bar.victor.2002 at gmail.com>
Date: Sun, 5 Apr 2026 15:17:25 +0300
Subject: [PATCH] [clang-tidy] Fix FP on cppcoreguidelines-pro-type-member-init
with forward decl
---
.../ProTypeMemberInitCheck.cpp | 3 ++-
clang-tools-extra/docs/ReleaseNotes.rst | 5 ++++
.../pro-type-member-init.cpp | 24 +++++++++++++++++++
3 files changed, 31 insertions(+), 1 deletion(-)
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 69dc5b9633398..5ba16e1f71a10 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -283,6 +283,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