public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* warning: assignment to `int' from `double'
@ 2002-02-27 10:29 Ralf W. Grosse-Kunstleve
  2002-02-27 11:14 ` Neil Booth
  0 siblings, 1 reply; 4+ messages in thread
From: Ralf W. Grosse-Kunstleve @ 2002-02-27 10:29 UTC (permalink / raw)
  To: gcc; +Cc: rwgk

The following code generates warnings with gcc 3.0.3:

int main()
{
  int i;
  double d;
  i = 0;
  i += d;
  return 0;
}

g++ -g z.cpp -o z

z.cpp: In function `int main()':
z.cpp:6: warning: assignment to `int' from `double'
z.cpp:6: warning: argument to `int' from `double'

Is it possible to suppress this warning without resorting to -w?

Thanks,
        Ralf

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: warning: assignment to `int' from `double'
  2002-02-27 10:29 warning: assignment to `int' from `double' Ralf W. Grosse-Kunstleve
@ 2002-02-27 11:14 ` Neil Booth
  0 siblings, 0 replies; 4+ messages in thread
From: Neil Booth @ 2002-02-27 11:14 UTC (permalink / raw)
  To: Ralf W. Grosse-Kunstleve; +Cc: gcc, rwgk

Ralf W. Grosse-Kunstleve wrote:-

> The following code generates warnings with gcc 3.0.3:
> 
> int main()
> {
>   int i;
>   double d;
>   i = 0;
>   i += d;
>   return 0;
> }
> 
> g++ -g z.cpp -o z
> 
> z.cpp: In function `int main()':
> z.cpp:6: warning: assignment to `int' from `double'
> z.cpp:6: warning: argument to `int' from `double'
> 
> Is it possible to suppress this warning without resorting to -w?

Have you tried a cast?

Neil.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: warning: assignment to `int' from `double'
@ 2002-02-27 15:27 Ralf W. Grosse-Kunstleve
  0 siblings, 0 replies; 4+ messages in thread
From: Ralf W. Grosse-Kunstleve @ 2002-02-27 15:27 UTC (permalink / raw)
  To: gcc; +Cc: hahn, rwgk

> > 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: warning: assignment to `int' from `double'
@ 2002-02-27 11:30 Ralf W. Grosse-Kunstleve
  0 siblings, 0 replies; 4+ messages in thread
From: Ralf W. Grosse-Kunstleve @ 2002-02-27 11:30 UTC (permalink / raw)
  To: gcc; +Cc: neil, rwgk

Neil Booth wrote:

> Ralf W. Grosse-Kunstleve wrote:-
> 
> > The following code generates warnings with gcc 3.0.3:
> > 
> > int main()
> > {
> >   int i;
> >   double d;
> >   i = 0;
> >   i += d;
> >   return 0;
> > }
> > 
> > g++ -g z.cpp -o z
> > 
> > z.cpp: In function `int main()':
> > z.cpp:6: warning: assignment to `int' from `double'
> > z.cpp:6: warning: argument to `int' from `double'
> > 
> > Is it possible to suppress this warning without resorting to -w?
> 
> Have you tried a cast?

In my application a cast is not an option. I am overloading
operator+= etc. for operations on arrays. The array
element types can be custom types with overloaded
operators. Any cast burried in the array operator+= would
interfer with the semantics of the overloaded custom
operators.

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.)

Thanks,
        Ralf

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-02-27 23:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-27 10:29 warning: assignment to `int' from `double' Ralf W. Grosse-Kunstleve
2002-02-27 11:14 ` Neil Booth
2002-02-27 11:30 Ralf W. Grosse-Kunstleve
2002-02-27 15:27 Ralf W. Grosse-Kunstleve

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).