compile-time-regular-expressions
compile-time-regular-expressions copied to clipboard
Why is the simplest code ok with clang but failed with vc++?
#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 : ]
probably problem in constexpr engine of MSVC, don't use static_assert, in runtime it will be ok
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?
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.
It's still doing the validation of pattern in compile-time. It looks as something greedy cycle related to me.
And I don't have MSVC to try it, please report bug to MSVC compiler team.
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.