#Issue with nodiscard

11 messages · Page 1 of 1 (latest)

primal sequoiaBOT
#

When your question is answered use !solved or the button below to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

hardy maple
#

;compile clang_trunk -Werror

#include <utility>
template <typename T> [[nodiscard("")]] auto move_nodiscard(T &&movee) {
  return std::move(movee);
}



int main()
{
    #define DD(expr) ({move_nodiscard(expr))}                                                       

  DD(1)               // doesnt work
  DD("hi")            // doesnt work
  return 0;}```
hot coveBOT
#
Compiler Output
<source>:12:3: error: expected ';' after expression
   12 |   DD(1)               // doesnt work
      |   ^
<source>:10:44: note: expanded from macro 'DD'
   10 |     #define DD(expr) ({move_nodiscard(expr))}                                                       
      |                                            ^
<source>:12:3: error: ignoring return value of function declared with 'nodiscard' attribute [-Werror,-Wunused-result]
   12 |   DD(1)               // doesnt work
      |   ^~~~~
<source>:10:24: note: expanded from macro 'DD'
   10 |     #define DD(expr) ({move_nodiscard(expr))}                                                       
      |                        ^~~~~~~~~~~~~~~~~~~~
<source>:12:3: error: expected expression
<source>:10:44: note: expanded from macro 'DD'
   10 |     #define DD(expr) ({move_nodiscard(expr))}                                                       
      |                                            ^
<source>:14:3: error: expected unqualifie
hardy maple
#

it does work

#

wym

#

clang trunk works

#

gcc msvc and clang do completely different things xD

#

i mean its a GCC extension

#

apparently

primal sequoiaBOT
#

This question is being automatically marked as stale.
If your question has been answered, type !solved.
If your question is not answered feel free to bump the post or re-ask.
Take a look at !howto ask for tips on improving your question.