https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108939
Bug ID: 108939
Summary: -Wstringop-truncation warning when -fsanitize=address,
-O2 and -std=c++11 are used
Product: gcc
Version: 10.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: bezkrovatki at gmail dot com
Target Milestone: ---
GCC 10 and 11 emit the -Wstringop-truncation warning on the following
simplified sample ====
#include <string.h>
#define LEN 32
int main()
{
char dest[LEN];
char src[LEN];
strncpy(dest, src, LEN);
dest[LEN-1]=0;
return 0;
}
====
... when compiling with the following flags
g++ -fsanitize=address -std=c++11 -Werror -Wstringop-truncation -O2
The issue is not reproducible in any of the following cases:
- GCC 9 or earlier is used;
- GCC 12 or later is used;
- the option -fsanitize=address is omitted;
- the option -O2 is omitted;
- the option -std=c++11 is omitted or replaced with -std=gnu++11.