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

--- Comment #4 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
(In reply to Zeb Figura from comment #3)
> (In reply to Xi Ruoyao from comment #2)
> > (In reply to Xi Ruoyao from comment #1)
> > > The warning given for the reduced test case is correct because it does not
> > > make sense.  It should be just rewritten as
> > 
> > I mean, the code does not make sense.
> > 
> > And the warning is given exactly because GCC is optimizing the strcpy call
> > to unreachable.
> 
> If GetWindowsDirectoryA() was idempotent, and GetSystemDirectory16() had no
> other users, that might be true, but as it is I don't think so.
> 
> The pattern both of those functions call is, much like snprintf(), you pass
> a buffer and a size, and if the size is 0 then they'll return the size that
> would have been written if there was a large enough buffer. In that case the
> buffer can be NULL. In trying to reduce the test case down to the minimal
> possible complexity I obscured that fact, but regardless I don't think the
> reduced testcase is nonsensical.

Then that's why -Wnonnull is a warning, not an error.

Using -Werror is just telling the compiler "you can reject valid code", anyway.

Reply via email to