compile-time-regular-expressions icon indicating copy to clipboard operation
compile-time-regular-expressions copied to clipboard

Why is the simplest code ok with clang but failed with vc++?

Open yaoxinliu opened this issue 6 years ago • 6 comments
trafficstars

#include <ctre.hpp>

using namespace std::literals;

static constexpr auto pattern =
    ctll::fixed_string{R"(([^.]|[.])*(^|[^{])(\{\{)*\{[^{}]*)"};

constexpr bool check(std::string_view sv) noexcept
{
    return ctre::match<pattern>(sv);
}

static_assert(check("{"sv));       // ok
static_assert(check("{{{"sv));     // ok
static_assert(!check("abc{{{"sv)); // failure

int main() {}

clang 8.0 is ok, but visual studio 2019 is failed.

The error message:

test.cpp(15,15): error C2131:  expression did not evaluate to a constant
ctre.hpp(3695,20): message :  failure was caused by a read of an uninitialized symbol
ctre.hpp(3695,20): message :  see usage of 'ctre::captured_content<0,void>::storage<Iterator>::_matched'
ctre.hpp(3695,20): message :         with
ctre.hpp(3695,20): message :         [
ctre.hpp(3695,20): message :             Iterator=std::_String_view_iterator<std::char_traits<char>>
ctre.hpp(3695,20): message :         ]

yaoxinliu avatar Sep 05 '19 08:09 yaoxinliu

probably problem in constexpr engine of MSVC, don't use static_assert, in runtime it will be ok

hanickadot avatar Sep 05 '19 08:09 hanickadot

probably problem in constexpr engine of MSVC, don't use static_assert, in runtime it will be ok

To me, however, the killer-feature of CTRE is compile-time checking and validating. Is there any workaround for this issue?

yaoxinliu avatar Sep 05 '19 08:09 yaoxinliu

I don't know now, probably there is, there was something similar recently. But I don't have time to fix it now. Sorry, Probably end of this month.

hanickadot avatar Sep 05 '19 08:09 hanickadot

It's still doing the validation of pattern in compile-time. It looks as something greedy cycle related to me.

hanickadot avatar Sep 05 '19 08:09 hanickadot

And I don't have MSVC to try it, please report bug to MSVC compiler team.

hanickadot avatar Sep 05 '19 08:09 hanickadot

This works fine with a Release build (and an up-to-date MSVC 2019). I think that the iterator checking feature of MS standard library is causing the issue. Setting _ITERATOR_DEBUG_LEVEL=0 works to.

sdebionne avatar Nov 27 '19 11:11 sdebionne