tcbrindle / cpp17_headers

C++17 library facilities for older compilers
145 stars 27 forks source link

variant & optional mutually incompatible #2

Closed Kaosumaru closed 7 years ago

Kaosumaru commented 7 years ago

Both headers declare std::in_place_t.

tcbrindle commented 7 years ago

Hi, thanks for the bug report. I've committed a fix to master, would you mind giving it a try and seeing whether it's solved the issue for you?

tcbrindle commented 7 years ago

I'm going to go ahead and close this now, please let me know if you're still having problems.

cstoitner commented 7 years ago

With the current revision the guard in variant.hpp is not protecting all duplicate definitions. If variant.hpp is included after optional.hpp I get the following errors with clang 3.9.0:

In file included from test.cpp:38:
./cpp17_headers/include/stx/variant.hpp:102:27: error: redefinition of 'in_place_type_t'
template <class T> struct in_place_type_t {
                          ^
./cpp17_headers/include/stx/optional.hpp:288:27: note: previous definition is here
template <class T> struct in_place_type_t {
                          ^
In file included from test.cpp:38:
./cpp17_headers/include/stx/variant.hpp:106:30: error: redefinition of 'in_place_type'
constexpr in_place_type_t<T> in_place_type{};
                             ^
./cpp17_headers/include/stx/optional.hpp:300:30: note: previous definition is here
constexpr in_place_type_t<T> in_place_type{};
                             ^
In file included from test.cpp:38:
./cpp17_headers/include/stx/variant.hpp:108:28: error: redefinition of 'in_place_index_t'
template <size_t I> struct in_place_index_t {
                           ^
./cpp17_headers/include/stx/optional.hpp:293:28: note: previous definition is here
template <size_t I> struct in_place_index_t {
                           ^
In file included from test.cpp:38:
./cpp17_headers/include/stx/variant.hpp:112:31: error: redefinition of 'in_place_index'
constexpr in_place_index_t<I> in_place_index{};
                              ^
./cpp17_headers/include/stx/optional.hpp:302:31: note: previous definition is here
constexpr in_place_index_t<I> in_place_index{};

Everything works fine when variant.hpp is included first.

cstoitner commented 7 years ago

The errors above are with '#define STX_NO_STD_OPTIONAL' and '#define STX_NO_STD_VARIANT'. When your header picks up clangs 'experimental/optional' there are different conflicts with 'in_place_t' and 'in_place' no matter the order of the includes.