llvm-project/clang/test/SemaCXX/cxx20-default-compare.cpp
Congcong Cai 5df593a354 [Sema] cast to CXXRecordDecl correctly when diag a default comparison method
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.

Reviewed By: #clang-language-wg, erichkeane

Differential Revision: https://reviews.llvm.org/D151365
2023-05-25 22:07:50 +02:00

18 lines
1.1 KiB
C++

// 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}}