Skip to content

Commit

Permalink
?cxx/Macros: +macrosNoUniqueAddressTest():
Browse files Browse the repository at this point in the history
	tests `SUSUWU_NO_UNIQUE_ADDRESS`.
	?`SUSUWU_NO_UNIQUE_ADDRESS`: documentation has logic fixes.

Is followup to 796d4fe (?`cxx/Macros.hxx`: +`SUSUWU_NO_UNIQUE_ADDRESS`:).
Is small step to issue #14 .
  • Loading branch information
SwuduSusuwu committed Nov 9, 2024
1 parent 796d4fe commit bdfb817
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cxx/Macros.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,17 @@ namespace Susuwu { /* namespaces do not affect macros. Is just standard practice
#endif /* if (defined(__cplusplus) && 201702 < __cplusplus) */
#if (defined(__cplusplus) && 202002 <= __cplusplus)
# define SUSUWU_CXX20
# define SUSUWU_NO_UNIQUE_ADDRESS [[no_unique_address]] /* use this attribute for members which have no size, suchas `class {SUSUWU_NO_UNIQUE_ADDRESS Zero zero;};` (if `std::is_empty<Zero>`). */
# define SUSUWU_NO_UNIQUE_ADDRESS [[no_unique_address]] /* use this attribute on member subojects if `std::is_empty<MemberClass>::value == true`, if you want those to not pad (most compilers pad such that `1 == sizeof(zero)` in the test. */
void macrosNoUniqueAddressTest() {
typedef class Zero {} Zero;
class SubClassWithBaseSubobject : public Zero {bool boo;};
class SubClassWithMemberSubobject {bool boo; public: Zero zero;};
class SubClassWithMemberSubobjectNoAddress {bool boo; public: SUSUWU_NO_UNIQUE_ADDRESS Zero zero;};
SUSUWU_STATIC_ASSERT(std::is_empty<Zero>::value);
SUSUWU_STATIC_ASSERT(sizeof(bool) == sizeof(SubClassWithBaseSubobject));
SUSUWU_STATIC_ASSERT(sizeof(bool) < sizeof(SubClassWithMemberSubobject));
SUSUWU_STATIC_ASSERT(sizeof(bool) == sizeof(SubClassWithMemberSubobjectNoAddress));
}
#else /* (defined(__cplusplus) && 202002 <= __cplusplus) else */
# define SUSUWU_NO_UNIQUE_ADDRESS /* No-op */
#endif /* if (defined(__cplusplus) && 202002 <= __cplusplus) */
Expand Down

0 comments on commit bdfb817

Please sign in to comment.