From 1635999736b419d3517f9095f6573d52b19c9462 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Thu, 19 Aug 2021 18:17:56 +0100 Subject: [PATCH] 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. --- include/boost/config/detail/suffix.hpp | 2 +- test/helper_macro_test.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/boost/config/detail/suffix.hpp b/include/boost/config/detail/suffix.hpp index bdc96af4..6ca044b5 100644 --- a/include/boost/config/detail/suffix.hpp +++ b/include/boost/config/detail/suffix.hpp @@ -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)) diff --git a/test/helper_macro_test.cpp b/test/helper_macro_test.cpp index 18b9268a..79549ca3 100644 --- a/test/helper_macro_test.cpp +++ b/test/helper_macro_test.cpp @@ -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)