This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/39981] zero-size base class optimization fails in certain scenarios
- From: "navinkumar+bugs at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 9 Nov 2009 17:35:23 -0000
- Subject: [Bug c++/39981] zero-size base class optimization fails in certain scenarios
- References: <bug-39981-17658@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #7 from navinkumar+bugs at gmail dot com 2009-11-09 17:35 -------
(From update of attachment 18986)
>#include <iostream>
>#include <stdint.h>
>#include <tuple>
>#include <type_traits>
>
>struct empty_t {
> template <typename Arg>
> explicit empty_t(Arg arg) { }
>};
>
>template <int N, class T>
>struct EmptyWrapperA {
> template <typename Arg>
> explicit EmptyWrapperA(Arg arg) { }
> static_assert(std::is_empty<T>::value, "sanity check");
>};
>
>template <int N, class T>
>struct EmptyWrapperB : T {
> template <typename Arg>
> explicit EmptyWrapperB(Arg arg) : T(arg) { }
> static_assert(std::is_empty<T>::value, "sanity check");
>};
>
>template <int N, typename T>
>struct Member {
> T m_value;
> template <typename Arg>
> explicit Member(Arg arg) : m_value(arg) { }
>};
>
>typedef EmptyWrapperA<0,empty_t> _0_emptyA; typedef EmptyWrapperB<0,empty_t> _0_emptyB;
>typedef Member<1,int> _1_member;
>typedef EmptyWrapperA<2,empty_t> _2_emptyA; typedef EmptyWrapperB<2,empty_t> _2_emptyB;
>
>static_assert(std::is_empty<_0_emptyA>::value, "sanity check");
>static_assert(std::is_empty<_0_emptyB>::value, "sanity check");
>static_assert(std::is_empty<_2_emptyA>::value, "sanity check");
>static_assert(std::is_empty<_2_emptyB>::value, "sanity check");
>class compositeA1 : _0_emptyA, _1_member, _2_emptyA { };
>class compositeA2 : _0_emptyA, _1_member { };
>class compositeB1 : _0_emptyB, _1_member { };
>class compositeB2 : _0_emptyB, _1_member, _2_emptyB { };
>class compositeB3 : _1_member, _2_emptyB { };
>
>int main(int argc, char** argv) {
> // output *should* be 4 since "int" is the only data member
> // something is wrong with GCC's zero-size base class optimization for compositeB1
> std::cout << "sizeA1: " << sizeof(compositeA1) << std::endl; // outputs 4
> std::cout << "sizeA2: " << sizeof(compositeA2) << std::endl; // outputs 4
> std::cout << "sizeB1: " << sizeof(compositeB1) << std::endl; // outputs 4
> std::cout << "sizeB2: " << sizeof(compositeB2) << std::endl; // outputs 8
> std::cout << "sizeB3: " << sizeof(compositeB3) << std::endl; // outputs 4
> return 0;
>}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39981