From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11717 invoked by alias); 21 Aug 2008 21:51:36 -0000 Received: (qmail 11708 invoked by uid 22791); 21 Aug 2008 21:51:35 -0000 X-Spam-Check-By: sourceware.org Received: from web51809.mail.re2.yahoo.com (HELO web51809.mail.re2.yahoo.com) (206.190.38.240) by sourceware.org (qpsmtpd/0.31) with SMTP; Thu, 21 Aug 2008 21:50:53 +0000 Received: (qmail 27251 invoked by uid 60001); 21 Aug 2008 21:50:50 -0000 X-YMail-OSG: h4JX1BwVM1lUOHP7DNK36vF3g9tWm75tl60CXg5lnF.VbQozeteHlWWYHV6q18EdqruBsKkWpxezp_mKkhMtFjUrXhK2cGxzEDEGkMThBzhfxDR9EbFPF7KHGgfgoXsQAQ-- Received: from [207.42.203.5] by web51809.mail.re2.yahoo.com via HTTP; Thu, 21 Aug 2008 14:50:50 PDT X-Mailer: YahooMailWebService/0.7.218.2 Date: Fri, 22 Aug 2008 01:49:00 -0000 From: Andrew Frezell Reply-To: dfrezell@speakeasy.net Subject: Looking for a warning when casting 'const char *' to bool. To: gcc-help@gcc.gnu.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Message-ID: <662720.27082.qm@web51809.mail.re2.yahoo.com> Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2008-08/txt/msg00226.txt.bz2 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 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; }