https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105251
Bug ID: 105251 Summary: static assert sizeof(decltype(_together)) <= hardware_constructive_interference_size fails with gcc12 Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: raj.khem at gmail dot com Target Milestone: --- This testcase below fails to compile with gcc12 on aarch64 but works ok with gcc11 gcc12 ===== $ aarch64-yoe-linux-musl-g++ --sysroot=/mnt/b/yoe/master/build/tmp/work/cortexa72-yoe-linux-musl/mongodb/4.4.13-r0/recipe-sysroot a.cpp -std=c++17 a.cpp:35:47: error: static assertion failed: cache line spill 35 | static_assert(sizeof(decltype(_together)) <= hardware_constructive_interference_size, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cpp:35:47: note: the comparison reduces to '(256 <= 64)' ===== a.cpp ===== #include <cstdint> #include <cstddef> #include <new> #include <algorithm> #ifdef __cpp_lib_hardware_interference_size using std::hardware_constructive_interference_size; using std::hardware_destructive_interference_size; #else // 64 bytes on x86-64 │ L1_CACHE_BYTES │ L1_CACHE_SHIFT │ __cacheline_aligned │ ... constexpr std::size_t hardware_constructive_interference_size = 64; constexpr std::size_t hardware_destructive_interference_size = 64; #endif class NetworkCounter { private: template <typename T, size_t alignment> struct alignas(alignment) WithAlignment : T { using T::T; }; template <typename T, size_t alignment> using WithAlignmentAtLeast = WithAlignment<T, std::max(alignof(T), alignment)>; // These two counters are always incremented at the same time, so // we place them on the same cache line. template <typename T> using CacheAligned = WithAlignmentAtLeast<T, hardware_destructive_interference_size>; struct Together { long long logicalBytesIn{0}; long long requests{0}; }; CacheAligned<Together> _together{}; static_assert(sizeof(decltype(_together)) <= hardware_constructive_interference_size, "cache line spill"); };