public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Compiler error using 4.5.2 with function template
@ 2011-03-05 16:18 Edward Diener
  2011-03-05 16:38 ` Edward Diener
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Edward Diener @ 2011-03-05 16:18 UTC (permalink / raw)
  To: gcc-help

This very simple program:

template<class T> struct ATemplate { };
template<class T> void check(ATemplate<&T::SomeFuncTemplate<int> > *);

int main()
   {
   return 0;
   }

produces a compiler error:

"test_has_mem_fun_template.cpp:2:66: error: template argument 1 is invalid

     "g++"  -ftemplate-depth-128 -O0 -fno-inline -Wall -pedantic -g 
-Wno-variadic-macros   -I"..\..\.." 
-I"C:\Programming\VersionControl\boost" -c -o 
"..\..\..\bin.v2\libs\tti\test\test_has_mem_fun_template.test\gcc-mingw-4.5.2\debug\test_has_mem_fun_template.o" 
"test_has_mem_fun_template.cpp""

I suspect that I need to add the 'template' keyword to tell the compiler 
that SomeFuncTemplate is a function template but all my attempts appear 
to fail.

Is this a compiler bug or do I need to do something else above ?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Compiler error using 4.5.2 with function template
  2011-03-05 16:18 Compiler error using 4.5.2 with function template Edward Diener
@ 2011-03-05 16:38 ` Edward Diener
  2011-03-05 16:55 ` Axel Freyn
  2011-03-05 17:10 ` Jonathan Wakely
  2 siblings, 0 replies; 4+ messages in thread
From: Edward Diener @ 2011-03-05 16:38 UTC (permalink / raw)
  To: gcc-help

On 3/5/2011 11:17 AM, Edward Diener wrote:
> This very simple program:
>
> template<class T> struct ATemplate { };
> template<class T> void check(ATemplate<&T::SomeFuncTemplate<int> > *);
>
> int main()
> {
> return 0;
> }
>
> produces a compiler error:
>
> "test_has_mem_fun_template.cpp:2:66: error: template argument 1 is invalid
>
> "g++" -ftemplate-depth-128 -O0 -fno-inline -Wall -pedantic -g
> -Wno-variadic-macros -I"..\..\.."
> -I"C:\Programming\VersionControl\boost" -c -o
> "..\..\..\bin.v2\libs\tti\test\test_has_mem_fun_template.test\gcc-mingw-4.5.2\debug\test_has_mem_fun_template.o"
> "test_has_mem_fun_template.cpp""
>
> I suspect that I need to add the 'template' keyword to tell the compiler
> that SomeFuncTemplate is a function template but all my attempts appear
> to fail.
>
> Is this a compiler bug or do I need to do something else above ?

Evidently this works:

template<class T> struct ATemplate { };
template<class T> void check(ATemplate<typename T::template 
SomeFuncTemplate<int> > *);

int main()
   {
   return 0;
   }




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Compiler error using 4.5.2 with function template
  2011-03-05 16:18 Compiler error using 4.5.2 with function template Edward Diener
  2011-03-05 16:38 ` Edward Diener
@ 2011-03-05 16:55 ` Axel Freyn
  2011-03-05 17:10 ` Jonathan Wakely
  2 siblings, 0 replies; 4+ messages in thread
From: Axel Freyn @ 2011-03-05 16:55 UTC (permalink / raw)
  To: gcc-help

Hi Edward,
On Sat, Mar 05, 2011 at 11:17:52AM -0500, Edward Diener wrote:
> This very simple program:
>
> template<class T> struct ATemplate { };
> template<class T> void check(ATemplate<&T::SomeFuncTemplate<int> > *);
>
> int main()
>   {
>   return 0;
>   }
>
> produces a compiler error:
>
> "test_has_mem_fun_template.cpp:2:66: error: template argument 1 is invalid
>
>     "g++"  -ftemplate-depth-128 -O0 -fno-inline -Wall -pedantic -g  
> -Wno-variadic-macros   -I"..\..\.."  
> -I"C:\Programming\VersionControl\boost" -c -o  
> "..\..\..\bin.v2\libs\tti\test\test_has_mem_fun_template.test\gcc-mingw-4.5.2\debug\test_has_mem_fun_template.o" 
> "test_has_mem_fun_template.cpp""
>
> I suspect that I need to add the 'template' keyword to tell the compiler  
> that SomeFuncTemplate is a function template but all my attempts appear  
> to fail.
>
> Is this a compiler bug or do I need to do something else above ?
The compiler is right.
As soon as you assume that an element of an unknown class is a
class-type, you have to tell the compiler by adding a typename. E.g.
expressions of the form (T being a template parameter):
	A<T>::B
	T::B
are NO typenames… What you need, is
	typename A<T>::B
	typename T::B
such that the compiler understands that "B" will be a type.

I don't understand what you want exactly. However, the following works:
if "T::SomeType" is a type which does not depend on a template
parameter:
template<class T> void check(ATemplate<typename T::SomeType > *);

if "T::SomeFuncTemplate" is a type which depends on a given parameter
(in your example: int), you have to add an additional "template":

template<class T> void check(ATemplate<typename T::template SomeFuncTemplate<int> > *);

if that doesn't solve your problem, could you give as also an axample
for the class "T" -- so that we can see the precise definition of
::SomeFuncTemplate<int> ?

HTH,

Axel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Compiler error using 4.5.2 with function template
  2011-03-05 16:18 Compiler error using 4.5.2 with function template Edward Diener
  2011-03-05 16:38 ` Edward Diener
  2011-03-05 16:55 ` Axel Freyn
@ 2011-03-05 17:10 ` Jonathan Wakely
  2 siblings, 0 replies; 4+ messages in thread
From: Jonathan Wakely @ 2011-03-05 17:10 UTC (permalink / raw)
  To: Edward Diener; +Cc: gcc-help

On 5 March 2011 16:17, Edward Diener wrote:
>
> template<class T> struct ATemplate { };

The template parameter T must be a type.

> template<class T> void check(ATemplate<&T::SomeFuncTemplate<int> > *);

&T::SomeFuncTemplate<int> is an expression taking the address of a
member, it is not a type.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-03-05 17:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-05 16:18 Compiler error using 4.5.2 with function template Edward Diener
2011-03-05 16:38 ` Edward Diener
2011-03-05 16:55 ` Axel Freyn
2011-03-05 17:10 ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).