Test program:

template <class T> class foo
{
public:
    static const unsigned long long max = (T)~0ULL;
    bool toobig (unsigned long long val) 
    {
        return val > max;
    }
};

Message:

test.cc: In member function ‘bool foo<T>::toobig(long long unsigned int)’:
test.cc:7: error: ‘T’ used where a ‘long long unsigned int’ was expected

The baffling part is that T doesn't occur anywhere in or near line 7.  It's
almost as if the initialization part of the static const member has been
textually substituted in line 7 -- but if it were that should still be legal... 

It works ok if I explicitly initialize the member outside the class definition
via specializations, which is tolerable given that only a small number of cases
of this template class are used.

-- 
           Summary: Strange error message on reference to static const
                    member initialized via cast
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pkoning at equallogic dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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

Reply via email to