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

Template specialization error


Hi,

I'm trying to port some code to work on gcc.  Unfortunately I have
come across an error which I have been unable to solve.  I have
created a small example program which illustrates the compiler error I
get.

Compiling the following code using gcc 3.3.4 or 3.4.3 gives the following error:
test.C: In instantiation of `Bar<void>':
test.C:31:   instantiated from here
test.C:7: error: forming reference to void

When calling "fun<void>( k )" it appears that g++ gets confused with
the last argument in template  3 (see code) even though it should be
using the void specialization in Template 2.



template<class T>
struct Foo;

template<class T>
struct Bar
{
  typedef Foo< const T& > fooTypedef;
};

// Template 1
template <class T>
T fun( int Key )
{ };
  
// Template 2
// Specialization of fun template for void.
template <> inline 
void fun<void>( int Key ) { };

// Template 3
// The following function causes the error.  If you remove/rename this function
// or replace "typename Bar<T>::fooTypedef" with "Foo< const T& >"
// it compiles ok.
template <class T>
T fun( int Key, const typename Bar<T>::fooTypedef& theFoo )
{ };


int main()
{
  int k;

  fun<char>( k );
  fun<void>( k );
}


Am I doing something incorrectly here?

Thanks for any help you can provide.

Mark


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