diff --git a/doc/macro_reference.qbk b/doc/macro_reference.qbk index a0d51e89..8f024ba7 100644 --- a/doc/macro_reference.qbk +++ b/doc/macro_reference.qbk @@ -1262,6 +1262,18 @@ 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_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 +of other types. If the compiler supports this feature `BOOST_NO_MAY_ALIAS` is not defined. +Otherwise `BOOST_MAY_ALIAS` expands to nothing and `BOOST_NO_MAY_ALIAS` is defined. + +Usage example: +`` + struct BOOST_MAY_ALIAS aliasing_struct; + typedef unsigned int BOOST_MAY_ALIAS aliasing_uint; +`` +]] ] [endsect] diff --git a/include/boost/config/compiler/clang.hpp b/include/boost/config/compiler/clang.hpp index 157a94d2..0fdf331f 100644 --- a/include/boost/config/compiler/clang.hpp +++ b/include/boost/config/compiler/clang.hpp @@ -318,6 +318,11 @@ // Clang has supported the 'unused' attribute since the first release. #define BOOST_ATTRIBUTE_UNUSED __attribute__((__unused__)) +// Type aliasing hint. +#if __has_attribute(__may_alias__) +# define BOOST_MAY_ALIAS __attribute__((__may_alias__)) +#endif + #ifndef BOOST_COMPILER # define BOOST_COMPILER "Clang version " __clang_version__ #endif diff --git a/include/boost/config/compiler/gcc.hpp b/include/boost/config/compiler/gcc.hpp index d1cfed7a..12958ab9 100644 --- a/include/boost/config/compiler/gcc.hpp +++ b/include/boost/config/compiler/gcc.hpp @@ -315,6 +315,10 @@ #if __GNUC__ >= 4 # define BOOST_ATTRIBUTE_UNUSED __attribute__((__unused__)) #endif + +// Type aliasing hint. Supported since gcc 3.3. +#define BOOST_MAY_ALIAS __attribute__((__may_alias__)) + // // __builtin_unreachable: #if BOOST_GCC_VERSION >= 40800 diff --git a/include/boost/config/compiler/intel.hpp b/include/boost/config/compiler/intel.hpp index f55189a0..f549dcb6 100644 --- a/include/boost/config/compiler/intel.hpp +++ b/include/boost/config/compiler/intel.hpp @@ -311,6 +311,12 @@ template<> struct assert_intrinsic_wchar_t {}; # define BOOST_SYMBOL_IMPORT # define BOOST_SYMBOL_VISIBLE __attribute__((visibility("default"))) #endif + +// Type aliasing hint +#if defined(__GNUC__) && (BOOST_INTEL_CXX_VERSION >= 1300) +# define BOOST_MAY_ALIAS __attribute__((__may_alias__)) +#endif + // // C++0x features // For each feature we need to check both the Intel compiler version, diff --git a/include/boost/config/compiler/vacpp.hpp b/include/boost/config/compiler/vacpp.hpp index 683c167d..c8400a34 100644 --- a/include/boost/config/compiler/vacpp.hpp +++ b/include/boost/config/compiler/vacpp.hpp @@ -65,6 +65,11 @@ #define BOOST_NO_PARTIAL_SPECIALIZATION_IMPLICIT_DEFAULT_ARGS #endif +// Type aliasing hint. Supported since XL C++ 13.1 +#if (__IBMCPP__ >= 1310) +# define BOOST_MAY_ALIAS __attribute__((__may_alias__)) +#endif + // // C++0x features // diff --git a/include/boost/config/compiler/xlcpp.hpp b/include/boost/config/compiler/xlcpp.hpp index b267f49b..a4c66e40 100644 --- a/include/boost/config/compiler/xlcpp.hpp +++ b/include/boost/config/compiler/xlcpp.hpp @@ -267,6 +267,11 @@ # define BOOST_ATTRIBUTE_UNUSED __attribute__((unused)) #endif +// Type aliasing hint. +#if __has_attribute(__may_alias__) +# define BOOST_MAY_ALIAS __attribute__((__may_alias__)) +#endif + #ifndef BOOST_COMPILER # define BOOST_COMPILER "Clang version " __clang_version__ #endif diff --git a/include/boost/config/compiler/xlcpp_zos.hpp b/include/boost/config/compiler/xlcpp_zos.hpp index c554903a..bc785b8a 100644 --- a/include/boost/config/compiler/xlcpp_zos.hpp +++ b/include/boost/config/compiler/xlcpp_zos.hpp @@ -159,6 +159,7 @@ #if defined(__IBM_ATTRIBUTES) # define BOOST_FORCEINLINE inline __attribute__ ((__always_inline__)) # define BOOST_NOINLINE __attribute__ ((__noinline__)) +# define BOOST_MAY_ALIAS __attribute__((__may_alias__)) // No BOOST_ALIGNMENT - explicit alignment support is broken (V2R1). #endif diff --git a/include/boost/config/detail/suffix.hpp b/include/boost/config/detail/suffix.hpp index 6abec22f..caa0b229 100644 --- a/include/boost/config/detail/suffix.hpp +++ b/include/boost/config/detail/suffix.hpp @@ -602,6 +602,14 @@ namespace std{ using ::type_info; } # endif #endif +// BOOST_MAY_ALIAS -----------------------------------------------// +// The macro expands to an attribute to mark a type that is allowed to alias other types. +// The macro is defined in the compiler-specific headers. +#if !defined(BOOST_MAY_ALIAS) +# define BOOST_NO_MAY_ALIAS +# define BOOST_MAY_ALIAS +#endif + // BOOST_FORCEINLINE ---------------------------------------------// // Macro to use in place of 'inline' to force a function to be inline #if !defined(BOOST_FORCEINLINE) diff --git a/test/config_info.cpp b/test/config_info.cpp index a7863f42..2a2a110d 100644 --- a/test/config_info.cpp +++ b/test/config_info.cpp @@ -1152,6 +1152,8 @@ void print_boost_macros() PRINT_MACRO(BOOST_FORCEINLINE); PRINT_MACRO(BOOST_NOINLINE); PRINT_MACRO(BOOST_FALLTHROUGH); + PRINT_MACRO(BOOST_MAY_ALIAS); + PRINT_MACRO(BOOST_NO_MAY_ALIAS); } void print_separator() diff --git a/test/helper_macro_test.cpp b/test/helper_macro_test.cpp index 81737fec..e3b11128 100644 --- a/test/helper_macro_test.cpp +++ b/test/helper_macro_test.cpp @@ -34,6 +34,9 @@ BOOST_NORETURN void always_throw() throw 0; } +struct BOOST_MAY_ALIAS aliasing_struct {}; +typedef unsigned int BOOST_MAY_ALIAS aliasing_uint; + #define test_fallthrough(x) foobar(x)