Need help adding an error to gcc (C++)
Craig Rodrigues
rodrigc@attbi.com
Wed Mar 6 21:08:00 GMT 2002
Hi,
I am looking at PR 4926:
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&database=gcc&pr=4926
The following C++ testcase will crash the compiler:
====================================================================
namespace ExprType
{
struct UnknownType;
template<unsigned>
struct ETType
{
typedef UnknownType Type;
};
template<typename T>
struct ETArray
{
char array[1];
};
template<typename T>
ETArray<T> etFunc(const T& t);
}
namespace ExprType{ template<> struct ETArray<int > { char array[7]; }; template<> struct ETType<7> { typedef int Type; };}
namespace ExprType{ template<> struct ETArray<double > { char array[12]; }; template<> struct ETType<12> { typedef double Type; };}
struct F
{
int operator()(int,double) const
{
return 3;
}
} f;
template<typename T>
T makeT();
template<typename Func,typename Arg1,typename Arg2>
typename ExprType::ETType<sizeof(ExprType::etFunc(makeT<Func>()(makeT<Arg1>(),makeT<Arg2>())).array)>::Type doCall(const Func& func,const Arg1& a1,const Arg2& a2)
{
return func(a1,a2);
}
int main()
{
doCall(f,4,7.5);
}
====================================================================
The backtrace of the problem leads to:
#0 0x400a5f27 in strlen (str=0x0) at ../sysdeps/i386/strlen.c:28
#1 0x0811b7bc in write_expression (expr=0x401855f0)
at cp/mangle.c:1830
#2 0x0811b881 in write_expression (expr=0x40186140)
at cp/mangle.c:1856
#3 0x0811b881 in write_expression (expr=0x40186160)
at cp/mangle.c:1856
#4 0x0811b881 in write_expression (expr=0x40185618)
at cp/mangle.c:1856
#5 0x0811c79d in write_template_arg (node=0x40185618)
at cp/mangle.c:1967
#6 0x0811b668 in write_template_args (args=0x40185640)
I am playing around with a patch:
Index: mangle.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/mangle.c,v
retrieving revision 1.44
diff -u -r1.44 mangle.c
--- mangle.c 2002/02/20 04:09:04 1.44
+++ mangle.c 2002/03/07 05:05:08
@@ -1825,7 +1825,13 @@
code = TREE_CODE (expr);
}
-
+
+ if (! operator_name_info[(int) code].mangled_name )
+ {
+ error ("Error during template instantiation");
+ return;
+ }
+
/* If it wasn't any of those, recursively expand the expression. */
write_string (operator_name_info[(int) code].mangled_name);
This seems to prevent the compiler crash, but
I am not familiar enough with gcc to know what to put
for the error message.
Can someone help me with this?
Thanks.
--
Craig Rodrigues
http://www.gis.net/~craigr
rodrigc@attbi.com
More information about the Gcc
mailing list