From fa3bbab91429e073c6c80494cd1d5d6c1bfdc282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kr=C3=BCgler?= Date: Sun, 4 Feb 2024 12:27:52 +0100 Subject: [PATCH] New issue from Corentin: "A less hacky and more useful way to compare comparison category types" --- xml/issue4051.xml | 89 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 xml/issue4051.xml diff --git a/xml/issue4051.xml b/xml/issue4051.xml new file mode 100644 index 0000000000..9505744fa4 --- /dev/null +++ b/xml/issue4051.xml @@ -0,0 +1,89 @@ + + + + +A less hacky and more useful way to compare comparison category types +
+Corentin Jabot +31 Jan 2024 +99 + + +

+Comparison categories can only be compared to the literal 0. +It does not make sense for them to be comparable to anything else, so conceptually, the design of + makes sense, however in practice it's a pain point from users and implementations +alike, as the desired semantics is barely implementable. +

+
    +
  • One implementation strategy is to use nullptr_t. This produces warnings in implementations +because using a 0 pointer constant is not recommended, and filtering out these warnings would be unreliable.

  • +
  • Another implementation strategy is to require a consteval expression but

    +
      +
    • This permits 1-1, which ought to be totally fine and yet it exposes users to UB

    • +
    • It is not SFINAE friendly (and attempts at SFINAE are presumably UB).

    • +
    +
  • +
+

+And there are use cases where SFINAE friendliness is important, notably testing frameworks. +

+The status quo has engendered multiple issues being reported to at least 3 vendors +

+Suggestion: +

+
    +
  • Allow any 0 constant expression

  • +
  • Require compile magic to SFINAE on non zero values

  • +
  • Remove the gratuitous UB

  • +
+

+The proposed wording requires compiler magic and has been +implemented in clang. +(Other possible way to implement that would for example be a magic type attribute, or a magic type) +

+Related vendor issues: +

+GCC Bugzilla issue 96278 +

+GCC Bugzilla issue 100903 +

+LLVM issue 43670 +

+LLVM pulls request 79465 +

+Microsoft STL issue 4359 +

+Microsoft STL pull request 3581 +

+Visual Studio issue 10509214 +

+snitch issue 140 +

+
+ + +

+This wording is relative to . +

+ +
    +
  1. Modify as indicated:

    + +
    +

    +-3- The relational and equality operators for the comparison category types are specified with an anonymous +parameter of unspecified type. This type shall be selected by the implementation such that these parameters +can only accept an integral constant expression evaluating toliteral 0 +as a corresponding argument. +

    +[Example 1: nullptr_t meets this requirement. — end example] +

    +In this context, the behavior of a program that supplies an argument other than a literal 0 is undefined. +

    +
    +
  2. +
+
+ +