MySQL 8.0.39
Source Code Documentation
nodiscard.h File Reference

Go to the source code of this file.

Macros

#define NODISCARD   nodiscard
 The function attribute [[NODISCARD]] is a replacement for [[nodiscard]] to workaround a gcc bug. More...
 

Macro Definition Documentation

◆ NODISCARD

#define NODISCARD   nodiscard

The function attribute [[NODISCARD]] is a replacement for [[nodiscard]] to workaround a gcc bug.

This attribute can appear before a function declaration, and makes it mandatory for the caller to use the return value. Use this on functions where it is always essential to check if an error occurred.

It would be better if we could use [[nodiscard]], but gcc has a bug that makes it ineffective is some cases: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84476 OTOH, gnu::warn_unused_result is unaffected by the bug. Once the bug is fixed, and we drop support for compiler versions that have the bug, we can replace [[NODISCARD]] by [[nodiscard]].

MSVC gives a warning for gnu::warn_unused_result because it does not recognize it, so we use gnu::warn_unused_result only on gnuc.