foonathan / lexy

C++ parsing DSL
https://lexy.foonathan.net
Boost Software License 1.0
991 stars 66 forks source link

parse_as_tree static assertion fails in Debug configuration on MSVC #190

Closed jan-kelemen closed 6 months ago

jan-kelemen commented 6 months ago

The following code doesn't compile in Debug configuration on MSVC:

#include <string_view>
#include <lexy/action/parse_as_tree.hpp>
#include <lexy/input/range_input.hpp>
#include <lexy_ext/report_error.hpp>
#include <lexy/dsl.hpp>

struct channel
{
    static constexpr auto rule = lexy::dsl::n_digits<2, lexy::dsl::hex>;
};

int main()
{
    constexpr std::string_view str{"abc123"};
    lexy::range_input input{ str.begin(), str.end() };
    lexy::parse_tree_for<decltype(input)> tree;
    parse_as_tree<channel>(tree, input, lexy_ext::report_error);
}

On this static_assert:

    void update_end(typename Reader::iterator end) noexcept
    {
        if constexpr (_optimize_end)
        {
            static_assert(sizeof(pt_node_token) == 3 * sizeof(void*));

Error message:

1>C:\Users\puma\.conan2\p\b\foonab043832bb9606\p\include\lexy\parse_tree.hpp(128,49): error C2607: static assertion failed
1>(compiling source file '../../../../src/mql/mqlast/test/mqlast_parse.t.cpp')
1>C:\Users\puma\.conan2\p\b\foonab043832bb9606\p\include\lexy\parse_tree.hpp(128,49):
1>the template instantiation context (the oldest one first) is
1>  D:\git\melinda.git\master\src\mql\mqlast\test\mqlast_parse.t.cpp(17,5):
1>  see reference to function template instantiation 'lexy::validate_result<lexy_ext::_report_error<int>> lexy::parse_as_tree<channel,void,void,lexy::range_input<lexy::default_encoding,Iterator,Sentinel>,lexy_ext::_report_error<int>>(lexy::parse_tree<lexy::_rr<Encoding,Iterator,Sentinel>,void,void> &,const Input &,const ErrorCallback &)' being compiled
1>        with
1>        [
1>            Iterator=std::_String_view_iterator<std::char_traits<char>>,
1>            Sentinel=std::_String_view_iterator<std::char_traits<char>>,
1>            Encoding=lexy::default_encoding,
1>            Input=lexy::range_input<lexy::default_encoding,std::_String_view_iterator<std::char_traits<char>>,std::_String_view_iterator<std::char_traits<char>>>,
1>            ErrorCallback=lexy_ext::_report_error<int>
1>        ]

I assume that this is due to the fact that MSVC has checked iterators in Debug configuration and in that case the size of the iterator isn't equal to the size of the pointer.

foonathan commented 6 months ago

Thanks, should be fixed.