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.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69089 Ciao Dominik ^_^ ^_^ -- Dominik Vogt IBM Germany
gcc/cp/ChangeLog * parser.c (cp_parser_std_attribute_spec): Do not generate an "aligned" attribute for "alignas(0)". gcc/testsuite/ChangeLog PR tree-optimization/68069 * g++.dg/cpp0x/alignas5.C: New test.
>From 59787d0af77d0a45dabb06ac7fc70e9bd7a9d5d8 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] PR/68089: C++-11: Ingore "alignas(0)". error message. This is required by the C++-11 standard. --- gcc/cp/parser.c | 15 +++++++++------ gcc/testsuite/g++.dg/cpp0x/alignas5.C | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/alignas5.C diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index c1948c4..72da56d 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -23990,6 +23990,7 @@ cp_parser_std_attribute_spec (cp_parser *parser) else { tree alignas_expr; + int is_int_zero; /* Look for an alignment-specifier. */ @@ -24026,6 +24027,7 @@ cp_parser_std_attribute_spec (cp_parser *parser) } alignas_expr = cxx_alignas_expr (alignas_expr); + is_int_zero = integer_zerop (alignas_expr); alignas_expr = build_tree_list (NULL_TREE, alignas_expr); if (cp_lexer_next_token_is (parser->lexer, CPP_ELLIPSIS)) @@ -24040,12 +24042,13 @@ cp_parser_std_attribute_spec (cp_parser *parser) return error_mark_node; } - /* Build the C++-11 representation of an 'aligned' - attribute. */ - attributes = - build_tree_list (build_tree_list (get_identifier ("gnu"), - get_identifier ("aligned")), - alignas_expr); + if (! is_int_zero) + /* Build the C++-11 representation of an 'aligned' + attribute. */ + attributes = + build_tree_list (build_tree_list (get_identifier ("gnu"), + get_identifier ("aligned")), + alignas_expr); } return attributes; diff --git a/gcc/testsuite/g++.dg/cpp0x/alignas5.C b/gcc/testsuite/g++.dg/cpp0x/alignas5.C new file mode 100644 index 0000000..0ddbc63 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/alignas5.C @@ -0,0 +1,19 @@ +// 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" } */ +}; -- 2.3.0