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: PR 19253


This patch fixes another ICE-on-invalid.  The introduction of
cp_parser_diagnose_invalid_type_name and its friends was rather
confused; there was no clear design for these functions.  The
duplicate error messages are coming from the fact that this function
unconditionally issues error messages (even if we are parsing
tentatively), but does nothing to ensure that the parser does not then
backtrack and re-encounter the same error.  That's a design bug.

Therefore, I've modified the function to commit to the tentative
parse.  If callers don't want that behavior, they need to avoid
calling this function.

Tested on x86_64-unknown-linux-gnu, applied on the mainline.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2005-01-28  Mark Mitchell  <mark@codesourcery.com>

	PR c++/19253
	* parser.c (cp_parser_diagnose_invalid_type_name): Commit to
	tentative parses.

2005-01-28  Mark Mitchell  <mark@codesourcery.com>

	PR c++/19253
	* g++.dg/template/crash33.C: New test.

Index: cp/parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.303
diff -c -5 -p -r1.303 parser.c
*** cp/parser.c	26 Jan 2005 18:45:00 -0000	1.303
--- cp/parser.c	29 Jan 2005 02:05:13 -0000
*************** cp_parser_non_integral_constant_expressi
*** 1959,1969 ****
      }
    return false;
  }
  
  /* Emit a diagnostic for an invalid type name.  SCOPE is the
!    qualifying scope (or NULL, if none) for ID.  */
  
  static void
  cp_parser_diagnose_invalid_type_name (cp_parser *parser, tree scope, tree id)
  {
    tree decl, old_scope;
--- 1959,1972 ----
      }
    return false;
  }
  
  /* Emit a diagnostic for an invalid type name.  SCOPE is the
!    qualifying scope (or NULL, if none) for ID.  This function commits
!    to the current active tentative parse, if any.  (Otherwise, the
!    problematic construct might be encountered again later, resulting
!    in duplicate error messages.)  */
  
  static void
  cp_parser_diagnose_invalid_type_name (cp_parser *parser, tree scope, tree id)
  {
    tree decl, old_scope;
*************** cp_parser_diagnose_invalid_type_name (cp
*** 2031,2040 ****
--- 2034,2044 ----
        else if (TYPE_P (parser->scope))
  	error ("%qE in class %qT does not name a type", id, parser->scope);
        else
  	gcc_unreachable ();
      }
+   cp_parser_commit_to_tentative_parse (parser);
  }
  
  /* Check for a common situation where a type-name should be present,
     but is not, and issue a sensible error message.  Returns true if an
     invalid type-name was detected.
Index: testsuite/g++.dg/template/crash33.C
===================================================================
RCS file: testsuite/g++.dg/template/crash33.C
diff -N testsuite/g++.dg/template/crash33.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/template/crash33.C	29 Jan 2005 02:05:13 -0000
***************
*** 0 ****
--- 1,8 ----
+ // PR c++/19253
+ 
+ namespace N {}
+ 
+ template<typename> struct A
+ {
+   A<typename N::X<int> > a; // { dg-error "" }
+ };


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