While working on a fix for bug 58109 (and bug 69020) I came across another instance of attribute vector_size not being handled correctly (in addition to bug 35758 and bug 38260). In the following test case, the attribute is accepted on all declarations except that of c. As in bug 58109, the problem in this case also seems to be in the is_late_template_attribute() function which fails to treat the argument as dependent. $ cat x.cpp && /build/gcc-trunk-svn/gcc/xg++ -B /build/gcc-trunk-svn/gcc -S -Wall -Wextra -Wpedantic -o/dev/null x.cpp template <int N> struct A { static const int X = N; }; #define ASSERT(e) static_assert (e, #e) template <class T, int N> struct B: A<N> { using A<N>::X; static void foo () { char a __attribute__ ((vector_size (N))); ASSERT (sizeof a == N); T b __attribute__ ((vector_size (N))); ASSERT (sizeof b == N); } static void bar () { char c __attribute__ ((vector_size (X))); ASSERT (sizeof c == X); T d __attribute__ ((vector_size (X))); ASSERT (sizeof d == X); } }; void bar () { B<int, 16>::foo (); B<int, 16>::bar (); } x.cpp: In static member function ‘static void B<T, N>::bar()’: x.cpp:22:48: warning: ‘vector_size’ attribute ignored [-Wattributes] char c __attribute__ ((vector_size (X))); ^ x.cpp: In instantiation of ‘static void B<T, N>::bar() [with T = int; int N = 16]’: x.cpp:33:17: required from here x.cpp:4:19: error: static assertion failed: sizeof c == X #define ASSERT(e) static_assert (e, #e) ^ x.cpp:23:9: note: in expansion of macro ‘ASSERT’ ASSERT (sizeof c == X); ^~~~~~
I'll try to fix this in the same patch as bug 58109.
Patch posted for review: https://gcc.gnu.org/ml/gcc-patches/2015-12/msg02074.html
Author: msebor Date: Sat Jan 23 16:01:47 2016 New Revision: 232766 URL: https://gcc.gnu.org/viewcvs?rev=232766&root=gcc&view=rev Log: PR c++/58109 - alignas() fails to compile with constant expression PR c++/69022 - attribute vector_size ignored with dependent bytes gcc/testsuite/ChangeLog: 2016-01-23 Martin Sebor <msebor@redhat.com> PR c++/58109 PR c++/69022 * g++.dg/cpp0x/alignas5.C: New test. * g++.dg/ext/vector29.C: Same. gcc/cp/ChangeLog: 2016-01-23 Martin Sebor <msebor@redhat.com> PR c++/58109 PR c++/69022 * decl2.c (is_late_template_attribute): Handle dependent argument to attribute align and attribute vector_size. Added: trunk/gcc/testsuite/g++.dg/ext/vector29.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/decl2.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/g++.dg/cpp0x/alignas5.C
Fixed by r232766.
This does not fully handle vector_size, see bug #68703.