This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/85311] New: const& aggregate parameter with empty default brace initializer results in undefined references to std containers
- From: "vishal at royal-caliber dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 10 Apr 2018 06:30:05 +0000
- Subject: [Bug c++/85311] New: const& aggregate parameter with empty default brace initializer results in undefined references to std containers
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85311
Bug ID: 85311
Summary: const& aggregate parameter with empty default brace
initializer results in undefined references to std
containers
Product: gcc
Version: 7.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: vishal@royal-caliber.com
Target Milestone: ---
Created attachment 43890
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43890&action=edit
preprocessed output
Hello,
The following code fails to link:
----------test.cpp------------------
#include <vector>
struct Foo
{
std::vector<int> x;
};
void foo(const Foo& = {})
{
}
int main()
{
foo();
}
-----------------------------------
$ g++ test.cpp
/tmp/ccJsJY1c.o: In function `main':
test.cpp:(.text+0x2a): undefined reference to `std::vector<int,
std::allocator<int> >::vector()'
collect2: error: ld returned 1 exit status
The problem is triggered by the default value for the parameter to foo(). It
can be avoided by either changing the prototype of foo() to not have a default
value, or by actually providing a value in the call to foo().
The same behavior occurs with several other std containers inside the aggregate
such as deque and list. It can be reproduced in gcc versions 6.4.0, 7.2.0 and
7.3.0 and libstdc++ versions 6.0.22 and 6.0.24.
The preprocessed file is attached. The output of g++ -v follows.
Thank you,
Vishal
Output of "g++-7.3 -v -save-temps test.cpp"
Using built-in specs.
COLLECT_GCC=g++-7.3
COLLECT_LTO_WRAPPER=/home/vishal/localbuild/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --enable-languages=c,c++
--prefix=/home/vishal/localbuild --program-suffix=-7.3 --disable-multilib
Thread model: posix
gcc version 7.3.0 (GCC)
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic'
'-march=x86-64'
/home/vishal/localbuild/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/cc1plus -E
-quiet -v -D_GNU_SOURCE test.cpp -mtune=generic -march=x86-64 -fpch-preprocess
-o test.ii
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory
"/home/vishal/localbuild/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../x86_64-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/home/vishal/localbuild/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0
/home/vishal/localbuild/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/x86_64-pc-linux-gnu
/home/vishal/localbuild/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/backward
/home/vishal/localbuild/lib/gcc/x86_64-pc-linux-gnu/7.3.0/include
/home/vishal/localbuild/include
/home/vishal/localbuild/lib/gcc/x86_64-pc-linux-gnu/7.3.0/include-fixed
/usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic'
'-march=x86-64'
/home/vishal/localbuild/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/cc1plus
-fpreprocessed test.ii -quiet -dumpbase test.cpp -mtune=generic -march=x86-64
-auxbase test -version -o test.s
GNU C++14 (GCC) version 7.3.0 (x86_64-pc-linux-gnu)
compiled by GNU C version 7.3.0, GMP version 6.1.0, MPFR version
3.1.3-p4, MPC version 1.0.2, isl version none
warning: GMP header version 6.1.0 differs from library version 6.1.2.
warning: MPFR header version 3.1.3-p4 differs from library version 3.1.6.
warning: MPC header version 1.0.2 differs from library version 1.0.3.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++14 (GCC) version 7.3.0 (x86_64-pc-linux-gnu)
compiled by GNU C version 7.3.0, GMP version 6.1.0, MPFR version
3.1.3-p4, MPC version 1.0.2, isl version none
warning: GMP header version 6.1.0 differs from library version 6.1.2.
warning: MPFR header version 3.1.3-p4 differs from library version 3.1.6.
warning: MPC header version 1.0.2 differs from library version 1.0.3.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: e93c907a87f28f1e65d001f94ea5afa5
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic'
'-march=x86-64'
as -v --64 -o test.o test.s
GNU assembler version 2.29.1 (x86_64-pc-linux-gnu) using BFD version (Gentoo
2.29.1 p3) 2.29.1
COMPILER_PATH=/home/vishal/localbuild/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/:/home/vishal/localbuild/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/:/home/vishal/localbuild/libexec/gcc/x86_64-pc-linux-gnu/:/home/vishal/localbuild/lib/gcc/x86_64-pc-linux-gnu/7.3.0/:/home/vishal/localbuild/lib/gcc/x86_64-pc-linux-gnu/
LIBRARY_PATH=/home/vishal/localbuild/lib/gcc/x86_64-pc-linux-gnu/7.3.0/:/home/vishal/localbuild/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/home/vishal/localbuild/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic'
'-march=x86-64'
/home/vishal/localbuild/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/collect2 -plugin
/home/vishal/localbuild/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/liblto_plugin.so
-plugin-opt=/home/vishal/localbuild/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/lto-wrapper
-plugin-opt=-fresolution=test.res -plugin-opt=-pass-through=-lgcc_s
-plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc
-plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc
--eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2
/usr/lib/../lib64/crt1.o /usr/lib/../lib64/crti.o
/home/vishal/localbuild/lib/gcc/x86_64-pc-linux-gnu/7.3.0/crtbegin.o
-L/home/vishal/localbuild/lib/gcc/x86_64-pc-linux-gnu/7.3.0
-L/home/vishal/localbuild/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../lib64
-L/lib/../lib64 -L/usr/lib/../lib64
-L/home/vishal/localbuild/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../.. test.o
-lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/home/vishal/localbuild/lib/gcc/x86_64-pc-linux-gnu/7.3.0/crtend.o
/usr/lib/../lib64/crtn.o
test.o: In function `main':
test.cpp:(.text+0x1b): undefined reference to `std::vector<int,
std::allocator<int> >::vector()'
collect2: error: ld returned 1 exit status