Title
tuple-for-each can call user-defined operator,
Status
c++23
Section
[range.zip.view]
Submitter
Nicole Mazzuca

Created on 2022-08-26.00:00:00 last changed 5 months ago

Messages

Date: 2022-11-17.00:42:33

Proposed resolution:

This wording is relative to the forthcoming C++23 CD.

  • Modify [range.adaptor.tuple] as indicated:

    template<class F, class Tuple>
    constexpr auto tuple-for-each(F&& f, Tuple&& t) { // exposition only
      apply([&]<class... Ts>(Ts&&... elements) {
        (static_cast<void>(invoke(f, std::forward<Ts>(elements))), ...);
      }, std::forward<Tuple>(t));
    }
    
Date: 2022-11-12.00:00:00

[ 2022-11-12 Approved at November 2022 meeting in Kona. Status changed: Voting → WP. ]

Date: 2022-09-15.00:00:00

[ 2022-09-23; Reflector poll ]

Set status to Tentatively Ready after nine votes in favour during reflector poll.

Feedback from reviewers:

"NAD. This exposition-only facility is only used with things that return void. As far as I know, users can't define operator, for void." "If I see the void cast, I don't need to audit the uses or be concerned that we'll add a broken use in the future."

Date: 2022-08-26.00:00:00

The specification for tuple-for-each is:

template<class F, class Tuple>
constexpr auto tuple-for-each(F&& f, Tuple&& t) { // exposition only
  apply([&]<class... Ts>(Ts&&... elements) {
    (invoke(f, std::forward<Ts>(elements)), ...);
  }, std::forward<Tuple>(t));
}

Given

struct Evil {
  void operator,(Evil) {
        abort();
    }
};

and tuple<int, int> t, then tuple-for-each([](int) { return Evil{}; }, t), the program will (unintentionally) abort.

It seems likely that our Evil's operator, should not be called.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2022-11-17 00:42:33adminsetmessages: + msg13064
2022-11-17 00:42:33adminsetstatus: voting -> wp
2022-11-08 03:46:49adminsetstatus: ready -> voting
2022-09-23 14:50:50adminsetmessages: + msg12783
2022-09-23 14:50:50adminsetstatus: new -> ready
2022-08-26 20:00:23adminsetmessages: + msg12720
2022-08-26 00:00:00admincreate