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]

Re: reject `f<typename T>' without crashing


On Dec  8, 2004, Jason Merrill <jason@redhat.com> wrote:

> On 08 Dec 2004 15:50:50 -0200, Alexandre Oliva <aoliva@redhat.com> wrote:
>> On Dec  8, 2004, Jakub Jelinek <jakub@redhat.com> wrote:
>> 
>>> On Wed, Dec 08, 2004 at 07:25:57AM -0200, Alexandre Oliva wrote:
>>>> Comments?  Ok to install if it passes regression testing, currently
>>>> ongoing on x86_64-linux-gnu?  
>> 
>>> FYI it causes regression on the 7 arches I bootstraped/regtested 3.4.3-RH
>>> on today:
>>> FAIL: g++.dg/parse/typename5.C (test for excess errors)
>> 
>> Yup, mainline too.
>> 
>>> That testcase is checking error messages on invalid and your patch
>>> changes the errors that are issued, so if the patch is accepted
>>> the above mentioned testcase will need tweaking.
>> 
>> Will do.

> OK, then.

Thanks, the first attached patch is what I'm checking in in mainline.
Ok for the 3.4 branch as well?  It's the second patch, with just a
minor tweak for it to apply cleanly; regression-tested successfully on
x86_64-linux-gnu.

Index: gcc/cp/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	PR c++/18757
	* parser.c (cp_parser_template_id): Don't create a CPP_TEMPLATE_ID
	if parsing failed.

Index: gcc/cp/parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.289
diff -u -p -r1.289 parser.c
--- gcc/cp/parser.c 3 Dec 2004 09:51:35 -0000 1.289
+++ gcc/cp/parser.c 9 Dec 2004 12:10:08 -0000
@@ -8416,8 +8416,9 @@ cp_parser_template_id (cp_parser *parser
      should we re-parse the token stream, we will not have to repeat
      the effort required to do the parse, nor will we issue duplicate
      error messages about problems during instantiation of the
-     template.  */
-  if (start_of_id)
+     template.  Do so only if parsing succeeded, otherwise we may
+     silently accept template arguments with syntax errors.  */
+  if (start_of_id && !cp_parser_error_occurred (parser))
     {
       cp_token *token = cp_lexer_token_at (parser->lexer, start_of_id);
       
Index: gcc/testsuite/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* g++.dg/parse/typename5.C: Adjust for new error.
	* g++.dg/parse/typename7.C: New.

Index: gcc/testsuite/g++.dg/parse/typename5.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.dg/parse/typename5.C,v
retrieving revision 1.2
diff -u -p -r1.2 typename5.C
--- gcc/testsuite/g++.dg/parse/typename5.C 15 Dec 2003 06:28:22 -0000 1.2
+++ gcc/testsuite/g++.dg/parse/typename5.C 9 Dec 2004 12:10:36 -0000
@@ -8,5 +8,5 @@ template <typename> struct A {};
 
 template <typename> struct B
 {
-    typedef A<typename X::Y> C; // { dg-error "declared|invalid|no type" }
+    typedef A<typename X::Y> C; // { dg-error "declared|invalid|no type|expected" }
 };
Index: gcc/testsuite/g++.dg/parse/typename7.C
===================================================================
RCS file: gcc/testsuite/g++.dg/parse/typename7.C
diff -N gcc/testsuite/g++.dg/parse/typename7.C
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/g++.dg/parse/typename7.C 9 Dec 2004 12:10:36 -0000
@@ -0,0 +1,31 @@
+// { dg-do compile }
+
+// Origin: Volker Reichelt <reichelt@igpm.rwth-aachen.de> and
+// Alexandre Oliva <aoliva@redhat.com>
+
+// PR c++/18757: ICE in get_innermost_template_args
+
+struct A
+{
+  template<typename>   void foo(int);
+  template<typename T> void bar(T t) {
+    this->foo<typename T>(t); } // { dg-error "expected" }
+  template<typename T> void bad(T t) {
+    foo<typename T>(t); } // { dg-error "expected" }
+};
+
+template <typename T>
+struct B
+{
+  void bar(T t) {
+    A().bar<typename T>(t); } // { dg-error "expected" }
+  void bad(T t) {
+    B<typename T>::bar(t); } // { dg-error "invalid|not a template" }
+};
+
+void baz()
+{
+    A().bar(0);
+    A().bad(0);
+    B<int>().bar(0);
+}
Index: gcc/testsuite/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* g++.dg/parse/typename5.C: Adjust for new error.
	* g++.dg/parse/typename7.C: New.

Index: gcc/cp/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	PR c++/18757
	* parser.c (cp_parser_template_id): Don't create a CPP_TEMPLATE_ID
	if parsing failed.

Index: gcc/cp/parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.157.2.46
diff -u -p -r1.157.2.46 parser.c
--- gcc/cp/parser.c 2 Dec 2004 11:51:26 -0000 1.157.2.46
+++ gcc/cp/parser.c 9 Dec 2004 12:30:59 -0000
@@ -8014,7 +8014,7 @@ cp_parser_template_id (cp_parser *parser
      the effort required to do the parse, nor will we issue duplicate
      error messages about problems during instantiation of the
      template.  */
-  if (start_of_id >= 0)
+  if (start_of_id >= 0 && !cp_parser_error_occurred (parser))
     {
       cp_token *token;
 
Index: gcc/testsuite/g++.dg/parse/typename5.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.dg/parse/typename5.C,v
retrieving revision 1.2
diff -u -p -r1.2 typename5.C
--- gcc/testsuite/g++.dg/parse/typename5.C 15 Dec 2003 06:28:22 -0000 1.2
+++ gcc/testsuite/g++.dg/parse/typename5.C 9 Dec 2004 12:30:59 -0000
@@ -8,5 +8,5 @@ template <typename> struct A {};
 
 template <typename> struct B
 {
-    typedef A<typename X::Y> C; // { dg-error "declared|invalid|no type" }
+    typedef A<typename X::Y> C; // { dg-error "declared|invalid|no type|expected" }
 };
Index: gcc/testsuite/g++.dg/parse/typename7.C
===================================================================
RCS file: gcc/testsuite/g++.dg/parse/typename7.C
diff -N gcc/testsuite/g++.dg/parse/typename7.C
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/g++.dg/parse/typename7.C 9 Dec 2004 12:30:59 -0000
@@ -0,0 +1,31 @@
+// { dg-do compile }
+
+// Origin: Volker Reichelt <reichelt@igpm.rwth-aachen.de> and
+// Alexandre Oliva <aoliva@redhat.com>
+
+// PR c++/18757: ICE in get_innermost_template_args
+
+struct A
+{
+  template<typename>   void foo(int);
+  template<typename T> void bar(T t) {
+    this->foo<typename T>(t); } // { dg-error "expected" }
+  template<typename T> void bad(T t) {
+    foo<typename T>(t); } // { dg-error "expected" }
+};
+
+template <typename T>
+struct B
+{
+  void bar(T t) {
+    A().bar<typename T>(t); } // { dg-error "expected" }
+  void bad(T t) {
+    B<typename T>::bar(t); } // { dg-error "invalid|not a template" }
+};
+
+void baz()
+{
+    A().bar(0);
+    A().bad(0);
+    B<int>().bar(0);
+}
-- 
Alexandre Oliva             http://www.ic.unicamp.br/~oliva/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}

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