Using constants from the base class of the template

The following code fragment does not compile under g ++ 5.3.1, but compiles under clang 3.7.0. Which compiler is right?

[hidden] cat c.cpp
template <typename T>
struct Base {
  constexpr static int Align_ = alignof(T);
};

template <typename T>
struct Derived : Base<T> {
  using Base_ = Base<T>;
  using Base_::Align_;
  alignas(Align_) char buf[1];
};

Compile output:

[hidden] clang++ -c -std=c++14 c.cpp
[hidden] g++ -c -std=c++14 c.cpp
c.cpp:10:29: error: requested alignment is not an integer constant
   alignas(Align_) char buf[1];
                             ^
[hidden]
[hidden] g++ -v
Using built-in specs.
COLLECT_GCC=/usr/bin/g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/5.3.1/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --disable-libgcj --with-isl --enable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 5.3.1 20151207 (Red Hat 5.3.1-2) (GCC)
[hidden]
[hidden] clang++ -v
clang version 3.7.0 (http://llvm.org/git/clang.git 2ddd3734f32e39e793550b282d44fd71736f8d21)
Target: x86_64-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/3.4.6
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/5.3.1
Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/5.3.1
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
+2
source share
1 answer

It looks like a bug in GCC because it should work by standard. From the standard draft n4567

If the alignment specifier is of the form alignas ( expression constant ):

(2.1) is a constant expression must be an integral constant expression

(2.2) - (3.11) , .

. ,

std:: size_t. alignof , , , . .

, , alignof (std:: max_align_t). - , - , , (7.6.2). , , . [ : , (, ).

0

All Articles