gcc/libstdc++-v3/include/std
Jason Merrill b7689b962d Implement C++20 operator<=>.
There are three major pieces to this support: scalar operator<=>,
synthesis of comparison operators, and rewritten/reversed overload
resolution (e.g. a < b becomes 0 > b <=> a).

Unlike other defaulted functions, where we use synthesized_method_walk to
semi-simulate what the definition of the function will be like, this patch
determines the characteristics of a comparison operator by trying to define
it.

My handling of non-dependent rewritten operators in templates can still use
some work: build_min_non_dep_op_overload can't understand the rewrites and
crashes, so I'm avoiding it for now by clearing *overload.  This means we'll
do name lookup again at instantiation time, which can incorrectly mean a
different result.  I'll poke at this more in stage 3.

I'm leaving out a fourth section ("strong structural equality") even though
I've implemented it, because it seems likely to change radically tomorrow.

Thanks to Tim van Deurzen and Jakub for implementing lexing of the <=>
operator, and Jonathan for the initial <compare> header.

gcc/cp/
	* cp-tree.h (struct lang_decl_fn): Add maybe_deleted bitfield.
	(DECL_MAYBE_DELETED): New.
	(enum special_function_kind): Add sfk_comparison.
	(LOOKUP_REWRITTEN, LOOKUP_REVERSED): New.
	* call.c (struct z_candidate): Add rewritten and reversed methods.
	(add_builtin_candidate): Handle SPACESHIP_EXPR.
	(add_builtin_candidates): Likewise.
	(add_candidates): Don't add a reversed candidate if the parms are
	the same.
	(add_operator_candidates): Split out from build_new_op_1.  Handle
	rewritten and reversed candidates.
	(add_candidate): Swap conversions of reversed candidate.
	(build_new_op_1): Swap them back.  Build a second operation for
	rewritten candidates.
	(extract_call_expr): Handle rewritten calls.
	(same_fn_or_template): New.
	(joust): Handle rewritten and reversed candidates.
	* class.c (add_implicitly_declared_members): Add implicit op==.
	(classtype_has_op, classtype_has_defaulted_op): New.
	* constexpr.c (cxx_eval_binary_expression): Handle SPACESHIP_EXPR.
	(cxx_eval_constant_expression, potential_constant_expression_1):
	Likewise.
	* cp-gimplify.c (genericize_spaceship): New.
	(cp_genericize_r): Use it.
	* cp-objcp-common.c (cp_common_init_ts): Handle SPACESHIP_EXPR.
	* decl.c (finish_function): Handle deleted function.
	* decl2.c (grokfield): SET_DECL_FRIEND_CONTEXT on defaulted friend.
	(mark_used): Check DECL_MAYBE_DELETED.  Remove assumption that
	defaulted functions are non-static members.
	* error.c (dump_expr): Handle SPACESHIP_EXPR.
	* method.c (type_has_trivial_fn): False for sfk_comparison.
	(enum comp_cat_tag, struct comp_cat_info_t): New types.
	(comp_cat_cache): New array variable.
	(lookup_comparison_result, lookup_comparison_category)
	(is_cat, cat_tag_for, spaceship_comp_cat)
	(spaceship_type, genericize_spaceship)
	(common_comparison_type, early_check_defaulted_comparison)
	(comp_info, build_comparison_op): New.
	(synthesize_method): Handle sfk_comparison.  Handle deleted.
	(get_defaulted_eh_spec, maybe_explain_implicit_delete)
	(explain_implicit_non_constexpr, implicitly_declare_fn)
	(defaulted_late_check, defaultable_fn_check): Handle sfk_comparison.
	* name-lookup.c (get_std_name_hint): Add comparison categories.
	* tree.c (special_function_p): Add sfk_comparison.
	* typeck.c (cp_build_binary_op): Handle SPACESHIP_EXPR.

2019-11-05  Tim van Deurzen  <tim@kompiler.org>

	Add new tree code for the spaceship operator.
gcc/cp/
	* cp-tree.def: Add new tree code.
	* operators.def: New binary operator.
	* parser.c: Add new token and tree code.
libcpp/
	* cpplib.h: Add spaceship operator for C++.
	* lex.c: Implement conditional lexing of spaceship operator for C++20.

2019-11-05  Jonathan Wakely  <jwakely@redhat.com>

libstdc++-v3/
	* libsupc++/compare: New header.
	* libsupc++/Makefile.am (std_HEADERS): Add compare.
	* include/std/version: Define __cpp_lib_three_way_comparison.
	* include/std/functional: #include <compare>.

From-SVN: r277865
2019-11-05 18:56:18 -05:00
..
algorithm
any
array Remove include directives for deleted Profile Mode headers 2019-09-26 17:08:24 +01:00
atomic
bit Fix some missing/incorrect feature test macros 2019-10-30 16:57:13 +00:00
bitset Remove include directives for deleted Profile Mode headers 2019-09-26 17:08:24 +01:00
charconv LWG 3266. to_chars(bool) should be deleted 2019-09-10 10:08:20 +01:00
chrono
codecvt
complex
concepts Use if-constexpr instead of overloading for customization point 2019-10-30 17:42:04 +00:00
condition_variable PR libstdc++/41861 Add full steady_clock support to condition_variable 2019-09-04 23:43:29 +01:00
deque Remove include directives for deleted Profile Mode headers 2019-09-26 17:08:24 +01:00
execution
filesystem
forward_list Remove include directives for deleted Profile Mode headers 2019-09-26 17:08:24 +01:00
fstream
functional Implement C++20 operator<=>. 2019-11-05 18:56:18 -05:00
future
iomanip
ios
iosfwd
iostream
istream
iterator
limits
list Remove include directives for deleted Profile Mode headers 2019-09-26 17:08:24 +01:00
locale
map Remove include directives for deleted Profile Mode headers 2019-09-26 17:08:24 +01:00
memory Remove redundant std::allocator members for C++20 2019-10-22 22:48:39 +01:00
memory_resource
mutex
numbers
numeric Add C++11 __iterator_category_t template alias. 2019-10-06 15:10:40 +00:00
optional
ostream
queue
random
ranges Partial implementation of C++20 of <ranges> header 2019-10-31 21:42:18 +00:00
ratio
regex
scoped_allocator
set Remove include directives for deleted Profile Mode headers 2019-09-26 17:08:24 +01:00
shared_mutex
span Implement LWG 3255 for std::span constructors 2019-09-30 12:52:08 +01:00
sstream
stack
stdexcept
streambuf
string
string_view Implement C++20 p1424 - 'constexpr' feature macro concerns... 2019-09-10 03:38:58 +00:00
system_error
thread
tuple Implement C++20 constexpr changes to std::pair (P1032R1) 2019-09-26 17:08:39 +01:00
type_traits Only use GCC-specific __is_same_as built-in conditionally 2019-10-16 11:26:05 +01:00
typeindex
unordered_map Remove include directives for deleted Profile Mode headers 2019-09-26 17:08:24 +01:00
unordered_set Remove include directives for deleted Profile Mode headers 2019-09-26 17:08:24 +01:00
utility Implement C++20 p1424 - 'constexpr' feature macro concerns... 2019-09-10 03:38:58 +00:00
valarray
variant Remove check for impossible condition in std::variant::index() 2019-09-24 15:17:08 +01:00
vector Remove include directives for deleted Profile Mode headers 2019-09-26 17:08:24 +01:00
version Implement C++20 operator<=>. 2019-11-05 18:56:18 -05:00