Std :: any via shared library restricting mingw

I came across a problem when using libstdc ++ std :: any implementation with mingw across the border of a shared library. It creates std::bad_any_castwhere it clearly does not follow (I suppose).

I am using mingw-w64, gcc-7 and compiling code with -std = C ++ 1z.

Simplified code:

main.cpp:

#include <any>
#include <string>

// prototype from lib.cpp
void do_stuff_with_any(const std::any& obj);

int main()
{
    do_stuff_with_any(std::string{"Hello World"});
}

lib.cpp:

It will be compiled into a shared library and linked to the executable from main.cpp.

#include <any>
#include <iostream>

void do_stuff_with_any(const std::any& obj)
{
    std::cout << std::any_cast<const std::string&>(obj) << "\n";
}

std:: bad_any_cast, , do_stuff_with_any, . gcc , -, - (, ), , - , , -, .

std:: any ? UB -? gcc? , Linux, mingw? , -, ? () ?

+4

Source: https://habr.com/ru/post/1682164/


All Articles