[clang-tools-extra] [clang-tidy] Fix crash in `cppcoreguidelines-pro-type-member-init` with alias template in constructor initializer (PR #192786)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 18 04:22:18 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tidy
@llvm/pr-subscribers-clang-tools-extra
Author: flovent
<details>
<summary>Changes</summary>
Closes #<!-- -->192510.
---
Full diff: https://github.com/llvm/llvm-project/pull/192786.diff
3 Files Affected:
- (modified) clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp (+7-3)
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+6-3)
- (modified) clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init-no-crash.cpp (+19)
``````````diff
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
index 07d71968a07b8..74cd62cd869f8 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -571,9 +571,13 @@ void ProTypeMemberInitCheck::checkMissingBaseClassInitializer(
return;
for (const CXXCtorInitializer *Init : Ctor->inits())
- if (Init->isBaseInitializer() && Init->isWritten())
- BasesToInit.erase(
- Init->getBaseClass()->getAsCXXRecordDecl()->getCanonicalDecl());
+ if (Init->isBaseInitializer() && Init->isWritten()) {
+ // In template AST BaseInitializer could be generated too even if it's
+ // not target to base class.
+ if (const CXXRecordDecl *CRD =
+ Init->getBaseClass()->getAsCXXRecordDecl())
+ BasesToInit.erase(CRD->getCanonicalDecl());
+ }
}
if (BasesToInit.empty())
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 95ed0061d654c..980939c6ae0a3 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -344,9 +344,12 @@ Changes in existing checks
lambda captures such as ``[t{std::forward<T>(t)}]``.
- 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.
+ <clang-tidy/checks/cppcoreguidelines/pro-type-member-init>` check:
+
+ - Fixed a false positive when a base class has a forward declaration before
+ its definition.
+
+ - Fixed a crash with alias template in constructor initializer.
- Improved :doc:`cppcoreguidelines-pro-type-vararg
<clang-tidy/checks/cppcoreguidelines/pro-type-vararg>` check by no longer
diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init-no-crash.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init-no-crash.cpp
index 2e2964dda1daf..c454874503eac 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init-no-crash.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init-no-crash.cpp
@@ -13,3 +13,22 @@ template <typename T> class NoCrash {
template <typename U> B(U u) {}
};
};
+
+namespace gh192510 {
+ template<typename T>
+ struct C {
+
+ };
+
+ struct Base {
+ int x;
+ };
+
+ template<typename T>
+ class X: public Base {
+ using INT = C<T>;
+
+ X(INT i) : INT(i) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: constructor does not initialize these bases: Base
+ };
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/192786
More information about the cfe-commits
mailing list