Title
Diagnose misuse of `std::projected::operator*`
Status
new
Section
[projected]
Submitter
Jiang An

Created on 2025-05-30.00:00:00 last changed 3 weeks ago

Messages

Date: 2025-06-05.15:52:42

Proposed resolution:

This wording is relative to N5008.

  1. Modify [projected] as indicated:

    namespace std {
      template<class I, class Proj>
      struct projected-impl { // exposition only
        struct type { // exposition only
          […]
          // models weakly_incrementable
          indirect_result_t<Proj&, I> operator*() const; // not defined
        };
      };
      […]
    }
    
    indirect_result_t<Proj&, I> operator*() const;
    

    -?- Mandates: This function is not odr-used ([basic.def.odr]).

Date: 2025-05-30.00:00:00

`std::projected::operator*` is only intentionally used for type calculation like `std::declval`. Currently, if one attempts to call it in a potentially evaluated expression, the program is ill-formed, no diagnostic required because the `operator*` is not defined.

It seems better to diagnose such misuse, as we are already diagnosing misuse of `std::declval` ([declval]/2). Implementation used to perform such misuse via `std::ranges::iter_move`, but libc++ and libstdc++ have already switched not to do this (see microsoft/STL#5555).

History
Date User Action Args
2025-06-05 15:52:42adminsetmessages: + msg14775
2025-05-30 00:00:00admincreate