This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: warning: assignment to `int' from `double'
- From: "Ralf W. Grosse-Kunstleve" <rwgk at cci dot lbl dot gov>
- To: gcc at gcc dot gnu dot org
- Cc: hahn at physics dot mcmaster dot ca, rwgk at boa dot lbl dot gov
- Date: Wed, 27 Feb 2002 15:16:35 -0800 (PST)
- Subject: Re: warning: assignment to `int' from `double'
> > operator+= etc. for operations on arrays. The array
> > element types can be custom types with overloaded
> > operators. Any cast buried in the array operator+= would
> > interfere with the semantics of the overloaded custom
> > operators.
>
> I'm not sure why this is relevant; the issue is implicit conversions,
> isn't it?
Consider an idealized array operator+=:
template <typename ElementType1,
typename ElementType2>
std::vector<ElementType1>&
operator+=(std::vector<ElementType1>& a1,
const std::vector<ElementType1>& a2) {
for(std::size_t i=0;i<a1.size();i++) a1[i] += a2[i];
return a1;
}
For built-in types this would be fine:
a[i] += ElementType1(a2[i]);
But for custom types with potentially multiple overloads
for operator+= this construct would result in unexpected
behavior.
> > gcc 3.0.x (incl. 3.0.4) is the only compiler that issues
> > the warning above. (I am also using various EDG derivatives
> > and Codewarrior.)
>
> not a strong argument; you need to reference the standard.
If the standard demands a warning it is counter-productive
in my case. I wish it would be possible to selectively
suppress the warning.
Thanks,
Ralf