On Fri, Jan 01, 2016 at 05:53:08PM -0700, Martin Sebor wrote: > On 12/31/2015 04:50 AM, Dominik Vogt wrote: > >The attached patch fixes C++-11 handling of "alignas(0)" which > >should be ignored but currently generates an error message. A > >test case is included; the patch has been tested on S390x. Since > >it's a language issue it should be independent of the backend > >used. > > The patch doesn't handle value-dependent expressions(*).
> It > seems that the problem is in handle_aligned_attribute() calling > check_user_alignment() with the second argument (ALLOW_ZERO) > set to false. Calling it with true fixes the problem and handles > value-dependent expressions (I haven't done any more testing beyond > that). Like the attached patch? (Passes the testsuite on s390x.) But wouldn't an "aligned" attribute be added, allowing the backend to possibly generate an error or a warning? > Also, in the test, I noticed the definition of the first struct > is missing the terminating semicolon. Yeah. Ciao Dominik ^_^ ^_^ -- Dominik Vogt IBM Germany
gcc/c-family/ChangeLog PR/69089 * c-common.c (handle_aligned_attribute): Allow 0 as an argument to the "aligned" attribute. gcc/testsuite/ChangeLog PR/69089 * g++.dg/cpp0x/alignas5.C: New test.
>From 2461293b9070da74950fd0ae055d1239cc69ce67 Mon Sep 17 00:00:00 2001 From: Dominik Vogt <v...@de.ibm.com> Date: Wed, 30 Dec 2015 15:08:52 +0100 Subject: [PATCH] C++-11: Ingore "alignas(0)" instead of generating an error message. This is required by the C++-11 standard. --- gcc/c-family/c-common.c | 2 +- gcc/testsuite/g++.dg/cpp0x/alignas5.C | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/alignas5.C diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 653d1dc..9eb25a9 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -7804,7 +7804,7 @@ handle_aligned_attribute (tree *node, tree ARG_UNUSED (name), tree args, else if (TYPE_P (*node)) type = node, is_type = 1; - if ((i = check_user_alignment (align_expr, false)) == -1 + if ((i = check_user_alignment (align_expr, true)) == -1 || !check_cxx_fundamental_alignment_constraints (*node, i, flags)) *no_add_attrs = true; else if (is_type) diff --git a/gcc/testsuite/g++.dg/cpp0x/alignas5.C b/gcc/testsuite/g++.dg/cpp0x/alignas5.C new file mode 100644 index 0000000..f3252a9 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/alignas5.C @@ -0,0 +1,29 @@ +// PR c++/69089 +// { dg-do compile { target c++11 } } +// { dg-options "-Wno-attributes" } + +alignas (0) int valid1; +alignas (1 - 1) int valid2; +struct Tvalid +{ + alignas (0) int i; + alignas (2 * 0) int j; +}; + +alignas (-1) int invalid1; /* { dg-error "not a positive power of 2" } */ +alignas (1 - 2) int invalid2; /* { dg-error "not a positive power of 2" } */ +struct Tinvalid +{ + alignas (-1) int i; /* { dg-error "not a positive power of 2" } */ + alignas (2 * 0 - 1) int j; /* { dg-error "not a positive power of 2" } */ +}; + +template <int N> struct TNvalid1 { alignas (N) int i; }; +TNvalid1<0> SNvalid1; +template <int N> struct TNvalid2 { alignas (N) int i; }; +TNvalid2<1 - 1> SNvalid2; + +template <int N> struct TNinvalid1 { alignas (N) int i; }; /* { dg-error "not a positive power of 2" } */ +TNinvalid1<-1> SNinvalid1; +template <int N> struct TNinvalid2 { alignas (N) int i; }; /* { dg-error "not a positive power of 2" } */ +TNinvalid2<1 - 2> SNinvalid2; -- 2.3.0