On Tue, Mar 15, 2016 at 5:25 PM, Joseph Myers <jos...@codesourcery.com> wrote: > On Tue, 15 Mar 2016, H.J. Lu wrote: > >> On Tue, Mar 15, 2016 at 3:34 PM, Joseph Myers <jos...@codesourcery.com> >> wrote: >> > On Tue, 15 Mar 2016, H.J. Lu wrote: >> > >> >> On Tue, Mar 15, 2016 at 2:39 PM, Joseph Myers <jos...@codesourcery.com> >> >> wrote: >> >> > I'm not sure if the zero-size arrays (a GNU extension) are considered to >> >> > make a struct non-empty, but in any case I think the tests should cover >> >> > such arrays as elements of structs. >> >> >> >> There are couple tests for structs with members of array >> >> of empty types. testsuite/g++.dg/abi/empty14.h has >> > >> > My concern is the other way round - structs with elements such as >> > "int a[0];", an array [0] of a nonempty type. My reading of the subobject >> > definition is that such an array should not cause the struct to be >> > considered nonempty (it doesn't result in any int subobjects). >> >> This is a test for struct with zero-size array, which isn't treated >> as empty type. C++ and C are compatible in its passing. > > Where is the current definition of empty types you're proposing for use in > GCC? Is the behavior of this case clear from that definition?
https://gcc.gnu.org/ml/gcc/2016-03/msg00071.html Jason's patch follows it. Here is a test for struct with zero-size array of empty type, which is treated as empty type. -- H.J.
From 222c8fcf6518b8689ead18516ce49ba71a1c0a49 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" <hjl.to...@gmail.com> Date: Tue, 15 Mar 2016 19:14:30 -0700 Subject: [PATCH] Add a test for struct with zero-size array of empty type --- gcc/testsuite/g++.dg/abi/empty19.C | 17 +++++++++++++++++ gcc/testsuite/g++.dg/abi/empty19.h | 10 ++++++++++ gcc/testsuite/g++.dg/abi/empty19a.c | 6 ++++++ 3 files changed, 33 insertions(+) create mode 100644 gcc/testsuite/g++.dg/abi/empty19.C create mode 100644 gcc/testsuite/g++.dg/abi/empty19.h create mode 100644 gcc/testsuite/g++.dg/abi/empty19a.c diff --git a/gcc/testsuite/g++.dg/abi/empty19.C b/gcc/testsuite/g++.dg/abi/empty19.C new file mode 100644 index 0000000..489eb3a --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/empty19.C @@ -0,0 +1,17 @@ +// PR c++/60336 +// { dg-do run } +// { dg-options "-Wabi=9 -x c" } +// { dg-additional-sources "empty14a.c" } +// { dg-prune-output "command line option" } + +#include "empty19.h" +extern "C" void fun(struct dummy, struct foo); + +int main() +{ + struct dummy d; + struct foo f = { -1, -2, -3, -4, -5 }; + + fun(d, f); // { dg-warning "empty" } + return 0; +} diff --git a/gcc/testsuite/g++.dg/abi/empty19.h b/gcc/testsuite/g++.dg/abi/empty19.h new file mode 100644 index 0000000..616b87b --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/empty19.h @@ -0,0 +1,10 @@ +struct dummy0 { }; +struct dummy { struct dummy0 d[0]; }; +struct foo +{ + int i1; + int i2; + int i3; + int i4; + int i5; +}; diff --git a/gcc/testsuite/g++.dg/abi/empty19a.c b/gcc/testsuite/g++.dg/abi/empty19a.c new file mode 100644 index 0000000..767b1eb --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/empty19a.c @@ -0,0 +1,6 @@ +#include "empty19.h" +void fun(struct dummy d, struct foo f) +{ + if (f.i1 != -1) + __builtin_abort(); +} -- 2.5.0