This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C++ PATCH] Fix -Wlogical-not-parentheses (PR c++/62199)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]