Fixed: https://github.com/llvm/llvm-project/issues/62791
Fixed: https://github.com/llvm/llvm-project/issues/62102
in c++20, default comparison is supported. getLexicalDeclContext maybe cannot
get the CXXRecord if default comparison defined out of CXXRecord.
This patch want to get these information from the first function argument.
Details
- Reviewers
hazohelet shafik erichkeane aaron.ballman rsmith hans - Group Reviewers
Restricted Project - Commits
- rG5df593a35471: [Sema] cast to CXXRecordDecl correctly when diag a default comparison method
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
As Richard says, we should just be taking the first parameter type and using that instead (obviously de-qualified and removing reference if necessary).
clang/lib/Sema/SemaTemplateInstantiate.cpp | ||
---|---|---|
970 | According to the comment on the related bug: This code predates P2085R0, prior to which a comparison function could only be defaulted lexically within the class. Given that we can't use the lexically-enclosing class any more, we can instead look at the (first) parameter type to determine which class's comparison is being defaulted. ... since the lexical context isn't the right thing for us to be looking at any more ... |
That ends up being an absurdly larger amount of work, and in the case of a 'friend' declaration can result in the wrong answer, correct? Consider something like:
struct Foo; struct Bar { friend bool operator==(const Foo&, const Foo&); }; struct Foo { friend bool operator==(const Foo&, const Foo&); }; bool operator==(const Foo&, const Foo&) = default;
or even:
struct Foo { bool operator==(const Foo&) const; }; struct Bar { friend bool Foo::operator==(const Foo&) const; }; bool operator==(Foo, Foo) = default;
In the 1st one, the lexical context could be 'Bar'. Searching 'redecls' will end up with the 'first one first', so at least the 2nd example isn't as problematic, but I'm sure someone more clever than I could come up with a case where that could be declared in a different order.
clang/lib/Sema/SemaTemplateInstantiate.cpp | ||
---|---|---|
970 | What is going on here? You already have the RecordType in the RecordType variable. You don't need to go to RecordDecl and back? You should just be able to put the RecordType variable directly. |
clang/lib/Sema/SemaTemplateInstantiate.cpp | ||
---|---|---|
970 | I am not very familiar with QualType's conversion. Do you think it is the correct path to remove all qualifier and get the full name for class? |
clang/lib/Sema/SemaTemplateInstantiate.cpp | ||
---|---|---|
968 | This doesn't seem right to me? I think you just want the unqualified, non-reference type here. I suspect you don't really want to do Desugaring at all, since then you lose the typedef information (so something like std::string will be confusing). So I think you just want: .getNonReferenceType().getUnqualifiedType(). |
This doesn't seem right to me? I think you just want the unqualified, non-reference type here. I suspect you don't really want to do Desugaring at all, since then you lose the typedef information (so something like std::string will be confusing).
So I think you just want: .getNonReferenceType().getUnqualifiedType().