Perfectly valid C++ syntax causes a compiler error when used inside a template
function. Both the Sun compiler and Microsoft compiler have no trouble with the
sample code shown below. Notice that the same code inside the non-template
function succeeds in compiling just fine. The GCC compiler appears to have
trouble figuring out that the expression resolves into a normal data type. The
error I get from GCC is:

test23.cpp: In function `void THIS_FAILS(T)':
test23.cpp:19: error: type/value mismatch at argument 1 in template parameter
list for `template<class T> struct whatever'
test23.cpp:19: error:   expected a type, got ` S<sizeof (func(var))>::type'
test23.cpp:19: error: invalid type in declaration before ';' token

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


template< typename T > struct whatever {};


template< int > struct S;
template<> struct S<1>  {  typedef char Array[ 1 ];  typedef char type;  };

S<1>::Array&   func( const char & );


void THIS_WORKS( char var )
{
        whatever<  S< sizeof( func( var ) ) >::type  >  temporary;
}

template< typename T >
void THIS_FAILS( T var )
{
        whatever<  S< sizeof( func( var ) ) >::type  >  temporary;
}


-- 
           Summary: Template argument is not recognized as a Type inside a
                    template function.
           Product: gcc
           Version: 3.4.6
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: SSacek at appsecinc dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30524

Reply via email to