jamboree / bustache

C++20 implementation of {{ mustache }}
82 stars 10 forks source link

Compilation error with C++17 variant conflict #11

Closed sjoubert closed 6 years ago

sjoubert commented 6 years ago

The following example fails to compile if C++17 is active and its std::variant is included. This issue is that the visit call inside bustache are resolved to std::visit instead of bustache::visit.

$ cat main.cpp
#include <bustache/generate/string.hpp>
#include <unordered_map>
#include <variant>

int main()
{
  std::string out;
  bustache::generate_string(out, bustache::format{}, bustache::object{}, std::unordered_map<std::string, bustache::format>{}, bustache::normal);
}

$ clang++ main.cpp -lbustache -std=c++17
In file included from main.cpp:1:
In file included from /usr/include/bustache/generate/string.hpp:12:
In file included from /usr/include/bustache/generate.hpp:10:
In file included from /usr/include/bustache/model.hpp:10:
In file included from /usr/include/bustache/format.hpp:10:
In file included from /usr/include/bustache/ast.hpp:12:
In file included from /usr/include/boost/unordered_map.hpp:17:
In file included from /usr/include/boost/unordered/unordered_map.hpp:18:
In file included from /usr/include/boost/functional/hash.hpp:6:
In file included from /usr/include/boost/container_hash/hash.hpp:114:
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/variant:1386:23: error: no member named 'valueless_by_exception' in 'bustache::ast::content'
      if ((__variants.valueless_by_exception() || ...))
           ~~~~~~~~~~ ^
/usr/include/bustache/generate.hpp:567:13: note: in instantiation of function template specialization
      'std::visit<bustache::detail::content_visitor<bustache::detail::string_sink<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >,
      std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bustache::format, std::hash<std::__cxx11::string>,
      std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::__cxx11::basic_string<char,
      std::char_traits<char>, std::allocator<char> >, bustache::format> > >, bustache::default_unresolved_handler> &, const bustache::ast::content &>' requested here
            visit(visitor, content);
            ^
/usr/include/bustache/generate/string.hpp:96:9: note: in instantiation of function template specialization 'bustache::generate<bustache::detail::string_sink<std::__cxx11::basic_string<char,
      std::char_traits<char>, std::allocator<char> > >, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bustache::format,
      std::hash<std::__cxx11::string>, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const
      std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bustache::format> > >, bustache::default_unresolved_handler>' requested here
        generate(sink, fmt, data, context, flag, std::forward<UnresolvedHandler>(f));
        ^
main.cpp:9:13: note: in instantiation of function template specialization 'bustache::generate_string<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >,
      std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bustache::format, std::hash<std::__cxx11::string>,
      std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::__cxx11::basic_string<char,
      std::char_traits<char>, std::allocator<char> >, bustache::format> > >, bustache::default_unresolved_handler>' requested here
  bustache::generate_string(out, bustache::format("{{foo}}"), bustache::object{}, context, bustache::normal);
            ^