Merge pull request #272 from boostorg/nodiscard

Add support for [[nodiscard]]
This commit is contained in:
jzmaddock
2019-04-02 13:24:34 +01:00
committed by GitHub
3 changed files with 16 additions and 0 deletions

View File

@ -1275,6 +1275,8 @@ Usage example:
]]
[[`BOOST_ATTRIBUTE_UNUSED`][Expands to `__attribute__((unused))` when this is available -
can be used to disable compiler warnings relating to unused types or variables.]]
[[`BOOST_ATTRIBUTE_NODISCARD`][Expands to `[[nodiscard]]` when this is available -
can be used to create a warning when a type or variable is unused.]]
[[`BOOST_MAY_ALIAS`, `BOOST_NO_MAY_ALIAS`][
`BOOST_MAY_ALIAS` expands to a type attribute that can be used to mark types that may
alias other types. Pointers or references to such marked types can be used to access objects

View File

@ -992,6 +992,17 @@ namespace std{ using ::type_info; }
#ifndef BOOST_ATTRIBUTE_UNUSED
# define BOOST_ATTRIBUTE_UNUSED
#endif
//
// [[nodiscard]]:
//
#ifdef __has_cpp_attribute
#if __has_cpp_attribute(nodiscard)
# define BOOST_ATTRIBUTE_NODISCARD [[nodiscard]]
#endif
#endif
#ifndef BOOST_ATTRIBUTE_NODISCARD
# define BOOST_ATTRIBUTE_NODISCARD
#endif
#define BOOST_STATIC_CONSTEXPR static BOOST_CONSTEXPR_OR_CONST

View File

@ -37,6 +37,8 @@ BOOST_NORETURN void always_throw()
struct BOOST_MAY_ALIAS aliasing_struct {};
typedef unsigned int BOOST_MAY_ALIAS aliasing_uint;
struct BOOST_ATTRIBUTE_NODISCARD nodiscard_struct {};
#define test_fallthrough(x) foobar(x)
@ -53,6 +55,7 @@ int main()
result += never_inline(3);
if(BOOST_UNLIKELY(!result))
always_throw();
nodiscard_struct s;
}
catch(int)
{