[PATCH] string: Fix GCC 11 `-Werror=stringop-overread' error

Joseph Myers joseph@codesourcery.com
Tue Sep 1 17:37:59 GMT 2020


On Mon, 31 Aug 2020, Maciej W. Rozycki via Libc-alpha wrote:

>  Umm, I never used this feature before and got confused with the version 
> mismatch (7 vs 8) right above:
> 
> #if __GNUC_PREREQ (7, 0)
>   DIAG_IGNORE_NEEDS_COMMENT (8, "-Wstringop-overflow=");
> #endif
> 
> misleading me into thinking GCC 7 is the version that introduced the 
> `_Pragma' feature we use here.
> 
>  Joseph: has the mismatch been intentional?

All GCC versions supported for building glibc support the relevant pragma.  
However, the pragma gives an error if the -W option named isn't supported 
in the GCC version being used, so __GNUC_PREREQ conditionals are needed 
around uses of the pragma with options not present in the minimum GCC 
version for building glibc (currently GCC 6).

The version number in the macro call is ignored by the macro and is only 
for human readers.  It indicates the *most recent* GCC version with which 
the warning has been observed, and is intended as a hint that a particular 
use of the pragma might be obsolete, if the version named is older than 
the oldest GCC version still supported for building glibc - but actually 
determining whether it is obsolete would require removing the pragma and 
trying building with that GCC version.

That number is more relevant where the pragma is working around a GCC bug, 
and thus might well not be needed with newer GCC, than where the code 
(typically a testcase) is deliberately doing something that is 
deliberately warned about (which is common for tests of various corner 
cases) and thus the warning is not expected to disappear with newer GCC.

-- 
Joseph S. Myers
joseph@codesourcery.com


More information about the Libc-alpha mailing list