Looking for a warning when casting 'const char *' to bool.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello all,

I've done some searching and haven't found the right flag to issue a warning in the following scenario.  When passing a 'const char *' to an overloaded function that takes either a 'char *' or bool, the compiler is casting the 'const char *' to a bool and no warning is issued with the following flags: -Wall -Wextra -pedantic.  I tried a mix of a bunch of other warning flags and no success.  Is there a way for g++ to issue a warning in this case?  Below is example code

I know what the correct thing to do is, provide another overloaded function that takes a 'const char *', but this is an existing code base of millions of lines of code and I would like to find anything lurking through a warning.

Thanks,

Drew

// Start example

#include <iostream>

using namespace std;

class Foo {
public:
    void Test(char *c, bool b);
    void Test(char *c1, char *c2);
};

inline void Foo::Test(char *c, bool b) {
    cout << __PRETTY_FUNCTION__ << endl;
    cout << "c = " << c << endl;
    cout << "b = " << b << endl;
}

inline void Foo::Test(char *c1, char *c2) {
    cout << __PRETTY_FUNCTION__ << endl;
    cout << "c1 = " << c1 << endl;
    cout << "c2 = " << c2 << endl;
}

int main(int argc, char *argv[]) {
    char *c1 = "first arg";
    const char *c2 = "second arg";
    Foo f;

    f.Test(c1, c2);

    return 0;
}


      

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux