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:
Marek Polacek 2020-04-07 14:24:52 -04:00
parent 542f73539d
commit a6479aa4c0
4 changed files with 29 additions and 0 deletions

View File

@ -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

View File

@ -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))
{

View File

@ -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

View 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" }