[clang] [Clang] Fix crash on malformed std::partial_ordering static members (PR #172001)
Oliver Hunt via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 12 23:18:17 PST 2025
================
@@ -83,7 +83,14 @@ ComparisonCategoryInfo::ValueInfo *ComparisonCategoryInfo::lookupValueInfo(
&Ctx.Idents.get(ComparisonCategories::getResultString(ValueKind)));
if (Lookup.empty() || !isa<VarDecl>(Lookup.front()))
return nullptr;
- Objects.emplace_back(ValueKind, cast<VarDecl>(Lookup.front()));
+ // The static member must have the same type as the comparison category class
+ // itself (e.g., std::partial_ordering::less must be of type partial_ordering).
+ VarDecl *ValueDecl = cast<VarDecl>(Lookup.front());
+ const CXXRecordDecl *ValueDeclRecord = ValueDecl->getType()->getAsCXXRecordDecl();
+ if (!ValueDeclRecord || ValueDeclRecord->getCanonicalDecl() != Record->getCanonicalDecl())
----------------
ojhunt wrote:
Nit: this line is too long, it's weird the style bot didn't complain - running clang-format over this should fix that.
https://github.com/llvm/llvm-project/pull/172001
More information about the cfe-commits
mailing list