Skip to content

STL: Compiler intrinsics for BUILTIN-PTR-XXX #489

@CaseyCarter

Description

@CaseyCarter

The concept-constrained comparisons (std::ranges::equal_to, std::ranges::not_equal_to, std::ranges::less, std::ranges::greater, std::ranges::less_equal, std::ranges::greater_equal, std::compare_three_way) admit pairs of arguments that compare as pointers despite that they do not otherwise meet the constraints. Such arguments are recognized via the exposition-only magic macros BUILTIN-PTR-CMP ([range.cmp]/1) and BUILTIN-PTR-THREE-WAY
([comparisons.three.way]/1). These magic macros can be implemented as three compiler intrinsics:

  • __builtin_ptr_equal(T, U) which evaluates to true iff t == u for expressions t and u such that decltype((t)) is T and decltype((u)) is U resolves to a builtin == operator that compares pointers.

  • __builtin_ptr_less(T, U) which evaluates to true iff t < u for expressions t and u such that decltype((t)) is T and decltype((u)) is U resolves to a builtin < operator that compares pointers.

  • __builtin_ptr_spaceship(T, U) which evaluates to true iff t <=> u for expressions t and u such that decltype((t)) is T and decltype((u)) is U resolves to a builtin <=> operator that compares pointers.

If we cannot find a way to implement the equivalent of these intrinsics in C++ - there are library implementations, but to my knowledge none that properly handle types that convert to function pointers - we need to get these intrinsics implemented in our compiler front-ends, ideally with the same set of names. (I'm not married to the names above, but they seem as good as any.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    compilerCompiler work involvedresolvedSuccessfully resolved without a commitspaceshipC++20 operator <=>

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions