NVIDIA / stdexec

`std::execution`, the proposed C++ framework for asynchronous and parallel programming.
Apache License 2.0
1.56k stars 159 forks source link

nodiscard warning on nvc++ #786

Closed maikel closed 1 year ago

maikel commented 1 year ago

On nvc++ I get the following warning

"/stdexec/test/exec/test_any_sender.cpp", line 285: warning: ignoring return value type with "nodiscard" attribute [nodiscard_return_type]
    sender = just(21) | then([&](int v) {
           ^

Remark: individual warnings can be suppressed with "--diag_suppress <warning-name>"

"/stdexec/test/exec/test_any_sender.cpp", line 306: warning: ignoring return value type with "nodiscard" attribute [nodiscard_return_type]
    sndr = just(42);
         ^

"/stdexec/test/exec/test_any_sender.cpp", line 315: warning: ignoring return value type with "nodiscard" attribute [nodiscard_return_type]
    sndr = when_any(just(42));
         ^

This is due to the nodiscard attribute that i added as class [[nodiscard]] any_sender. And I consider that a bug in nvc++. Code looks like this

  my_sender_of<int> sender = just(21) | then([&](int v) { return 2 * v; });
  auto [value] = *sync_wait(std::move(sender));
  CHECK(value == 42);
  sender = just(21) | then([&](int v) {
             throw 420;
             return 2 * v;
           });

i.e. we reassign a moved-from sender. Is there a STDEXEC_NODISCARD macro that handles nvc++ as a special case?

ericniebler commented 1 year ago

Is there a STDEXEC_NODISCARD macro that handles nvc++ as a special case?

Not yet. You're free to add one. I don't see a particularly strong case for marking any_sender_of [[nodiscard]] though. In this case, I would simply strike the attribute.