Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22118

Linker error with empty braces initialization

$
0
0

The following code compiles normally:

#include <iostream>
#include <map>
#include <string>

struct Config {
    std::map<std::string, std::string> info;
};

void f(const Config& = Config()) { }

int main() {
    f();
}

however, the following seems to produce a linker error on some compilers:

#include <iostream>
#include <map>
#include <string>

struct Config {
    std::map<std::string, std::string> info;
};

void f(const Config& = {}) { }

int main() {
    f();
}

On GCC on CentOS 7 (c++ (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)), it produces the following linker error:

/tmp/ccM1NXXc.o: In function `main':
test.cc:(.text+0x42): undefined reference to `std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<std::string const, std::string> > >::map()'
collect2: error: ld returned 1 exit status

On other platforms/compiler versions, it seems to work fine. Is this a compiler bug, and should the two codes work the same? (Should = {} initialization of Config result in default-construction of the std::map?)


Viewing all articles
Browse latest Browse all 22118

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>