diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -439,6 +439,9 @@ (`#62789 `_). - Fix a crash when instantiating a non-type template argument in a dependent scope. (`#62533 `_). +- Fix crash when diagnosing default comparison method. + (`#62791 `_) and + (`#62102 `_). Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp b/clang/lib/Basic/Targets/WebAssembly.cpp --- a/clang/lib/Basic/Targets/WebAssembly.cpp +++ b/clang/lib/Basic/Targets/WebAssembly.cpp @@ -163,6 +163,7 @@ bool WebAssemblyTargetInfo::handleTargetFeatures( std::vector &Features, DiagnosticsEngine &Diags) { for (const auto &Feature : Features) { + llvm::errs() << Feature << "\n"; if (Feature == "+simd128") { SIMDLevel = std::max(SIMDLevel, SIMD128); continue; diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -961,11 +961,14 @@ << MD->isExplicitlyDefaulted() << DFK.asSpecialMember() << Context.getTagDeclType(MD->getParent()); } else if (DFK.isComparison()) { + QualType RecordType = + FD->getParamDecl(0) + ->getType() + .getNonReferenceType() + ->getLocallyUnqualifiedSingleStepDesugaredType(); Diags.Report(Active->PointOfInstantiation, diag::note_comparison_synthesized_at) - << (int)DFK.asComparison() - << Context.getTagDeclType( - cast(FD->getLexicalDeclContext())); + << (int)DFK.asComparison() << RecordType; } break; } diff --git a/clang/test/SemaCXX/cxx20-default-compare.cpp b/clang/test/SemaCXX/cxx20-default-compare.cpp new file mode 100644 --- /dev/null +++ b/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}}