This is the mail archive of the gcc-bugs@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]
Other format: [Raw text]

[Bug c++/63431] New: implicit conversion changes value but no warning ?


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63431

            Bug ID: 63431
           Summary: implicit conversion changes value but no warning ?
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dcb314 at hotmail dot com

Given C++ source code

extern void g(int);

void f(int p1)
{
    int i;

       if (p1 >= 0)
        i = 0.01;
    else
        i = -0.02;

     g(i);
}

trunk 20141001 says nothing, even with provocation:

$ ~/gcc/results/bin/g++ -c -O2 -Wall -Wextra oct1a.cc
$

Here is clang being a bit more helpful:

$ clang++ -c -O2 -Wall -Wextra oct1a.cc
oct1a.cc:9:7: warning: implicit conversion from 'double' to 'int' changes value
      from 0.01 to 0 [-Wliteral-conversion]
                i = 0.01;
                  ~ ^~~~
oct1a.cc:11:8: warning: implicit conversion from 'double' to 'int' changes
value
      from 0.02 to 0 [-Wliteral-conversion]
                i = -0.02;
                  ~  ^~~~
2 warnings generated.
$

There are half a dozen examples of this in Fedora's current Linux source code.


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