[clang] [Clang][Sema] properly remove qualifiers in __is_pointer_interconvertible_base_of (PR #167881)
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 17 11:18:57 PST 2025
================
@@ -15607,8 +15607,8 @@ bool Sema::IsLayoutCompatible(QualType T1, QualType T2) const {
bool Sema::IsPointerInterconvertibleBaseOf(const TypeSourceInfo *Base,
const TypeSourceInfo *Derived) {
- QualType BaseT = Base->getType()->getCanonicalTypeUnqualified();
- QualType DerivedT = Derived->getType()->getCanonicalTypeUnqualified();
+ QualType BaseT = Base->getType().getUnqualifiedType();
+ QualType DerivedT = Derived->getType().getUnqualifiedType();
----------------
zygoloid wrote:
A canonical type being qualified isn't surprising to me -- that happens frequently (eg, the canonical type of a typedef can be qualified).
I'm not sure what the intent of `getCanonicalTypeUnqualified` is, but it looks very strange. If it's supposed to be returning an unqualified type, why isn't it removing the qualifiers and returning a `const Type*`? Maybe the intent is to provide "get canonical type and I don't care about whether you preserve all, some, or none of the qualifiers", but the name really doesn't convey that.
Looking through the calls, it seems most fall into one of three categories:
1) `getCanonicalTypeUnqualified().getUnqualifiedType()` -- actually discard the qualifiers and produce an unqualified `QualType` or `CanQualType`
2) `getCanonicalTypeUnqualified()->something` or `getCanonicalTypeUnqualified().getTypePtr()` -- actually discard the qualifiers and produce a `const Type*`
3) Calls that look suspicious and are probably wrong
:) It'd probably be good to remove this hazard, make the function actually return an unqualified type, and check all the callers to make sure none of them really cares about the qualifiers (one would hope they don't!).
(But in passing, maybe some or most of the callers should just be using `getUnqualifiedType` rather than removing type sugar, and we could make them do so?)
https://github.com/llvm/llvm-project/pull/167881
More information about the cfe-commits
mailing list