Update nodiscard attribute:

It's not supported on functions pre-c++11 even if __has_cpp_attribute indicates it is supported.
Also update test case.
Fixes https://github.com/boostorg/config/issues/336.
This commit is contained in:
jzmaddock
2021-08-19 18:17:56 +01:00
parent fac8ba93cc
commit 1635999736
2 changed files with 6 additions and 1 deletions

View File

@ -1050,7 +1050,7 @@ namespace std{ using ::type_info; }
#endif
#elif defined(__has_cpp_attribute)
// clang-6 accepts [[nodiscard]] with -std=c++14, but warns about it -pedantic
#if __has_cpp_attribute(nodiscard) && !(defined(__clang__) && (__cplusplus < 201703L))
#if __has_cpp_attribute(nodiscard) && !(defined(__clang__) && (__cplusplus < 201703L)) && !(defined(__GNUC__) && (__cplusplus < 201100))
# define BOOST_ATTRIBUTE_NODISCARD [[nodiscard]]
#endif
#if __has_cpp_attribute(no_unique_address) && !(defined(__GNUC__) && (__cplusplus < 201100))

View File

@ -41,6 +41,11 @@ typedef unsigned int BOOST_MAY_ALIAS aliasing_uint;
struct BOOST_ATTRIBUTE_NODISCARD nodiscard_struct {};
BOOST_ATTRIBUTE_NODISCARD int nodiscard_proc(int i)
{
return i * i;
}
#define test_fallthrough(x) foobar(x)