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

Differences in symbol export between gcc and msvc for implictely define constructors

$
0
0

I have a class Bar which holds a vector of a non-copyable class Foo:

struct  Foo {    Foo(int &a) : m_a(a){}    int &m_a;};struct CORE_EXPORT Bar {    std::vector<Foo> f;};

When I compile this code with GCC with -fvisibility=hidden and marking Bar as visibility default, it compiles fine.

However, when I compile this same code with MSVC, marking Bar with __declspec(dllexport), I get a compilation error due to deleted Foo::operator=.

I understand this is happening because under the hood, MSVC is generating a copy constructor for Bar and exporting it, which results in trying to use a copy constructor for Foo.

If I don't mark Bar as __declspec(dllexport), the code compiles fine.

Here is a complete example in godbolt: https://godbolt.org/z/hshddaz5z

Why is this behavior different? Which implicitly defined symbols does MSVC export that GCC doesn't?


Viewing all articles
Browse latest Browse all 22230

Trending Articles



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