https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105233

            Bug ID: 105233
           Summary: Incorrect "alignment not an integer constant" error in
                    alignas with template parameter dependent argument
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Jonathan.Strobl at gmx dot de
  Target Milestone: ---

Dear GCC maintainers,

g++ rejects the following code, which I believe to be valid:

g++ -std=c++20 -x c++ - <<EOF
#include <bit>
template<typename T>
struct Data {
    T m_a;
    T m_b;
    T m_c;
};
template<typename T>
struct alignas(std::bit_ceil(sizeof(Data<T>))) AlignedData {
    Data<T> m_data;
};
AlignedData<int> g_test;
EOF
<stdin>: In instantiation of ‘struct AlignedData<int>’:
<stdin>:12:18:   required from here
<stdin>:9:48: error: requested alignment is not an integer constant

This bug is present since GCC 10; I have tested all versions up to 12.0 (trunk)
using Godbolt: https://godbolt.org/z/3eaGGrvWM

One strange thing that I noticed: This only occurs when a value that depends on
a template parameter passes through a standard library function. If the
argument passed to std::bit_ceil doesn't depend on a template parameter, the
code compiles fine. Similarly, when std::bit_ceil is replaced with a hand-made
version of the same function, it also compiles.

std::bit_ceil seems to somehow strip the value passed to it of its
"constant-ness", but only if that value depends on a template parameter.

Thank you for your support,
Jonathan

Reply via email to