Possible bug in vc7.0 (and vc7.1) 
Author Message
 Possible bug in vc7.0 (and vc7.1)

Hi,

I'm having problems with some code of mine which fails to compile in vc7.0
Since I don't have it, I'm trying to guess the cause... could you compile
the following and show which errors it produces, if any, with both vc7.0 and
vc7.1?

TIA

template<class T>
struct X
{
  X();
  template<class U> X ( X<U> const& ) ;
  X ( X const& ) ;

Quote:
} ;

template<class T>
struct Y
{
  Y();
  explicit template<class U> Y ( Y<U> const& ) ;
  Y ( Y const& ) ;

Quote:
} ;

template<class T> void eat ( X<T> ) ;
template<class T> void eat ( Y<T> ) ;

int main()
{
  X<int> x1 ;
  X<int> x2 = x1;
  eat(x1);

  Y<int> y1 ;
  Y<int> y2 = y1;
  eat(y1);

Quote:
}

--
Fernando Cacciola


Sun, 17 Jul 2005 22:21:39 GMT  
 Possible bug in vc7.0 (and vc7.1)

Quote:
> Hi,

> I'm having problems with some code of mine which fails to compile in
vc7.0
> Since I don't have it, I'm trying to guess the cause... could you
compile
> the following and show which errors it produces, if any, with both
vc7.0 and
> vc7.1?

You code contains an error, it should read:

template<class T>
struct X
{
  X();
  template<class U> X ( X<U> const& ) ;
  X ( X const& ) ;

Quote:
} ;

template<class T>
struct Y
{
  Y();
  template<class U> explicit Y ( Y<U> const& ) ;  // 1
  Y ( Y const& ) ;

Quote:
} ;

template<class T> void eat ( X<T> ) ;
template<class T> void eat ( Y<T> ) ;

int main()
{
  X<int> x1 ;
  X<int> x2 = x1;
  eat(x1);

  Y<int> y1 ;
  Y<int> y2 = y1;
  eat(y1);

Quote:
}

With the change at //1, Comeau 4.3 and VC 7.1 (RC1) both compile your
code.  VC7 is unable to handle it.  It looks like VC7 is confused by the
explicit on the templated copy constructor, even though in this case, it
should be using the non-templated constructor, which is not explicit.

Indeed, removing the explicit allows VC7 to compile the code, but
obviously opens other doors, since the templated constructor becomes
available for implicit type conversions, which you probably don't want.

-cd



Sun, 17 Jul 2005 22:44:14 GMT  
 Possible bug in vc7.0 (and vc7.1)



Quote:


> > Hi,

> > I'm having problems with some code of mine which fails to compile in
> vc7.0
> > Since I don't have it, I'm trying to guess the cause... could you
> compile
> > the following and show which errors it produces, if any, with both
> vc7.0 and
> > vc7.1?

> You code contains an error, it should read:

Thanks for spotting it!

Quote:

> template<class T>
> struct X
> {
>   X();
>   template<class U> X ( X<U> const& ) ;
>   X ( X const& ) ;
> } ;

> template<class T>
> struct Y
> {
>   Y();
>   template<class U> explicit Y ( Y<U> const& ) ;  // 1
>   Y ( Y const& ) ;
> } ;

> template<class T> void eat ( X<T> ) ;
> template<class T> void eat ( Y<T> ) ;

> int main()
> {
>   X<int> x1 ;
>   X<int> x2 = x1;
>   eat(x1);

>   Y<int> y1 ;
>   Y<int> y2 = y1;
>   eat(y1);
> }

> With the change at //1, Comeau 4.3 and VC 7.1 (RC1) both compile your
> code.

I see.

Quote:
>VC7 is unable to handle it.  It looks like VC7 is confused by the
> explicit on the templated copy constructor, even though in this case, it
> should be using the non-templated constructor, which is not explicit.

> Indeed, removing the explicit allows VC7 to compile the code, but
> obviously opens other doors, since the templated constructor becomes
> available for implicit type conversions, which you probably don't want.

Thanks, this is exactly what I thought the problem was...

--
Fernando Cacciola



Sun, 17 Jul 2005 23:26:25 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. possible bug in VC6, VC7, VC7.1

2. Possible Bug in VC++.Net VC7 Debugger?

3. Invalid Program Format(Possible VC7++ BUG??)

4. my bug or VC7 bug ?

5. VC7.1 covariant return bug?

6. VC7.1 C++ bug: incorrect definition of the constructor of a template accepted

7. VC7 IDE bug?

8. VC7 adds a new twist to an old C++ compiler bug

9. VC6/VC7 bug with ?: operator and throw expressions.

10. optimizer bug in VC7.1 final beta Visual Studio .Net 2003

11. bug in VC7

12. Bug in VC7 Linker

 

 
Powered by phpBB® Forum Software