Looks like most of the difference can be accounted for by the fact that A
is not default constructible - which probably causes some more complicated
code in the standard library which the compiler isn't currently able to see
through. I haven't looked at the specifics of what that might be:
$ cat vec.cpp
#include
template
std::vector f()
{
std::vector a;
a.resize(1, 1);
return a;
}
class A
{
public:
long a;
*A() = default;*
A(long a) : a(a) {}
};
template std::vector f();
template std::vector f();
$ clang++-tot -O3 vec.cpp -c && nm vec.o --size-sort -Ctd
0079 W std::vector > f()
0079 W std::vector > f()
1802 W std::vector
>::_M_fill_insert(__gnu_cxx::__normal_iterator > >, unsigned long, A const&)
1898 W std::vector
>::_M_fill_insert(__gnu_cxx::__normal_iterator > >, unsigned long, long const&)
On Sun, Jan 10, 2021 at 11:11 AM Marcel Keller via cfe-users <
cfe-users@lists.llvm.org> wrote:
> Hi,
>
> When I compile the attached code, I find that one instantiation of
> vector::_M_fill_insert is double the size of the other even though the
> semantics should be the same:
>
> $ clang++ -O3 -g -c insert.cpp
> $ nm insert.o --size-sort -Ctd
> 0079 W std::vector > f()
> 0079 W std::vector > f()
> 1765 W std::vector
> >::_M_fill_insert(__gnu_cxx::__normal_iterator std::allocator > >, unsigned long, long const&)
> 3638 W std::vector
> >::_M_fill_insert(__gnu_cxx::__normal_iterator std::allocator > >, unsigned long, A const&)
>
> What is the reason for this? I would expect that a class trivially
> containing one member would be treated the same as just the member.
>
> I'm using clang 10 on Ubuntu 20.04.
>
> Best regards,
> Marcel
>
> ___
> cfe-users mailing list
> cfe-users@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
>
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users