g++(3.x) complains about incomplete type while it shouldn't

corey taylor corey.taylor@gmail.com
Tue Feb 1 23:30:00 GMT 2005


Peter,

  According to the specification (14.7.1.5), the requirement of that
template instantiation is left up to the implementation.

--
If the overload resolution process can determine the correct function
to call without instantiating a class
template definition, it is unspecified whether that instantiation
actually takes place. [Example:
template <class T> struct S {
operator int();
};
void f(int);
void f(S<int>&);
void f(S<float>);
void g(S<int>& sr) {
f(sr); //instantiation of S<int> allowed but not required
// instantiation of S<float> allowed but not required
};
—end example]



corey



On Tue, 1 Feb 2005 22:02:15 +0100, Peter Soetens
<peter.soetens@mech.kuleuven.ac.be> wrote:
> Hi,
> 
> The code below compiles fine with Intel's icc. However,
> all gcc versions refused to compile it saying :
> 
> g++    -c -o ttt.o ttt.cpp
> ttt.cpp: In instantiation of `Property<F>':
> ttt.cpp:15:   instantiated from `bool Property<T>::change(PropOp*) [with T =
> double]'
> ttt.cpp:23:   instantiated from here
> ttt.cpp:13: error: `Property<T>::val' has incomplete type
> ttt.cpp:1: error: forward declaration of `struct F'
> 
> -----Code-----
> struct F;
> 
> template< class T >
> struct Property;
> 
> struct PropOp {
>     bool update( Property<F>*      f) { return false; }
>     bool update( Property<double>* d) { return true; }
> };
> 
> template<class T>
> struct Property {
>     T val;
>     bool change( PropOp* p) {
>         return p->update( this );  // Line 15
>     }
> };
> 
> int main()
> {
>     PropOp po;
>     Property<double> pd;           // Line 23
>     pd.change( &po );
>     return 0;
> }
> 
> ----EndCode---
> 
> May I submit this as a bug ? I believe Property<F> should not be instantiated
> in line 15, only Property<double> should be.
> 
> Peter
> 
> PS: Please CC me.
> 
> --
> ------------------------------------------------------------------------
> Peter Soetens, Research Assistant                  http://www.orocos.org
> Katholieke Universiteit Leuven
> Division Production Engineering,                      tel. +32 16 322773
> Machine Design and Automation                         fax. +32 16 322987
> Celestijnenlaan 300B                   peter.soetens@mech.kuleuven.ac.be
> B-3001 Leuven Belgium                 http://www.mech.kuleuven.ac.be/pma
> ------------------------------------------------------------------------
>



More information about the Gcc-help mailing list