diff options
author | dodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-11-03 10:44:36 +0000 |
---|---|---|
committer | dodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-11-03 10:44:36 +0000 |
commit | 64ed018c41cc01c9e1be29e767d2764ea1a01f69 (patch) | |
tree | c87dd211761661c2a4d2e74640e5d6de9bb6613b /gcc/testsuite/c-c++-common/dfp | |
parent | 19a64efc18e179f32cde45ad62aaef3d12c72e2e (diff) | |
download | gcc-64ed018c41cc01c9e1be29e767d2764ea1a01f69.tar.gz |
Fix PR c++/38699
gcc/ChangeLog:
PR c++/38699
* c-common.c (fold_offsetof_1): Issue errors when the
member designator of the offsetoff expression is not legitimate.
gcc/testsuite/ChangeLog:
* c-c++-common/dfp/builtin-offsetof.c: New test.
* g++.dg/other/offsetof6.C: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@153843 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/c-c++-common/dfp')
-rw-r--r-- | gcc/testsuite/c-c++-common/dfp/builtin-offsetof.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/gcc/testsuite/c-c++-common/dfp/builtin-offsetof.c b/gcc/testsuite/c-c++-common/dfp/builtin-offsetof.c new file mode 100644 index 00000000000..0ab498acd09 --- /dev/null +++ b/gcc/testsuite/c-c++-common/dfp/builtin-offsetof.c @@ -0,0 +1,29 @@ +// Contributed by Dodji Seketeli <dodji@redhat.com> +// Origin PR c++/38699 +// { dg-options "-Warray-bounds" } +// { dg-do compile } + +struct A +{ + const char *p; +}; + +struct B +{ + char p[10]; + struct A a; +}; + +void +f0 () +{ + __builtin_offsetof(struct A, p); // OK + __builtin_offsetof(struct A, p[0]); // { dg-error "non constant address" } + __builtin_offsetof(struct B, p[0]); // OK + __builtin_offsetof(struct B, p[9]); // OK + __builtin_offsetof(struct B, p[10]); // { dg-warning "greater than size" } + __builtin_offsetof(struct B, a.p); // OK + __builtin_offsetof(struct B, p[0]); // OK + __builtin_offsetof(struct B, a.p[0]); // { dg-error "non constant address" } +} + |