mapbox / variant

C++11/C++14 Variant
BSD 3-Clause "New" or "Revised" License
371 stars 100 forks source link

Compilation problems with clang on windows #149

Closed usernameiwantedwasalreadytaken closed 7 years ago

usernameiwantedwasalreadytaken commented 7 years ago

I tried to compile this simple program with clang 3.8.0 on Windows 10 (using MSVC 2017 headers):

#include <iostream>
#include "mapbox/variant.hpp"

int main() {
  using namespace std;
  using myvar = mapbox::util::variant<int, double>;

  myvar m;

  cout << "ok" << endl;
  return 0;
}

But I've got the following errors:

C:\Tests\Cpp\variant>clang++ -std=c++14 -Ivariant/include main.cc
In file included from main.cc:2:
variant/include\mapbox/variant.hpp:599:44: error: no template named 'is_nothrow_default_constructible' in namespace
      'std'; did you mean 'has_nothrow_default_constructor'?
    VARIANT_INLINE variant() noexcept(std::is_nothrow_default_constructible<first_type>::value)
                                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                           has_nothrow_default_constructor
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\type_traits:1021:12: note:
      'has_nothrow_default_constructor' declared here
using tr1::has_nothrow_default_constructor;
           ^
In file included from main.cc:2:
variant/include\mapbox/variant.hpp:612:51: error: no template named 'is_nothrow_constructible' in namespace 'std'; did
      you mean 'has_nothrow_constructor'?
    VARIANT_INLINE variant(T&& val) noexcept(std::is_nothrow_constructible<typename Traits::target_type, T&&>::value)
                                             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
                                                  has_nothrow_constructor
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\type_traits:1018:12: note: 'has_nothrow_constructor'
      declared here
using tr1::has_nothrow_constructor;     // retained
           ^
In file included from main.cc:2:
variant/include\mapbox/variant.hpp:612:51: error: too many template arguments for class template
      'has_nothrow_constructor'
    VARIANT_INLINE variant(T&& val) noexcept(std::is_nothrow_constructible<typename Traits::target_type, T&&>::value)
                                                  ^                                                      ~~~~
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\type_traits:720:9: note: template is declared here
        struct has_nothrow_constructor _HAS_NOTHROW_CONSTRUCTOR(_Ty)
               ^
In file included from main.cc:2:
variant/include\mapbox/variant.hpp:625:43: error: no template named 'is_nothrow_move_constructible' in namespace 'std';
      did you mean 'has_nothrow_copy_constructor'?
        noexcept(detail::conjunction<std::is_nothrow_move_constructible<Types>...>::value)
                                     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                          has_nothrow_copy_constructor
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\type_traits:1020:12: note:
      'has_nothrow_copy_constructor' declared here
using tr1::has_nothrow_copy_constructor;
           ^
In file included from main.cc:2:
variant/include\mapbox/variant.hpp:583:19: error: static_assert expression is not an integral constant expression
    static_assert(sizeof...(Types) < std::numeric_limits<type_index_t>::max(), "Internal index type must be abl...
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cc:8:9: note: in instantiation of template class 'mapbox::util::variant<int, double>' requested here
  myvar m;
        ^
variant/include\mapbox/variant.hpp:583:38: note: non-constexpr function 'max' cannot be used in a constant expression
    static_assert(sizeof...(Types) < std::numeric_limits<type_index_t>::max(), "Internal index type must be abl...
                                     ^
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\limits:777:24: note: declared here
        static _Ty (__CRTDECL max)() _THROW0()
                              ^
5 errors generated.

Don't know if I'm doing something wrong...

usernameiwantedwasalreadytaken commented 7 years ago

I'm sorry. Clang was using the wrong headers (from MSVC 2010). I think that was the issue.

By the way, compiling with MSVC 2017 community everything works fine.

artemp commented 7 years ago

👍