This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/64524] gcc can't detect same expression in both parts of ternary operator
- From: "dcb314 at hotmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 07 Jan 2015 18:00:03 +0000
- Subject: [Bug c++/64524] gcc can't detect same expression in both parts of ternary operator
- Auto-submitted: auto-generated
- References: <bug-64524-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64524
--- Comment #2 from David Binderman <dcb314 at hotmail dot com> ---
(In reply to Jakub Jelinek from comment #1)
> Should it complain only when the expressions are the same (e.g. token-wise),
> or even when just two different expressions have the same value?
> I mean, say:
> enum X { E = 5, F = 5 };
> int i = cond ? E : F;
> int j = cond ? x + 3 : x + 2 + 1;
> int k = cond ? sizeof (x) : sizeof (y);
> etc.
All would be good ;->
I suspect token-wise comparison would be simple and cheap, so
suggest do that first. That would cover my example.
I suspect more complex would be making sure two compile time
constants have the same value, so suggest do that second.
That would cover cases i and k above.
Suspect case j would be more difficult, since it involves
expression comparison. Suggest leave till last.
Feel free to adjust the priority order if my guesses are wrong.