diff mbox

PR/68089: C++-11: Ingore "alignas(0)".

Message ID 20151231115039.GA31709@linux.vnet.ibm.com
State New
Headers show

Commit Message

Dominik Vogt Dec. 31, 2015, 11:50 a.m. UTC
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 ^_^  ^_^

Comments

Martin Sebor Jan. 2, 2016, 12:53 a.m. UTC | #1
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).

Also, in the test, I noticed the definition of the first struct
is missing the terminating semicolon.

Martin

[*] Such as in the following:

   template <int N> struct A { alignas (N) int i; };
   A<0> a3;
Andreas Krebbel April 29, 2016, 9:23 a.m. UTC | #2
On 12/31/2015 12:50 PM, 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.
> 
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69089

Applied. Thanks!

-Andreas-
diff mbox

Patch

From 59787d0af77d0a45dabb06ac7fc70e9bd7a9d5d8 Mon Sep 17 00:00:00 2001
From: Dominik Vogt <vogt@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