public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105233] New: Incorrect "alignment not an integer constant" error in alignas with template parameter dependent argument
@ 2022-04-11 22:19 Jonathan.Strobl at gmx dot de
  2022-04-12 12:03 ` [Bug c++/105233] " jakub at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Jonathan.Strobl at gmx dot de @ 2022-04-11 22:19 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-04-13 15:51 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-11 22:19 [Bug c++/105233] New: Incorrect "alignment not an integer constant" error in alignas with template parameter dependent argument Jonathan.Strobl at gmx dot de
2022-04-12 12:03 ` [Bug c++/105233] " jakub at gcc dot gnu.org
2022-04-12 12:19 ` jakub at gcc dot gnu.org
2022-04-12 12:34 ` jakub at gcc dot gnu.org
2022-04-12 13:09 ` jakub at gcc dot gnu.org
2022-04-12 13:50 ` jakub at gcc dot gnu.org
2022-04-12 13:59 ` ppalka at gcc dot gnu.org
2022-04-13 13:44 ` cvs-commit at gcc dot gnu.org
2022-04-13 13:46 ` jakub at gcc dot gnu.org
2022-04-13 15:46 ` Jonathan.Strobl at gmx dot de
2022-04-13 15:51 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).