From 8aca5ebe07efd6d710c76eff2d3524f6c5c4ff2b Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Sat, 21 Dec 2019 00:18:09 +0100 Subject: re PR c++/92973 (Silently accepting defaulted comparison operators in C++11 .. 17) PR c++/92973 * method.c (early_check_defaulted_comparison): For C++17 and earlier diagnose defaulted comparison operators. * g++.dg/cpp0x/spaceship-eq1.C: New test. From-SVN: r279682 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/method.c | 7 +++++++ gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/cpp0x/spaceship-eq1.C | 5 +++++ 4 files changed, 19 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/spaceship-eq1.C (limited to 'gcc') diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5a9a648..07200ad 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2019-12-20 Jakub Jelinek + PR c++/92973 + * method.c (early_check_defaulted_comparison): For C++17 and earlier + diagnose defaulted comparison operators. + PR c++/92666 * call.c (convert_arg_to_ellipsis): For floating point or decltype(nullptr) arguments call mark_rvalue_use. diff --git a/gcc/cp/method.c b/gcc/cp/method.c index 97c27c5..248a0e5 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -1092,6 +1092,13 @@ early_check_defaulted_comparison (tree fn) ctx = DECL_FRIEND_CONTEXT (fn); bool ok = true; + if (cxx_dialect < cxx2a) + { + error_at (loc, "defaulted %qD only available with %<-std=c++2a%> or " + "%<-std=gnu++2a%>", fn); + return false; + } + if (!DECL_OVERLOADED_OPERATOR_IS (fn, SPACESHIP_EXPR) && !same_type_p (TREE_TYPE (TREE_TYPE (fn)), boolean_type_node)) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index dd9e529..40568bb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2019-12-20 Jakub Jelinek + PR c++/92973 + * g++.dg/cpp0x/spaceship-eq1.C: New test. + PR c++/92666 * g++.dg/warn/Wunused-var-36.C: New test. diff --git a/gcc/testsuite/g++.dg/cpp0x/spaceship-eq1.C b/gcc/testsuite/g++.dg/cpp0x/spaceship-eq1.C new file mode 100644 index 0000000..2e0ad0c --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/spaceship-eq1.C @@ -0,0 +1,5 @@ +// PR c++/92973 +// { dg-do compile { target c++11 } } + +struct S { bool operator==(const S&) const = default; int s; }; // { dg-error "only available with" "" { target c++17_down } } +struct T { bool operator!=(const T&) const = default; int t; }; // { dg-error "only available with" "" { target c++17_down } } -- cgit v1.1