diff options
Diffstat (limited to 'gcc/testsuite/g++.dg/ext/strncpy-chk1.C')
-rw-r--r-- | gcc/testsuite/g++.dg/ext/strncpy-chk1.C | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/ext/strncpy-chk1.C b/gcc/testsuite/g++.dg/ext/strncpy-chk1.C new file mode 100644 index 00000000000..7770ba93127 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/strncpy-chk1.C @@ -0,0 +1,31 @@ +// PR c++/40502 +// { dg-do compile } +// { dg-options "-O2" } + +struct A { char x[12], y[35]; }; +struct B { char z[50]; }; + +inline void +foo (char *dest, const char *__restrict src, __SIZE_TYPE__ n) +{ + __builtin___strncpy_chk (dest, src, n, __builtin_object_size (dest, 0)); // { dg-warning "will always overflow" } +} + +void bar (const char *, int); + +inline void +baz (int i) +{ + char s[128], t[32]; + bar (s, 0); + bar (t, i); + A a; + B b; + foo (a.y, b.z, 36); +} + +void +test () +{ + baz (0); +} |