[Bug c++/71472] Wlogical-op misses exhaustive-or case (... || A) || B

2016-06-10 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71472

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org,
   ||mpolacek at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek  ---
That is because we do this warning only when building each single || or && or |
or &.
And, we do this during parsing, where we don't know yet if the current
expression will appear in yet another identical operation or not.
If we extend the current warn_logical_operator so that for the range tests
it recurses over identical code suboperands, then either we'd have to limit the
walk to fixed number of operands we check and punt if you have say over 30 ||
expressions, or we'd risk exponential compile time.
Another possibility might be to remove this part of warn_logical_operator, and
perform it later, e.g. during c_fully_fold* and cp_fold, where we should have
the whole expressions already built and somehow signal to the recursive calls
that we want to handle it only on the outermost ||/&&/|/& (i.e. not perform it
if the parent code is the same as current code).
Then we could detect even e != ENUM_A || i != 42 || e != ENUM_B.  Of course
for ||/&& we'd need to pay attention to side-effects in between,
e != ENUM_A || foo () || e != ENUM_B should not be warned about.
If we do that at that spot, we should basically try to virtually linearize the
trees combined with the same truth/logical binary operator, for all of them
perform the various checks warn_logical_operator does:
from_macro_expansion_at
TREE_NO_WARNING
CONSTANT_CLASS_P (fold_for_warn (...))
!(truth_value_p (TREE_CODE (...)) || INTEGRAL_TYPE_P (TREE_TYPE (...))
VECTOR_TYPE_P
make_range
build_range_check + integer_zerop (tem)
and stick the locations/make_range result/in*_p/low*/high* into a vector.
For operands with side-effects split the vector, then qsort each part without
side effects, so that we get records with the same make_range result next to
each other, and then perform the actual final checks and warnings.

[Bug c++/71472] Wlogical-op misses exhaustive-or case (... || A) || B

2016-06-09 Thread manu at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71472

Manuel López-Ibáñez  changed:

   What|Removed |Added

   Keywords||diagnostic
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2016-06-09
 CC||manu at gcc dot gnu.org
 Ever confirmed|0   |1

--- Comment #1 from Manuel López-Ibáñez  ---
I was sure there was a duplicate of this somewhere. Oh well...