silverqx / TinyORM

Modern C++ ORM library
https://www.tinyorm.org
MIT License
210 stars 22 forks source link

fatal error: reference to 'variant' is ambiguous #13

Closed JackDPro closed 1 year ago

JackDPro commented 1 year ago

Hello, I encountered an error while compiling TinyORM on my Mac. Could you please help me identify where the error occurred? WX20230606-155057@2x

xcode version is 'Xcode 14.3.1 Build version 14E300c'

silverqx commented 1 year ago

Hi, macOS isn't supported as I don't have any macOS so I can't test it.

What compiler and which version do you use? I assume it's the Apple Clang. Which c++ library this compiler uses, it's libstdc++ or libc++? I'm asking because I know nothing about macOS c++ dev. env.

SchaichAlonso commented 1 year ago

Hi,

I can reproduce this on FreeBSD, using clang++ and libc++

It's caused by the _LIBCPP_TEMPLATE_VIS macro used by std::variant as defined in <variant> to become

class __attribute__((__type_visibility__("default"))) variant;

while std::variant as defined in orm/ormconcepts.hpp:20 instead becomes

class __attribute__((__visibility__("hidden"))) variant;

where the hidden originates in the CXX_VISIBILITY_PRESET used by TinyORM.

Including <variant> instead of prototyping std::variant fixes this build failure.

silverqx commented 1 year ago

Are you able to compile it with libc++ because I don't support it, the reason is that I wasn't able to compile a simple hello world programs with c++2a two years ago.

I don't have any plans to add libc++ support in the near future, it will cost much more effort to add it correctly.

The problem is as you wrote, I agree with that.

Much better would be something like this:

namespace std
{
#if defined(_LIBCPP_VERSION) && defined(_LIBCPP_TEMPLATE_VIS)
    template<typename ...Types>
    class _LIBCPP_TEMPLATE_VIS variant; // NOLINT(bugprone-forwarding-reference-overload)
#else
    template<typename ...Types>
    class variant; // NOLINT(bugprone-forwarding-reference-overload)
#endif
} // namespace std

Can you try it if it compiles correctly? Thx

SchaichAlonso commented 1 year ago

Are you able to compile it with libc++ because I don't support it, the reason is that I wasn't able to compile a simple hello world programs with c++2a two years ago.

I don't have any plans to add libc++ support in the near future, it will cost much more effort to add it correctly.

The problem is as you wrote, I agree with that.

Much better would be something like this:

namespace std
{
#if defined(_LIBCPP_VERSION) && defined(_LIBCPP_TEMPLATE_VIS)
    template<typename ...Types>
    class _LIBCPP_TEMPLATE_VIS variant; // NOLINT(bugprone-forwarding-reference-overload)
#else
    template<typename ...Types>
    class variant; // NOLINT(bugprone-forwarding-reference-overload)
#endif
} // namespace std

Can you try it if it compiles correctly? Thx

It fails to compile, reproducing the same error the OP has.

silverqx commented 1 year ago

I should merge it much sooner, that forward declaration was not a good idea anyway. Is merged to develop now.