Query regarding "template as a qualifier"

John M Collins jmc@xisl.com
Tue Dec 28 19:25:00 GMT 2004


Please CC (carbon copy not compiler!) me in any reply as I'm not subscribed - 
thanks.

I've recently moved from G++ 3.3.1 to 3.4.1 and now 3.4.3

I have a suite of software which uses shared memory quite extensively and had 
built up a class library which in outline does the following:

class  shm_seg  {
private:
	void	*base;
	//  Other goodies
public:
	//  Constructors and such

	template<typename T> T* shm_cast(size_t offset)
	{ return reinterpret_cast<T*>(etc etc); }
};

This is so I can put (given an offset in the shared memory to a "foo" in 
segment described by "bar")

shm_seg  bar;
//  .... stuff

foo *fp = bar.shm_cast<foo>(foooffset);

Many versions of C++ including earlier versions of g++ required a "template 
qualifer" so that the parser didn't get confused as defined in Stroustrup 
appendix C 13.6 thus

foo *fp = bar.template shm_cast<foo>(foooffset);

G++ 3.3.* accepts this without warning. It also accepts the other version 
without the "template" keyword.

G++ 3.4.* rejects the latter form with

error: `template' (as a disambiguator) is only allowed within templates

I agree that it's much better that the compiler figures out what I want 
without me having to spell it out with spurious-looking "template"s 
everywhere but wouldn't it be better if this was a "warning" not an "error" 
to let people phase it out gently? Stroustrup doesn't actually say this only 
has to be done in a template and in principle you can see why many compilers 
aren't up to the task.

I know I can put "define template_qualifier" either to null or "template" as 
required but this is 73K lines of code with a goodly percentage of those 
"#ifdef obscure_machine_937" already.

(I wish I could leave out the "<foo>" too but that would mean that the result 
type would have to be considered).

-- 
John Collins Xi Software Ltd www.xisl.com



More information about the Gcc-help mailing list