Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix word boundary assertions under C++20 #345

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

BigRedEye
Copy link

In C++20 with P1614R2 implemented, zero-width assertions \b and \B do not work. For example, the following code fails with "Pattern can never match":

#include <hyperscan/src/hs.h>

#include <cstdio>


int main() {
    hs_compile_error_t* err = nullptr;
    hs_database_t* db = nullptr;
    hs_platform_info_t platform;
    hs_populate_platform(&platform);
    hs_error_t res = hs_compile("foo\\b", 0, HS_MODE_BLOCK, &platform, &db, &err);
    if (res != HS_SUCCESS) {
        printf("Error: %s\n", err->message);
    }
    hs_free_database(db);
}

This is caused by breaking change in std::pair comparison operators (after P1614R2 std::pair uses operator<=>). The spaceship operator prefers implicit conversion to bool, if exists:
https://godbolt.org/z/xnPreToW4
https://godbolt.org/z/T4cKEPrTf

So nearly all values of type std::pair<ue2::graph_detail::vertex_descriptor, ue2::graph_detail::vertex_descriptor> compare equal: https://github.com/intel/hyperscan/blob/master/src/util/ue2_graph.h#L179-L188, so edge_cache_t is malformed: https://github.com/intel/hyperscan/blob/master/src/compiler/asserts.cpp#L284-L288, and the NFA graph after removeAssertVertices becomes disconnected.

The fix is simple: just mark operator bool() as explicit.

@higher-performance
Copy link

Hi, I believe the same problem exists here as well:

operator bool() const { return p; }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants