diff --git a/doc/macro_reference.qbk b/doc/macro_reference.qbk index f39bb704..79692e03 100644 --- a/doc/macro_reference.qbk +++ b/doc/macro_reference.qbk @@ -1277,6 +1277,8 @@ Usage example: 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_ATTRIBUTE_NO_UNIQUE_ADDRESS`][Expands to `[[no_unique_address]]` when this is available - +can be used to indicate that a non-static data member need not have a unique address (for example empty classes).]] [[`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 diff --git a/include/boost/config/detail/suffix.hpp b/include/boost/config/detail/suffix.hpp index 465d5e47..2550239c 100644 --- a/include/boost/config/detail/suffix.hpp +++ b/include/boost/config/detail/suffix.hpp @@ -999,10 +999,16 @@ namespace std{ using ::type_info; } #if __has_cpp_attribute(nodiscard) # define BOOST_ATTRIBUTE_NODISCARD [[nodiscard]] #endif +#if __has_cpp_attribute(no_unique_address) +# define BOOST_ATTRIBUTE_NO_UNIQUE_ADDRESS [[no_unique_address]] +#endif #endif #ifndef BOOST_ATTRIBUTE_NODISCARD # define BOOST_ATTRIBUTE_NODISCARD #endif +#ifndef BOOST_ATTRIBUTE_NO_UNIQUE_ADDRESS +# define BOOST_ATTRIBUTE_NO_UNIQUE_ADDRESS +#endif #define BOOST_STATIC_CONSTEXPR static BOOST_CONSTEXPR_OR_CONST diff --git a/test/helper_macro_test.cpp b/test/helper_macro_test.cpp index 3a3b4f01..ffa8060a 100644 --- a/test/helper_macro_test.cpp +++ b/test/helper_macro_test.cpp @@ -42,6 +42,13 @@ struct BOOST_ATTRIBUTE_NODISCARD nodiscard_struct {}; #define test_fallthrough(x) foobar(x) +struct empty {}; +struct no_unique +{ + int a; + BOOST_ATTRIBUTE_NO_UNIQUE_ADDRESS empty b; +}; + int main() { @@ -56,6 +63,7 @@ int main() if(BOOST_UNLIKELY(!result)) always_throw(); nodiscard_struct s; + no_unique no_un; } catch(int) {