mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-03-21 17:30:54 +08:00
c++: ICE with defaulted comparison operator [PR94478]
Here we ICE because early_check_defaulted_comparison passed a null ctx to same_type_p. The attached test is ill-formed according to [class.compare.default]/1, so fixed by detecting this case early. PR c++/94478 - ICE with defaulted comparison operator * method.c (early_check_defaulted_comparison): Give an error when the context is null. * g++.dg/cpp2a/spaceship-err4.C: New test.
This commit is contained in:
parent
542f73539d
commit
a6479aa4c0
@ -1,3 +1,9 @@
|
||||
2020-04-08 Marek Polacek <polacek@redhat.com>
|
||||
|
||||
PR c++/94478 - ICE with defaulted comparison operator
|
||||
* method.c (early_check_defaulted_comparison): Give an error when the
|
||||
context is null.
|
||||
|
||||
2020-04-08 Tobias Burnus <tobias@codesourcery.com>
|
||||
|
||||
PR middle-end/94120
|
||||
|
@ -1102,6 +1102,17 @@ early_check_defaulted_comparison (tree fn)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ctx)
|
||||
{
|
||||
if (DECL_OVERLOADED_OPERATOR_IS (fn, SPACESHIP_EXPR))
|
||||
error_at (loc, "three-way comparison operator can only be defaulted "
|
||||
"in a class definition");
|
||||
else
|
||||
error_at (loc, "equality comparison operator can only be defaulted "
|
||||
"in a class definition");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!DECL_OVERLOADED_OPERATOR_IS (fn, SPACESHIP_EXPR)
|
||||
&& !same_type_p (TREE_TYPE (TREE_TYPE (fn)), boolean_type_node))
|
||||
{
|
||||
|
@ -1,3 +1,8 @@
|
||||
2020-04-08 Marek Polacek <polacek@redhat.com>
|
||||
|
||||
PR c++/94478 - ICE with defaulted comparison operator
|
||||
* g++.dg/cpp2a/spaceship-err4.C: New test.
|
||||
|
||||
2020-04-08 Alexandre Oliva <oliva@adacore.com>
|
||||
|
||||
* gcc.target/arm/polytypes.c: Add quotes around
|
||||
|
7
gcc/testsuite/g++.dg/cpp2a/spaceship-err4.C
Normal file
7
gcc/testsuite/g++.dg/cpp2a/spaceship-err4.C
Normal file
@ -0,0 +1,7 @@
|
||||
// PR c++/94478 - ICE with defaulted comparison operator.
|
||||
// { dg-do compile { target c++2a } }
|
||||
|
||||
struct B {};
|
||||
bool operator!=(const B&, const B&) = default; // { dg-error "equality comparison operator can only be defaulted in a class definition" }
|
||||
bool operator==(const B&, const B&) = default; // { dg-error "equality comparison operator can only be defaulted in a class definition" }
|
||||
bool operator<=>(const B&, const B&) = default; // { dg-error "three-way comparison operator can only be defaulted in a class definition" }
|
Loading…
x
Reference in New Issue
Block a user