https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88895

--- Comment #8 from Martin Sebor <msebor at gcc dot gnu.org> ---
I agree that GCC would do a better by running -Wshift-count-overflow later (but
that carries a risk of false positives as well).  That's also why I
acknowledged the report.

Both solutions appear to be optimized equally well.  The recursive approach
doesn't trigger the warning because it avoids the invalid shifts.  It starts
recursion at the point where sizeof (int) == 4 and not when sizeof (int) == 8
as the test case, and scales to integers of any size.  It does exactly as much
work as is necessary for the type it's instantiated on.  I didn't show it so
much as a workaround but rather as a better way to code it.

Reply via email to