I need the semantics of the [[nodiscard]]
attribute in a non-C++17 codebase. I guess there are compiler dependent ways of achieving this before C++17. Does anyone know these? I am interested in the ones for clang,gcc, and MSVC.
Asked
Active
Viewed 2,423 times
13

Alex Guteniev
- 12,039
- 2
- 34
- 79

gexicide
- 38,535
- 21
- 92
- 152
-
1What semantics? All nodiscard does is say "hey, if this return value is discarded you should probably issue a warning". – Cubic Jul 19 '17 at 12:39
-
@Cubic: Exactly this! – gexicide Jul 19 '17 at 12:39
-
A good place to look would be the compiler documentation. – Galik Jul 19 '17 at 12:41
-
GCC can use `__attribute__((warn_unused_result))`. – 0x5453 Jul 19 '17 at 12:42
-
[strongly related](https://stackoverflow.com/q/2042780/1708801) – Shafik Yaghmour Jul 22 '18 at 15:50
1 Answers
15
- GCC/Clang:
__attribute__((warn_unused_result))
- MSVC:
_Check_return_
for_MSC_VER >= 1700
(Visual Studio 2012)

Nikolai Shalakin
- 1,349
- 2
- 13
- 25