This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C/C++ PATCH] PR c++/66572. Fix Wlogical-op false positive
- From: Marek Polacek <polacek at redhat dot com>
- To: Mikhail Maltsev <maltsevm at gmail dot com>
- Cc: gcc-patches <gcc-patches at gnu dot org>, Jason Merrill <jason at redhat dot com>
- Date: Tue, 23 Jun 2015 21:49:29 +0200
- Subject: Re: [C/C++ PATCH] PR c++/66572. Fix Wlogical-op false positive
- Authentication-results: sourceware.org; auth=none
- References: <5584AD7E dot 7040603 at gmail dot com>
On Sat, Jun 20, 2015 at 03:02:06AM +0300, Mikhail Maltsev wrote:
> - /* We do not warn for constants because they are typical of macro
> - expansions that test for features. */
> - if (CONSTANT_CLASS_P (op_left) || CONSTANT_CLASS_P (op_right))
> + /* We do not warn for literal constants because they are typical of macro
> + expansions that test for features. Likewise, we do not warn for
> + const-qualified and constexpr variables which are initialized by constant
> + expressions, because they can come from e.g. <type_traits> or similar user
> + code. */
> + if (TREE_CONSTANT (op_left) || TREE_CONSTANT (op_right))
> return;
That looks wrong, because with TREE_CONSTANT we'd warn in C but not in C++
for the following:
const int a = 4;
void
f (void)
{
const int b = 4;
static const int c = 5;
if (a && a) {}
if (b && b) {}
if (c && c) {}
}
Note that const-qualified types are checked using TYPE_READONLY.
But I'm not even sure that the warning in the original testcase in the PR
is bogus; you won't get any warning when using e.g.
foo<unsigned, signed>();
in main().
Marek