This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Assignement from int to bool gives no warning


Hi all,

Consider this piece of code:

  float bar(void)
  {
    int rv = 0;
    float level = 42.0;

    rv = level;

    return(rv);
  }

If I compile this with g++-2.95.2 (on IRIX 6.3), I get the following
warning:

  erik@o2:/tmp > g++ -Wall -c bar.cc -o bar.o
  bar.cc: In function `float bar()':
  bar.cc:6: warning: assignment to `int' from `float'

This is a correct and valuable warning, because I'm losing resolution in
the assignment.

Now consider this code:

  int foo(void)
  {
    bool rv = false;
    int level = 42;

    rv = level;

    return(rv);
  }

Compile it:

  erik@o2:/tmp > g++ -Wall -c foo.cc -o foo.o 

No warnings at all, although I am actually losing resolution in the
assignment.

Shouldn't g++ issue a warning in the second case?


Erik

-- 
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031,  2600 GA Delft, The Netherlands
Phone: +31-15-2785859  Fax: +31-15-2781843  Email J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]