Jason Merrill wrote: > On 09/15/2014 11:21 AM, Ulrich Weigand wrote: > > Jakub Jelinek wrote: > >> On Tue, Jun 10, 2014 at 07:37:50PM +0200, Ulrich Weigand wrote: > >>> the following C++ test case: > >>> > >>> struct pollfd > >>> { > >>> int fd; > >>> short int events; > >>> short int revents; > >>> }; > >>> > >>> struct Pollfd : public pollfd { }; > >>> > >>> struct Pollfd myfd[10]; > >>> > >>> int test (void) > >>> { > >>> return __builtin_object_size ((struct pollfd *)myfd, 1); > >>> } > >>> > >>> ends up returning 8 from the "test" routine, not 80. > > This example strikes me as strange. Why do you expect the size of a > pointer to the base class subobject to give a meaningful answer, any > more than taking the address of a data member?
Well, it's a test case simplified from a real-world example. To quote the original mail at the start of this thread: >In the real-world application this test case was extracted from, >this causes a call: > > poll(myfd, count, 0); // 1 < count < 10 > >to fail with a "Buffer overflow detected" message at run-time >when building with _FORTIFY_SOURCE = 2 against glibc. [ Here, >there is no explicit cast, but it is implied by the prototype >of the "poll" routine. ] > >(Note that in the real-world application, the derived struct Pollfd >has some member functions to construct and pretty-print the structure, >but has no additional data members.) (https://gcc.gnu.org/ml/gcc/2014-06/msg00116.html) Thanks, Ulrich -- Dr. Ulrich Weigand GNU/Linux compilers and toolchain ulrich.weig...@de.ibm.com