From: Andrew Frezell <frezeal@yahoo.com>
To: gcc-help@gcc.gnu.org
Subject: Looking for a warning when casting 'const char *' to bool.
Date: Fri, 22 Aug 2008 01:49:00 -0000 [thread overview]
Message-ID: <662720.27082.qm@web51809.mail.re2.yahoo.com> (raw)
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;
}
next reply other threads:[~2008-08-21 21:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-22 1:49 Andrew Frezell [this message]
2008-08-22 11:22 ` Eljay Love-Jensen
2008-08-23 2:02 ` corey taylor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=662720.27082.qm@web51809.mail.re2.yahoo.com \
--to=frezeal@yahoo.com \
--cc=dfrezell@speakeasy.net \
--cc=gcc-help@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).