This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] Fix up static_cast/reinterpret_cast parsing in template argument (PR c++/57771)


Hi!

When parsing static_cast (expression) part inside of template argument,
greater_than_is_operator_p isn't temporarily set and thus the parser
considers >> in C++11 there as end of the the template argument, despite
this appearing before terminating ).

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk/4.8?

2013-07-01  Jakub Jelinek  <jakub@redhat.com>

	PR c++/57771
	* parser.c (cp_parser_postfix_expression) <case RID_STATCAST>
	Temporarily set parser->greater_than_is_operator_p for
	cp_parser_expression and restore from saved value afterwards.

	* g++.dg/template/arg9.C: New test.

--- gcc/cp/parser.c.jj	2013-07-01 22:43:42.000000000 +0200
+++ gcc/cp/parser.c	2013-07-01 22:47:14.220634900 +0200
@@ -5576,11 +5576,18 @@ cp_parser_postfix_expression (cp_parser
 	/* Restore the old message.  */
 	parser->type_definition_forbidden_message = saved_message;
 
+	bool saved_greater_than_is_operator_p
+	  = parser->greater_than_is_operator_p;
+	parser->greater_than_is_operator_p = true;
+
 	/* And the expression which is being cast.  */
 	cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
 	expression = cp_parser_expression (parser, /*cast_p=*/true, & idk);
 	cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
 
+	parser->greater_than_is_operator_p
+	  = saved_greater_than_is_operator_p;
+
 	/* Only type conversions to integral or enumeration types
 	   can be used in constant-expressions.  */
 	if (!cast_valid_in_integral_constant_expression_p (type)
--- gcc/testsuite/g++.dg/template/arg9.C.jj	2013-07-01 22:52:22.780699584 +0200
+++ gcc/testsuite/g++.dg/template/arg9.C	2013-07-01 22:51:22.000000000 +0200
@@ -0,0 +1,8 @@
+// PR c++/57771
+// { dg-do compile }
+
+template <int N>
+struct S {};
+
+S <static_cast <int> (4>>2)> s1;
+S <reinterpret_cast <int> (4>>2)> s2;

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]