Problem with class template instantiated with void.

Wegher, Jeff
Mon Nov 30 17:59:00 GMT 1998

Hi guys,

A little template instantiation problem popped up between 1.1b and the Nov
22 snapshot.

For some reason, it's either attempting to instantiate template members
which aren't used or is doing too much checking of the template members upon
first parse, and thus causes a little problem with smart-pointers
instantiated with void.

For instance:

# line 1"test_bad_void_template.cpp"
template < typename Type>
class Pointer
        Type* m_pObject;
        operator Type* () const { return m_pObject; }
        Type& operator * () const { return *m_pObject; }
int main()
        void* p;
        Pointer< void> vPtr;
        p = vPtr;
        return 0;

Compiling this code works fine under 1.1b (since the vPtr instance is not
dereferenced) but chokes now with:

% g++ test_bad_void_template.cpp -o test_bad_void_template
test_bad_void_template.cpp: In instantiation of `Pointer<void>':
test_bad_void_template.cpp:15:   instantiated from here
test_bad_void_template.cpp:9: forming reference to void

Relevant compiler info is: egcs-2.92.23 sparc-sun-solaris2.5.1, compiled
with --enable-threads --enable-shared

BTW, something didn't change in the standard that says this code is invalid,
did it?


More information about the Gcc-bugs mailing list