diff options
author | Marek Polacek <polacek@redhat.com> | 2020-04-07 14:24:52 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2020-04-08 08:56:07 -0400 |
commit | a6479aa4c0532ee9ad1f098b4e82de9dc684e036 (patch) | |
tree | 27a48b54e66d8f29800f434fa5a11010af19cb79 /gcc/cp/method.c | |
parent | 542f73539db1433303a4dd16bd2cfc5e7e12eda8 (diff) | |
download | gcc-a6479aa4c0532ee9ad1f098b4e82de9dc684e036.zip gcc-a6479aa4c0532ee9ad1f098b4e82de9dc684e036.tar.gz gcc-a6479aa4c0532ee9ad1f098b4e82de9dc684e036.tar.bz2 |
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.
Diffstat (limited to 'gcc/cp/method.c')
-rw-r--r-- | gcc/cp/method.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/gcc/cp/method.c b/gcc/cp/method.c index 41b9ff8..9a21bfc 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -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)) { |