From: Kyle Fuller Date: Wed, 15 Jun 2016 17:05:31 +0000 (-0700) Subject: Ensure that the compiler properly supports regex X-Git-Tag: 1.1.0~10 X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=e9b61749e7d84c3672d7eba53eb94a0788c28d1d;p=znc-palaver.git Ensure that the compiler properly supports regex --- diff --git a/.gitignore b/.gitignore index 3ddf499..1a36729 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -palaver.so \ No newline at end of file +palaver.so +test-regex diff --git a/Makefile b/Makefile index 71640d1..e51c89c 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,8 @@ PALAVER_VERSION := $(shell git describe --tags --always --dirty 2> /dev/null || cat VERSION) CXXFLAGS := -Wno-unknown-pragmas -DPALAVER_VERSION=\"$(PALAVER_VERSION)\" -palaver.so: palaver.cpp +palaver.so: test palaver.cpp + @echo "Building palaver.so" @CXXFLAGS="$(CXXFLAGS)" znc-buildmod palaver.cpp install: palaver.so @@ -16,3 +17,9 @@ uninstall: @echo "Uninstall palaver from $(HOME)/.znc/modules" -rm -f $(HOME)/.znc/modules/palaver.so +test-regex: test-regex.cpp + @c++ -std=c++11 test-regex.cpp -o test-regex + +.PHONY: test +test: test-regex + @./test-regex diff --git a/README.md b/README.md index 4c5bad1..d2d134f 100644 --- a/README.md +++ b/README.md @@ -98,3 +98,10 @@ To solve this problem you can force IPv4 connections in ZNC using: ``` /msg *status setbindhost 0.0.0.0 ``` + +###### Caught regex error + +This error indicates a problem with the C++ regex implementation in your C++ +compiler. Older versions of GCC have buggy implementations of regex and are +incompatible with the module. GCC 4.9 or newer, and Clang are known to work. +Please upgrade to a modern version. diff --git a/test-regex.cpp b/test-regex.cpp new file mode 100644 index 0000000..f3c77c6 --- /dev/null +++ b/test-regex.cpp @@ -0,0 +1,23 @@ +#include +#include + + +int main(int argc, const char *argv[]) { + std::smatch match; + std::string message = "Hello nickname."; + std::string matcher = "\\bnickname\\b"; + + try { + std::regex expression = std::regex(matcher, std::regex_constants::ECMAScript | std::regex_constants::icase); + std::regex_search(message, match, expression); + } catch (std::regex_error& error) { + std::cout << "Your C++ compiler doesn't properly support regex. Please upgrade to GCC 4.9, Clang or newer.\n"; + return 1; + } + + if (match.empty()) { + return 1; + } + + return 0; +}