Skip to content

Commit

Permalink
Ensure that the compiler properly supports regex
Browse files Browse the repository at this point in the history
  • Loading branch information
kylef committed Jun 15, 2016
1 parent 482bcf0 commit e9b6174
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1 +1,2 @@
palaver.so
palaver.so
test-regex
9 changes: 8 additions & 1 deletion 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
Expand All @@ -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
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -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.
23 changes: 23 additions & 0 deletions test-regex.cpp
@@ -0,0 +1,23 @@
#include <iostream>
#include <regex>


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;
}

0 comments on commit e9b6174

Please sign in to comment.