This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C/C++ PATCH] RFC: Implement -Wduplicated-cond (PR c/64249) (take
- From: Manuel LÃpez-IbÃÃez <lopezibanez at gmail dot com>
- To: Martin Sebor <msebor at gmail dot com>, Marek Polacek <polacek at redhat dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Jason Merrill <jason at redhat dot com>, Joseph Myers <joseph at codesourcery dot com>
- Date: Fri, 18 Sep 2015 20:16:52 +0200
- Subject: Re: [C/C++ PATCH] RFC: Implement -Wduplicated-cond (PR c/64249) (take
- Authentication-results: sourceware.org; auth=none
- References: <20150918134434 dot GG27588 at redhat dot com> <55FC3FAD dot 4010501 at gmail dot com>
On 18/09/15 18:45, Martin Sebor wrote:
but it makes me wonder how common this pattern is in portable
code and whether adding workarounds for it is the right solution
(or if it might prompt people to disable the warning, which would
be a shame).
Perhaps if we are going to warn, we could look for sizeof() and virtual
locations in the operands, and skip the warning. It would be nice to find a
heuristic that allows warning in most cases but skip those that appear often in
common code.
Another alternative is to have a more heuristic version of operand_equal(), if
two operands are equal because of "compilation-dependent" code (macro
expansion, sizeof, etc), then they are not considered equal. that is
operand_equal_2(sizeof(long), sizeof(long)) returns true, but
operand_equal_2(8, sizeof(long)) returns false.
I have no idea whether it is possible to implement operand_equal_2 in a sane way.
Cheers,
Manuel.