Commit a6479aa4 by Marek Polacek

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.
parent 542f7353
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> 2020-04-08 Tobias Burnus <tobias@codesourcery.com>
PR middle-end/94120 PR middle-end/94120
......
...@@ -1102,6 +1102,17 @@ early_check_defaulted_comparison (tree fn) ...@@ -1102,6 +1102,17 @@ early_check_defaulted_comparison (tree fn)
return false; 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) if (!DECL_OVERLOADED_OPERATOR_IS (fn, SPACESHIP_EXPR)
&& !same_type_p (TREE_TYPE (TREE_TYPE (fn)), boolean_type_node)) && !same_type_p (TREE_TYPE (TREE_TYPE (fn)), boolean_type_node))
{ {
......
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> 2020-04-08 Alexandre Oliva <oliva@adacore.com>
* gcc.target/arm/polytypes.c: Add quotes around * gcc.target/arm/polytypes.c: Add quotes around
......
// 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" }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment