[Bug c++/105233] Incorrect "alignment not an integer constant" error in alignas with template parameter dependent argument
jakub at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Apr 12 13:09:54 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105233
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at gcc dot gnu.org,
| |ppalka at gcc dot gnu.org
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Even
template <typename T>
constexpr T
foo (T x) noexcept
{
bool a = __builtin_is_constant_evaluated ();
return 4 * __alignof (int);
}
template <typename T>
struct A { T a, b, c; };
template <typename T>
struct alignas (foo (sizeof (A<T>))) B { A<T> d; };
B<int> e;
I see that the foo (sizeof (A<T>) expression is constexpr evaluated once
without manifestly_const_eval and with allow_non_constant set, so because of
the __builtin_is_constant_evaluated () fails in that case, as it isn't a
manifestly constant evaluation but manifestly constant evaluation could appear
later.
It isn't evaluated with it later though.
alignas argument is a constant expression (or type id), so at some point it
should be evaluated with manifestly_const_eval set.
Under the hood, we transform alignas into the gnu::aligned attribute, so the
question is, shall we treat as manifestly constant expression just alignas
argument, or gnu::aligned attribute's argument as well, or some other
attribute's arguments too? And where exactly we'd evaluate those arguments?
Seems the C++ FE has cp_check_const_attributes for this, but there it just
calls:
if (EXPR_P (expr))
TREE_VALUE (arg) = fold_non_dependent_expr (expr);
which is non-manifestly constant evaluated and doesn't guarantee it will be a
constant expression (we then just error if it is not later on).
More information about the Gcc-bugs
mailing list