Add BOOST_ATTRIBUTE_NO_UNIQUE_ADDRESS.

See https://github.com/boostorg/config/issues/257.
This commit is contained in:
jzmaddock
2019-04-02 18:40:25 +01:00
parent fb746fc6fb
commit 6ef16c8d90
3 changed files with 16 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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)
{