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]

[patch] PR c++/22172


 Hi,

  This patch makes the c++ parser issue and error of typename is used in the
wrong place.  We used to ICE in this situation.  This patch has been
bootstrapped and regtested on ia64-linux with no new regressions.  Ok for
mainline and 4.0.3?

-- 
Thanks,
Jim

http://www.csclub.uwaterloo.ca/~ja2morri/
http://phython.blogspot.com
http://open.nit.ca/wiki/?page=jim

2005-09-25  James A. Morrison  <phython@gcc.gnu.org>

	PR c++/22172
	* parser.c (cp_parser_postfix_expression): Ensure RID_TYPENAME only
	occurs in the context of a type.

Index: parser.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.359
diff -u -p -r1.359 parser.c
--- parser.c	16 Sep 2005 18:33:08 -0000	1.359
+++ parser.c	26 Sep 2005 00:22:10 -0000
@@ -3984,9 +3984,17 @@ cp_parser_postfix_expression (cp_parser 
 	/* Don't process id if nested name specifier is invalid.  */
 	if (!scope || scope == error_mark_node)
 	  return error_mark_node;
+
+	/* Complain about typename used on something other than a type.  */
+	if (!TYPE_P (scope))
+	  {
+	    cp_parser_error (parser, "typename used on non-type");
+	    return error_mark_node;
+	  }
+
 	/* If we look up a template-id in a non-dependent qualifying
 	   scope, there's no need to create a dependent type.  */
-	else if (TREE_CODE (id) == TYPE_DECL
+	if (TREE_CODE (id) == TYPE_DECL
 	    && !dependent_type_p (parser->scope))
 	  type = TREE_TYPE (id);
 	/* Create a TYPENAME_TYPE to represent the type to which the
// { dg-do compile }
namespace N { template<int> struct A {}; }

template<typename> void foo()
{
	    +typename N::A<0>;  // { dg-error "typename" }
}

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