-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[Clang][Sema] properly remove qualifiers in __is_pointer_interconvertible_base_of #167881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be better to put these tests in "clang/test/SemaCXX/type-traits.cpp". |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // RUN: %clangxx %s -o %t | ||
| // RUN: %t | FileCheck %s | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't use execution tests. You can test this with |
||
|
|
||
| #include <iostream> | ||
|
|
||
| class A {}; | ||
| class B : public A {}; | ||
|
|
||
| template <class _Base, class _Derived> | ||
| inline constexpr bool is_pointer_interconvertible_base_of_v = __is_pointer_interconvertible_base_of(_Base, _Derived); | ||
|
|
||
| int main() { | ||
| // CHECK: 1 | ||
| std::cout << __is_pointer_interconvertible_base_of(const A, A) << std::endl; | ||
| // CHECK-NEXT: 1 | ||
| std::cout << is_pointer_interconvertible_base_of_v<const A, A> << std::endl; | ||
|
|
||
| // CHECK-NEXT: 1 | ||
| std::cout << __is_pointer_interconvertible_base_of(const A, B) << std::endl; | ||
| // CHECK-NEXT: 1 | ||
| std::cout << is_pointer_interconvertible_base_of_v<const A, B> << std::endl; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you better explain why this is the right answer here? And why loss of canonicalization didn't affect anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I misread the def of
getUnqualifiedType()at first, now I'm not sure this is the correct solution. I thought it did canonicalise, but actually it desugars, which I don't know the intention behind but it seems to do near enough the same thing as canonicalisation that the tests passed.Is
getCanonicalTypeUnqualified()supposed to behave as it does? It returns the canonical type directly without explicitly stripping quals, but in the case ofSubstTemplateTypeParmTypethe canonical type can have quals (and there are tests that rely on this).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little surprised
getCanonicalTypeUnqualifiedactually resulted in qualifiers. Qualifiers are stored in theQualType, which gets stripped off by the operator->.Canonical Unqualifiedshould be exactly the unqualified type after canonicalization, so I'm a little shocked you're not seeing it work.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, instead of this change, the following also passes the tests:
It's surprising to me that we never ran into this before, but maybe this patch is more reasonable/correct.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hrmph... I would expect the canonical type to be without qualifiers, so that extra
getUnqualifiedTypeshouldn't be necessary. SOMEHOW we're failing to correctly canonicalize when creating the type? SeeisCanonicalUnqualified.EDIT: NOPE, that actually isn't right, the
isCanonicalUnqualifiedis asking a different question :) I THINK your proposed change there is perhaps right, I'd like to have another set or three of eyes on it.@AaronBallman @cor3ntin @mizvekov ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, if canonical types can have qualifiers, why is
Athe canonical type ofconst A?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not certain why template type parameter substitution types can have canonical types with qualifiers. Maybe @erichkeane @mizvekov @zygoloid or someone else knows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, we need references at least (since thats how reference folding needs to work/move semantics/etc). So I would presume that cv qualifiers would be the same way. So we'd need to maintain those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
getCanonicalTypeUnqualifiedis, but it looks very strange. If it's supposed to be returning an unqualified type, why isn't it removing the qualifiers and returning aconst 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:
getCanonicalTypeUnqualified().getUnqualifiedType()-- actually discard the qualifiers and produce an unqualifiedQualTypeorCanQualTypegetCanonicalTypeUnqualified()->somethingorgetCanonicalTypeUnqualified().getTypePtr()-- actually discard the qualifiers and produce aconst Type*:) 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
getUnqualifiedTyperather than removing type sugar, and we could make them do so?)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, if we're going to be poking at those calls, we also should be checking whether they should be using
getAtomicUnqualifiedType()thanks to_Atomicin C being such a weird beast; we've had numerous bugs where we accidentally fail to strip atomic qualifiers and that causes further issues.