diff options
author | Martin Sebor <msebor@redhat.com> | 2019-11-03 22:11:37 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2019-11-03 15:11:37 -0700 |
commit | 4bcd578ab4927bc42b72b66d6d4d816ae5598ae7 (patch) | |
tree | 5374b29ae13c3a7051cbd48e75df3457ad8e7969 /gcc | |
parent | ac6f2e594886e2209446114023ecdff96b0bd7c4 (diff) | |
download | gcc-4bcd578ab4927bc42b72b66d6d4d816ae5598ae7.zip gcc-4bcd578ab4927bc42b72b66d6d4d816ae5598ae7.tar.gz gcc-4bcd578ab4927bc42b72b66d6d4d816ae5598ae7.tar.bz2 |
PR c++/88565 - enhance -Warray-bounds for C++ trailing class member arrays
gcc/testsuite/ChangeLog:
* g++.dg/warn/Warray-bounds-9.C: New test.
From-SVN: r277758
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/Warray-bounds-9.C | 81 |
2 files changed, 86 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e0e8c9e..13acfbb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-11-03 Martin Sebor <msebor@redhat.com> + + PR c++/88565 + * g++.dg/warn/Warray-bounds-9.C: New test. + 2019-11-02 Paolo Carlini <paolo.carlini@oracle.com> * g++.dg/conversion/ptrmem9.C: Check location. diff --git a/gcc/testsuite/g++.dg/warn/Warray-bounds-9.C b/gcc/testsuite/g++.dg/warn/Warray-bounds-9.C new file mode 100644 index 0000000..1912a0d --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Warray-bounds-9.C @@ -0,0 +1,81 @@ +/* PR c++/88565 - enhance -Warray-bounds for C++ trailing class member arrays + { dg-do compile } + { dg-options "-O2 -Wall" } */ + +struct S0 +{ + S0 (); + + int f (); + + int a[0]; +}; + +int S0::f () +{ + // The following is not diagnosed but should be in a class with a ctor. + return a[0]; // { dg-warning "\\\[-Warray-bounds" "pr88565" { xfail *-*-* } } +} + + +struct S1 +{ + S1 (); + + int f (); + + int a[1]; +}; + +int S1::f () +{ + // The following is only diagnosed with -Warray-bounds=2 but should + // be even at level 1 in a call with a ctor. + return a[1]; // { dg-warning "\\\[-Warray-bounds" "pr88565" { xfail *-*-* } } +} + + +struct S2 +{ + S2 (); + + int f (); + + int a[2]; +}; + +int S2::f () +{ + return a[2]; // { dg-warning "\\\[-Warray-bounds" } +} + + +struct S3 +{ + S3 (); + + int f (); + + int a[3]; +}; + +int S3::f () +{ + return a[3]; // { dg-warning "\\\[-Warray-bounds" } +} + + +struct Sx +{ + Sx (); + + int f (); + + int n, a[]; +}; + +int Sx::f () +{ + // The following is not diagnosed but should be in a class with a ctor. + return a[0]; // { dg-warning "\\\[-Warray-bounds" "pr88565" { xfail *-*-* } } +} |