This is the mail archive of the gcc@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]

templates with pointer arguments


Hello,

In advance, I have found and read the
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=7166 bug report, but I do
not really understand the explanation. Maybe it is related with the fact
that template arguments must be known at compile time (i.e., constants)?

Take the following example:

template <typename _Tp, _Tp _errorflag> _Tp fn(void) {
	return _errorflag;
}

void x(void) {
	int i=fn<int,0>();
	char *p=fn<char *,(char *)0>();
}

Here GCC gives an error at the line marked with *:

test2.cpp: In function `void x()':
test2.cpp:7: `0' is not a valid template argument
test2.cpp:7: it must be the address of an object with external linkage
test2.cpp:7: no matching function for call to `fn()'

How can I force gcc to accept this type of code? I always want to pass
well-known values in the _errorflag, e.g. (char *)0.

Thanks,
Ferenc

PS: I am not on the list, please CC it to my personal address, too!
Thanks.


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