http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56785
Bug #: 56785
Summary: std::tuple of two elements does not apply empty base
class optimization when one of its elements is a
std::tuple with two elements
Classification: Unclassified
Product: gcc
Version: 4.7.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
AssignedTo: [email protected]
ReportedBy: [email protected]
#include <tuple>
class Empty {
};
int main() {
static_assert(sizeof(std::tuple<Empty, std::tuple<int, int>>) ==
sizeof(std::tuple<int, int>), "Too big");
}
[david@localhost test]$ g++ source/test.cpp -std=c++11 -Wall -Wextra -pedantic
source/test.cpp: In function ‘int main()’:
source/test.cpp:23:2: error: static assertion failed: Too big
The static_assert does not fail if I change it to be a std::tuple<int, int,
int> on both sides, however, or any number of int other than exactly 2. I also
get this bug regardless of the type in the std::tuple (for instance, my own
class type).
Therefore, I have created a workaround, demonstrated such:
#include <tuple>
class Empty {
};
class Empty2 {
};
int main() {
static_assert(sizeof(std::tuple<Empty, std::tuple<int, short>, Empty2>) ==
sizeof(std::tuple<int, short, Empty2>), "Too big");
static_assert(sizeof(std::tuple<Empty, std::tuple<int, int>, Empty2>) ==
sizeof(int) * 2, "Too big");
}
[david@localhost test]$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.7.2/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla
--enable-bootstrap --enable-shared --enable-threads=posix
--enable-checking=release --disable-build-with-cxx
--disable-build-poststage1-with-cxx --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-gnu-unique-object
--enable-linker-build-id --with-linker-hash-style=gnu
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin
--enable-initfini-array --enable-java-awt=gtk --disable-dssi
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre
--enable-libgcj-multifile --enable-java-maintainer-mode
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib
--with-ppl --with-cloog --with-tune=generic --with-arch_32=i686
--build=x86_64-redhat-linux
Thread model: posix
gcc version 4.7.2 20121109 (Red Hat 4.7.2-8) (GCC)