This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ PATCH] Fix -Wlogical-not-parentheses (PR c++/62199)
- From: Marc Glisse <marc dot glisse at inria dot fr>
- To: Jason Merrill <jason at redhat dot com>
- Cc: Marek Polacek <polacek at redhat dot com>, Paolo Carlini <paolo dot carlini at oracle dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 27 Sep 2014 14:09:00 +0200 (CEST)
- Subject: Re: [C++ PATCH] Fix -Wlogical-not-parentheses (PR c++/62199)
- Authentication-results: sourceware.org; auth=none
- References: <20140820200252 dot GO14320 at redhat dot com> <53F50CE0 dot 5010305 at redhat dot com> <20140821154125 dot GS14320 at redhat dot com> <53F63BCE dot 4050006 at redhat dot com> <20140822144848 dot GB15033 at redhat dot com> <53F75981 dot 3020401 at oracle dot com> <20140822155914 dot GD15033 at redhat dot com> <53F76EB0 dot 7000507 at redhat dot com> <20140822163357 dot GE15033 at redhat dot com> <53F77563 dot 30301 at redhat dot com> <20140822184532 dot GF15033 at redhat dot com> <alpine dot DEB dot 2 dot 11 dot 1408222117270 dot 1586 at laptop-mg dot saclay dot inria dot fr> <53F79AB4 dot 6030307 at redhat dot com> <alpine dot DEB dot 2 dot 11 dot 1408222138270 dot 6760 at laptop-mg dot saclay dot inria dot fr>
On Fri, 22 Aug 2014, Marc Glisse wrote:
On Fri, 22 Aug 2014, Jason Merrill wrote:
On 08/22/2014 03:24 PM, Marc Glisse wrote:
Note that there is a patch waiting for a review that makes us accept !v
for vector v:
Ah, indeed. I still think we might as well treat vectors the same as other
types here.
Ok, now that it is a conscious choice, it feels much safer :-)
Though depending on where exactly this is called, it would be funny if we
warned for !v==-1 but not for !v==true, when the possible values for the
elements of !v are actually {-1,0}. I guess I'll have to test after Marek
commits.
Sadly, this is exactly what is happening. With my patch,
typedef int veci __attribute__ ((vector_size (4 * sizeof (int))));
void f (veci *a)
{
*a = !*a == -1;
}
warning: logical not is only applied to the left hand side of comparison
I also get the warning if I replace -1 with 0 or with a vector, but not
with true. This seems like the reverse of what is desirable.
I don't see how to change that, the warning is super-early (it warns for
templates that are not instantiated) and we may not know yet if the lhs is
a vector.
I guess people using vectors in such a strange construct can just always
add parentheses, and it should be rare that anyone writes !vec==true and
thus misses a useful warning.
--
Marc Glisse