This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG5df593a35471: [Sema] cast to CXXRecordDecl correctly when diag a default comparison method (authored by HerrCai0907).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D151365/new/ https://reviews.llvm.org/D151365 Files: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaTemplateInstantiate.cpp clang/test/CXX/class/class.compare/class.spaceship/p1.cpp clang/test/SemaCXX/cxx20-default-compare.cpp Index: clang/test/SemaCXX/cxx20-default-compare.cpp =================================================================== --- /dev/null +++ clang/test/SemaCXX/cxx20-default-compare.cpp @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 %s -std=c++23 -verify -Wfloat-equal + +struct Foo { + float val; + bool operator==(const Foo &) const; + friend bool operator==(const Foo &, const Foo &); + friend bool operator==(Foo, Foo ); +}; + +// Declare the defaulted comparison function as a member function. +bool Foo::operator==(const Foo &) const = default; // expected-warning {{comparing floating point with == or != is unsafe}} expected-note {{in defaulted equality comparison operator for 'Foo' first required here}} + +// Declare the defaulted comparison function as a non-member function. +bool operator==(const Foo &, const Foo &) = default; // expected-warning {{comparing floating point with == or != is unsafe}} expected-note {{in defaulted equality comparison operator for 'Foo' first required here}} + +// Declare the defaulted comparison function as a non-member function. Arguments are passed by value. +bool operator==(Foo, Foo) = default; // expected-warning {{comparing floating point with == or != is unsafe}} expected-note {{in defaulted equality comparison operator for 'Foo' first required here}} Index: clang/test/CXX/class/class.compare/class.spaceship/p1.cpp =================================================================== --- clang/test/CXX/class/class.compare/class.spaceship/p1.cpp +++ clang/test/CXX/class/class.compare/class.spaceship/p1.cpp @@ -227,5 +227,5 @@ A a; std::strong_ordering operator<=>(const B&) const = default; // expected-error {{call to deleted constructor of 'A'}} }; - bool x = B() < B(); // expected-note {{in defaulted three-way comparison operator for 'Preference::B' first required here}} + bool x = B() < B(); // expected-note {{in defaulted three-way comparison operator for 'B' first required here}} } Index: clang/lib/Sema/SemaTemplateInstantiate.cpp =================================================================== --- clang/lib/Sema/SemaTemplateInstantiate.cpp +++ clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -961,11 +961,13 @@ << MD->isExplicitlyDefaulted() << DFK.asSpecialMember() << Context.getTagDeclType(MD->getParent()); } else if (DFK.isComparison()) { + QualType RecordType = FD->getParamDecl(0) + ->getType() + .getNonReferenceType() + .getUnqualifiedType(); Diags.Report(Active->PointOfInstantiation, diag::note_comparison_synthesized_at) - << (int)DFK.asComparison() - << Context.getTagDeclType( - cast<CXXRecordDecl>(FD->getLexicalDeclContext())); + << (int)DFK.asComparison() << RecordType; } break; } Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -445,6 +445,9 @@ (`#62789 <https://github.com/llvm/llvm-project/issues/62789>`_). - Fix a crash when instantiating a non-type template argument in a dependent scope. (`#62533 <https://github.com/llvm/llvm-project/issues/62533>`_). +- Fix crash when diagnosing default comparison method. + (`#62791 <https://github.com/llvm/llvm-project/issues/62791>`_) and + (`#62102 <https://github.com/llvm/llvm-project/issues/62102>`_). Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Index: clang/test/SemaCXX/cxx20-default-compare.cpp =================================================================== --- /dev/null +++ clang/test/SemaCXX/cxx20-default-compare.cpp @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 %s -std=c++23 -verify -Wfloat-equal + +struct Foo { + float val; + bool operator==(const Foo &) const; + friend bool operator==(const Foo &, const Foo &); + friend bool operator==(Foo, Foo ); +}; + +// Declare the defaulted comparison function as a member function. +bool Foo::operator==(const Foo &) const = default; // expected-warning {{comparing floating point with == or != is unsafe}} expected-note {{in defaulted equality comparison operator for 'Foo' first required here}} + +// Declare the defaulted comparison function as a non-member function. +bool operator==(const Foo &, const Foo &) = default; // expected-warning {{comparing floating point with == or != is unsafe}} expected-note {{in defaulted equality comparison operator for 'Foo' first required here}} + +// Declare the defaulted comparison function as a non-member function. Arguments are passed by value. +bool operator==(Foo, Foo) = default; // expected-warning {{comparing floating point with == or != is unsafe}} expected-note {{in defaulted equality comparison operator for 'Foo' first required here}} Index: clang/test/CXX/class/class.compare/class.spaceship/p1.cpp =================================================================== --- clang/test/CXX/class/class.compare/class.spaceship/p1.cpp +++ clang/test/CXX/class/class.compare/class.spaceship/p1.cpp @@ -227,5 +227,5 @@ A a; std::strong_ordering operator<=>(const B&) const = default; // expected-error {{call to deleted constructor of 'A'}} }; - bool x = B() < B(); // expected-note {{in defaulted three-way comparison operator for 'Preference::B' first required here}} + bool x = B() < B(); // expected-note {{in defaulted three-way comparison operator for 'B' first required here}} } Index: clang/lib/Sema/SemaTemplateInstantiate.cpp =================================================================== --- clang/lib/Sema/SemaTemplateInstantiate.cpp +++ clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -961,11 +961,13 @@ << MD->isExplicitlyDefaulted() << DFK.asSpecialMember() << Context.getTagDeclType(MD->getParent()); } else if (DFK.isComparison()) { + QualType RecordType = FD->getParamDecl(0) + ->getType() + .getNonReferenceType() + .getUnqualifiedType(); Diags.Report(Active->PointOfInstantiation, diag::note_comparison_synthesized_at) - << (int)DFK.asComparison() - << Context.getTagDeclType( - cast<CXXRecordDecl>(FD->getLexicalDeclContext())); + << (int)DFK.asComparison() << RecordType; } break; } Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -445,6 +445,9 @@ (`#62789 <https://github.com/llvm/llvm-project/issues/62789>`_). - Fix a crash when instantiating a non-type template argument in a dependent scope. (`#62533 <https://github.com/llvm/llvm-project/issues/62533>`_). +- Fix crash when diagnosing default comparison method. + (`#62791 <https://github.com/llvm/llvm-project/issues/62791>`_) and + (`#62102 <https://github.com/llvm/llvm-project/issues/62102>`_). Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits