https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122609
--- Comment #2 from Nathaniel Shead <nshead at gcc dot gnu.org> ---
Verified this is also confusing for cases like `auto operator<=>`; even if we
`import std` or `#include <compare>` at the declaration, if we try to use that
type in an importer we get confusing errors (including suggestions to add
`#include <compare>` to the module that already has it).
$ cat e.cpp
export module M;
import std;
export struct S {
std::strong_ordering operator<=>(const S&) const = default;
int x;
};
$ cat f.cpp
import M;
int main() {
S{} < S{};
}
$ g++ -fmodules -S -std=c++20 e.cpp f.cpp
f.cpp: In function ‘int main()’:
f.cpp:4:11: error: use of deleted function ‘constexpr std::strong_ordering
S@M::operator<=>(const S@M&) const’
4 | S{} < S{};
| ^
In module M, imported at f.cpp:1:
e.cpp:5:24: note: ‘constexpr std::strong_ordering S@M::operator<=>(const S@M&)
const’ is implicitly deleted because the default definition would be
ill-formed:
5 | std::strong_ordering operator<=>(const S&) const = default;
| ^~~~~~~~
e.cpp:5:24: error: ‘strong_ordering’ is not a member of ‘std’
e.cpp:2:1: note: ‘std::strong_ordering’ is defined in header ‘<compare>’; this
is probably fixable by adding ‘#include <compare>’
1 | export module M;
+++ |+#include <compare>
2 | import std;
e.cpp:5:24: note: forming type of ‘operator<=>’
5 | std::strong_ordering operator<=>(const S&) const = default;
| ^~~~~~~~
e.cpp:5:24: note: determining value of ‘operator<=>’
In this case however the standard explicitly requires this to be ill-formed,
https://eel.is/c++draft/expr.spaceship#8 says
> if a standard library declaration ([compare.syn], [std.modules]) of
> such a class type does not precede ([basic.lookup.general]) a use of that type