[clang-tools-extra] 90b1416 - [clang-tidy] Fix crash in `cppcoreguidelines-pro-type-member-init` with alias template in constructor initializer (#192786)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 18 07:24:14 PDT 2026
Author: flovent
Date: 2026-04-18T22:24:08+08:00
New Revision: 90b1416c3136244433d9f3917fe3029145687618
URL: https://github.com/llvm/llvm-project/commit/90b1416c3136244433d9f3917fe3029145687618
DIFF: https://github.com/llvm/llvm-project/commit/90b1416c3136244433d9f3917fe3029145687618.diff
LOG: [clang-tidy] Fix crash in `cppcoreguidelines-pro-type-member-init` with alias template in constructor initializer (#192786)
Closes #192510.
Added:
Modified:
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
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 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/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 7468ce04434b0..55963eae2c1b5 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
@@ -635,3 +635,22 @@ namespace PR155416 {
Ct() : St{0} {}
};
}
+
+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) {} // no crash
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: constructor does not initialize these bases: Base
+ };
+}
More information about the cfe-commits
mailing list