[PATCH] PR c++/54955 - Fail to parse alignas expr at the beginning of a declaration

Dodji Seketeli dodji@redhat.com
Fri Oct 26 17:50:00 GMT 2012


Hello,

In this PR, G++ embarrassingly fails to parse the simple alignas
expression below:

    alignas(double) int f;

even though the simple-declaration production in Clause 7 suggests
otherwise.

Fixed thus and tested on x86_64-unknown-linux-gnu against trunk.

gcc/cp

	PR c++/54955
	* parser.c (cp_next_tokens_can_be_std_attribute_p): Recognize the
	'alignas' keyword as the beginning of a c++11 attribute specifier.
	Update the comment of the function.

gcc/testsuite/

	PR c++/54955
	* g++.dg/cpp0x/gen-attrs-48-2.C: New test.
---
 gcc/cp/parser.c                             | 8 ++++++--
 gcc/testsuite/g++.dg/cpp0x/gen-attrs-48-2.C | 4 ++++
 2 files changed, 10 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/gen-attrs-48-2.C

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 9403563..50c1854 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -20324,12 +20324,16 @@ cp_next_tokens_can_be_gnu_attribute_p (cp_parser *parser)
 }
 
 /* Return TRUE iff the next tokens in the stream are possibly the
-   beginning of a standard C++-11 attribute.  */
+   beginning of a standard C++-11 attribute specifier.  */
 
 static bool
 cp_next_tokens_can_be_std_attribute_p (cp_parser *parser)
 {
-  return cp_nth_tokens_can_be_std_attribute_p (parser, 1);
+  cp_token *token = cp_lexer_peek_token (parser->lexer);
+
+  return (cxx_dialect >= cxx0x
+	  (token->type == CPP_KEYWORD && token->keyword == RID_ALIGNAS)
+	  || cp_nth_tokens_can_be_std_attribute_p (parser, 1));
 }
 
 /* Return TRUE iff the next Nth tokens in the stream are possibly the
diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-48-2.C b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-48-2.C
new file mode 100644
index 0000000..3cc5897
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-48-2.C
@@ -0,0 +1,4 @@
+// Origin: PR c++/54955
+// { dg-do compile { target c++11 } }
+
+alignas(double) int f;
-- 
1.7.11.7


-- 
		Dodji



More information about the Gcc-patches mailing list