[patch] Fix PR c++/28303
Lee Millward
lee.millward@codesourcery.com
Sat Sep 9 13:24:00 GMT 2006
Hi,
This bug is an ICE with the following invalid testcase in is_ancestor:
template<typename T> struct A
{
typedef struct typename T::X X;
};
template<typename T> A<T>::X::X() {}
The patch to fix this is simple, when the diagnostic is issued about
duplicate data types for a declaration, return error_mark_node to mark
it as invalid which is what the attached patch does.
Bootstrapped and regression tested with no new failures on
i686-pc-linux-gnu, ok for mainline?
Cheers,
Lee.
:ADDPATCH c++:
2006-09-09 Lee Millward <lee.millward@codesourcery.com>
PR c++/28303
* decl.c (grokdeclarator): Return error_mark_node on
declaration with two or more data types.
2006-09-09 Lee Millward <lee.millward@codesourcery.com>
PR c++/28303
* g++.dg/template/typedef6.C: New test.
* g++.dg/init/error1.C: Adjust error markers.
* g++.dg/parse/crash9.C: Likewise.
* g++.dg/template/crash55.C: Likewise.
-------------- next part --------------
Index: gcc/testsuite/g++.dg/init/error1.C
===================================================================
--- gcc/testsuite/g++.dg/init/error1.C (revision 116702)
+++ gcc/testsuite/g++.dg/init/error1.C (working copy)
@@ -1,7 +1,7 @@
// PR c++/12696
struct A {
- static float b[10]; // { dg-error "" }
+ static float b[10];
}
float A::b[] = {1,2,3}; // { dg-error "" }
Index: gcc/testsuite/g++.dg/parse/crash9.C
===================================================================
--- gcc/testsuite/g++.dg/parse/crash9.C (revision 116702)
+++ gcc/testsuite/g++.dg/parse/crash9.C (working copy)
@@ -6,4 +6,4 @@
// contains error.
template <typename> struct A {};
-template <typename> struct A<INVALID> : A<int> { }; // { dg-error "not declared|invalid" }
+template <typename> struct A<INVALID> : A<int> { }; // { dg-error "not declared|invalid|token|extra" }
Index: gcc/testsuite/g++.dg/template/crash55.C
===================================================================
--- gcc/testsuite/g++.dg/template/crash55.C (revision 116702)
+++ gcc/testsuite/g++.dg/template/crash55.C (working copy)
@@ -1,6 +1,6 @@
//PR c++/27668
template<typename class T, T = T()> // { dg-error "nested-name-specifier|two or more|valid type" }
-struct A {}; // { dg-error "definition"
+struct A {}; // { dg-error "definition|template" }
template<int> void foo(A<int>); // { dg-error "mismatch|constant|template argument" }
Index: gcc/testsuite/g++.dg/template/typedef6.C
===================================================================
--- gcc/testsuite/g++.dg/template/typedef6.C (revision 0)
+++ gcc/testsuite/g++.dg/template/typedef6.C (revision 0)
@@ -0,0 +1,8 @@
+//PR c++/28303
+
+template<typename T> struct A
+{
+ typedef struct typename T::X X; // { dg-error "expected identifier|two or more" }
+};
+
+template<typename T> A<T>::X::X() {} // { dg-error "not a type|forbids declaration" }
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c (revision 116702)
+++ gcc/cp/decl.c (working copy)
@@ -7118,7 +7118,11 @@ grokdeclarator (const cp_declarator *dec
/* If there were multiple types specified in the decl-specifier-seq,
issue an error message. */
if (declspecs->multiple_types_p)
- error ("two or more data types in declaration of %qs", name);
+ {
+ error ("two or more data types in declaration of %qs", name);
+ return error_mark_node;
+ }
+
/* Extract the basic type from the decl-specifier-seq. */
type = declspecs->type;
if (type == error_mark_node)
More information about the Gcc-patches
mailing list