diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc index d49e5a565e823aba7a23fcf746e037408379dbb3..3b8dc75d1986f9e7b708766a07051aa8b003a708 100644 --- a/gcc/cp/method.cc +++ b/gcc/cp/method.cc @@ -1228,7 +1228,11 @@ early_check_defaulted_comparison (tree fn) /* Defaulted outside the class body. */ ctx = TYPE_MAIN_VARIANT (parmtype); if (!is_friend (ctx, fn)) - error_at (loc, "defaulted %qD is not a friend of %qT", fn, ctx); + { + error_at (loc, "defaulted %qD is not a friend of %qT", fn, ctx); + inform (location_of (ctx), "declared here"); + ok = false; + } } else if (!same_type_ignoring_top_level_qualifiers_p (parmtype, ctx)) saw_bad = true; diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-eq17.C b/gcc/testsuite/g++.dg/cpp2a/spaceship-eq17.C new file mode 100644 index 0000000000000000000000000000000000000000..039bfac387c3cb71b81b33b6cab8b76791cff8b5 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-eq17.C @@ -0,0 +1,5 @@ +// PR c++/107291 +// { dg-do compile { target c++20 } } + +struct S4; // { dg-message "declared here" } +bool operator==(S4 const &, S4 const &) = default; // { dg-error "not a friend" }