cppcheck icon indicating copy to clipboard operation
cppcheck copied to clipboard

fixed #14261 - Regex: added `std::regex` implementation / added `engine` to rule XML to specify regex engine

Open firewave opened this issue 2 months ago • 11 comments

firewave avatar Oct 15 '25 22:10 firewave

Might make sense to be able to specify the type via a rule file as well. That would also allow to mix and match the engines depending on required performance/features. Or maybe even only allow it via a file so to not add another CLI option and not having to deal with the left-to-right issues.

firewave avatar Oct 15 '25 22:10 firewave

This will only add the additional engine. I will also do some performance tests.

The follow-up steps are:

  • implement PCRE2 as an additional engine and make it optional via a new build flag
  • make std::regex the default and deprecate HAVE_RULES and PCRE1 so the feature works without any build dependencies
  • remove HAVE_RULES and PCRE1 shortly after (most distros have already dropped the dependency since the library has long been EOL)

firewave avatar Oct 16 '25 01:10 firewave

thanks for working on this. :+1:

danmar avatar Oct 17 '25 11:10 danmar

Might make sense to be able to specify the type via a rule file as well. That would also allow to mix and match the engines depending on required performance/features. Or maybe even only allow it via a file so to not add another CLI option and not having to deal with the left-to-right issues.

@danmar any comment on this?

firewave avatar Oct 17 '25 12:10 firewave

No comment so I will go with the way to specify the engine via XML only and not providing a CLI option for it.

firewave avatar Nov 11 '25 18:11 firewave

The follow-up steps are:

I filed some tickets for those: https://trac.cppcheck.net/ticket/14262 https://trac.cppcheck.net/ticket/14263

firewave avatar Nov 11 '25 20:11 firewave

The documentation on how to use rules is unfortunately some PDFs hosted at Sourceforge so there is nowhere to add the new field. I filed https://trac.cppcheck.net/ticket/14264 about migrating the documentation.

firewave avatar Nov 11 '25 20:11 firewave

Great - std::regex appears to behave differently in Visual Studio:

D:\a\cppcheck\cppcheck\test\testregex.cpp:181(TestRegExStd::exactmatch): Assertion failed. 
Expected: 
0

Actual: 
2

Why am I not surprised?!

And on macos testrunner is not showing the failed test:

TestVarID::structuredBindings


Testing Complete
Number of tests: 5164
Number of todos: 371
make: *** [test] Error 1
Error: Process completed with exit code 2.

firewave avatar Nov 11 '25 20:11 firewave

Great - std::regex appears to behave differently in Visual Studio:

Apparently std::regex is partially broken in the current Visual Studio version (not sure if it is what affects the test): https://developercommunity.visualstudio.com/t/std::regex-gives-a-different-result-in-m/10417784

So that partially derails the plan going forward and makes things more awkward. And I have not even profiled it yet...

firewave avatar Nov 11 '25 22:11 firewave

Coincidentally Visual Studio 2026 was released just a few hours ago and I can confirm that the test passes in it.

firewave avatar Nov 11 '25 23:11 firewave