Menu

clang's Wliteral-conversion

dcb
2015-11-24
2015-11-24
  • dcb

    dcb - 2015-11-24

    define THIS 0.01

    define THAT -0.02

    extern void g(int);

    void f(int p1)
    {
    int i;

    if (p1 >= 0)
        i = THIS;
    else
        i = THAT;
    
    g(i);
    

    }

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

     
  • Daniel Marjamäki

    I don't think this is a good idea. If you want to truncate the value then you assign it. then there is noise.

    as an addon or rule I can live with it.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.