Skip to content

Commit 4ce44b2

Browse files
author
Hana Dusíková
committed
cnttp support in gcc9 experimental with workaround for bugs 88092 and 88095
1 parent a72dce6 commit 4ce44b2

File tree

16 files changed

+206
-52
lines changed

16 files changed

+206
-52
lines changed

Makefile

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,31 @@
22

33
default: all
44

5-
TARGETS := result.cpp test.cpp $(wildcard tests/benchmark-exec/*.cpp)
5+
TARGETS := a.cpp result.cpp test.cpp $(wildcard tests/benchmark-exec/*.cpp)
6+
IGNORE := $(wildcard tests/benchmark/*.cpp) $(wildcard tests/benchmark-exec/*.cpp) tests/trampoline.cpp
67

78
DESATOMAT := /www/root/desatomat/console/desatomat.php
89

9-
CXXFLAGS := -std=c++17 -Iinclude -O3 -Wno-gnu-string-literal-operator-template -pedantic -Wall -Wextra
10-
#-Xclang -fconcepts-ts
11-
LDFLAGS := -lpcre2-8
10+
CPP_STANDARD := $(shell ./cpp-20-check.sh $(CXX))
1211

12+
CXXFLAGS := $(CPP_STANDARD) -Iinclude -O3 -Wno-gnu-string-literal-operator-template -pedantic -Wall -Wextra
13+
LDFLAGS :=
14+
#-lpcre2-8 -lboost_regex -lre2
1315

1416
TESTS := $(wildcard tests/*.cpp) $(wildcard tests/benchmark/*.cpp)
1517
TRUE_TARGETS := $(TARGETS:%.cpp=%)
16-
IGNORE := $(wildcard tests/benchmark/*.cpp) tests/benchmark-exec/boost.cpp wildcard tests/benchmark-exec/re2.cpp
17-
OBJECTS_PRE := $(TARGETS:%.cpp=%.o) $(TESTS:%.cpp=%.o)
18-
OBJECTS := $(filter-out $(IGNORE:%.cpp=%.o), $(OBJECTS_PRE))
18+
override TRUE_TARGETS := $(filter-out $(IGNORE:%.cpp=%), $(TRUE_TARGETS))
19+
OBJECTS := $(TARGETS:%.cpp=%.o) $(TESTS:%.cpp=%.o)
20+
override OBJECTS := $(filter-out $(IGNORE:%.cpp=%.o),$(OBJECTS))
1921
DEPEDENCY_FILES := $(OBJECTS:%.o=%.d)
2022

2123
all: $(TRUE_TARGETS) $(OBJECTS)
2224

25+
list:
26+
echo $(SUPPORTED_CPP20)
27+
2328
$(TRUE_TARGETS): %: %.o
24-
$(CXX) $< $(LDFLAGS) -o $@
29+
$(CXX) $< $(LDFLAGS) -o $@ > /dev/null
2530

2631
$(OBJECTS): %.o: %.cpp
2732
$(CXX) $(CXXFLAGS) -MMD -c $< -o $@

a.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <iostream>
2+
#include <ctre.hpp>
3+
#include <string_view>
4+
#include <optional>
5+
6+
7+
struct name { std::string_view first, family; };
8+
9+
std::optional<name> extract(std::string_view sv) noexcept {
10+
#if __cpp_nontype_template_parameter_class
11+
if (auto [re,f,l] = ctre::match<"([A-Za-z]+?),([A-Za-z]+?)">(sv); re) {
12+
#else
13+
using namespace ctre::literals;
14+
if (auto [re,f,l] = "([A-Za-z]+?),([A-Za-z]+?)"_ctre.match(sv); re) {
15+
#endif
16+
return name{f,l};
17+
} else {
18+
return std::nullopt;
19+
}
20+
}
21+
22+
int main() {
23+
24+
}

cpp-20-check.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
if echo "" | $1 -std=c++2a -E -x c++ - 2>/dev/null 1>/dev/null; then
3+
VERSION=`$1 -v 2>&1 | grep "gcc" | grep "experimental"`
4+
if [ -z "$VERSION" ]; then
5+
echo "-std=c++2a";
6+
else
7+
echo "-std=c++2a -DISABLE_GNU_EXTENSION_LITERALS";
8+
fi
9+
else
10+
echo "-std=c++17";
11+
fi

include/ctll/parser.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ template <typename Grammar, ctll::basic_fixed_string input, typename ActionSelec
125125
template <typename Subject, size_t... Pos> static constexpr auto trampoline_decide(Subject, std::index_sequence<Pos...>) noexcept {
126126
// parse everything for first char and than for next and next ...
127127
// Pos+1 is needed as we want to finish calculation with epsilons on stack
128-
auto v = (seed<0, grammar::start_stack, Subject, decision::undecided>::parse() + ... + index_placeholder<Pos+1>());
129-
//id(v);
128+
auto v = (decide<0, typename grammar::start_stack, Subject>({}, {}) + ... + index_placeholder<Pos+1>());
130129
return v;
131130
}
132131

include/ctre/functions.hpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ template <typename CharT, size_t N> fixed_string(const CharT (&)[N]) -> fixed_st
3232

3333
#if __cpp_nontype_template_parameter_class
3434
template <ctll::basic_fixed_string input> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto re() noexcept {
35+
constexpr auto _input = input; // workaround for GCC 9 bug 88092
3536
#else
3637
template <auto & input> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto re() noexcept {
38+
constexpr auto & _input = input;
3739
#endif
38-
constexpr auto _input = input;
40+
3941
using tmp = typename ctll::parser<ctre::pcre, _input, ctre::pcre_actions>::template output<pcre_context<>>;
4042
static_assert(tmp(), "Regular Expression contains syntax error.");
4143
using re = decltype(front(typename tmp::output_type::stack_type()));
@@ -49,7 +51,7 @@ template <typename T> void identify(T);
4951

5052
#if __cpp_nontype_template_parameter_class
5153
template <ctll::basic_fixed_string input> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto match(std::string_view sv) noexcept {
52-
constexpr auto _input = input;
54+
constexpr auto _input = input; // workaround for GCC 9 bug 88092
5355
using tmp = typename ctll::parser<ctre::pcre, _input, ctre::pcre_actions>::template output<pcre_context<>>;
5456
static_assert(tmp(), "Regular Expression contains syntax error.");
5557
using re = decltype(ctll::front(typename tmp::output_type::stack_type()));
@@ -58,8 +60,8 @@ template <ctll::basic_fixed_string input> CTRE_FLATTEN constexpr CTRE_FORCE_INLI
5860
}
5961
#else
6062
template <auto & input> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto match(std::string_view sv) noexcept {
61-
62-
using tmp = typename ctll::parser<ctre::pcre, input, ctre::pcre_actions>::template output<pcre_context<>>;
63+
constexpr auto & _input = input;
64+
using tmp = typename ctll::parser<ctre::pcre, _input, ctre::pcre_actions>::template output<pcre_context<>>;
6365
static_assert(tmp(), "Regular Expression contains syntax error.");
6466
using re = decltype(ctll::front(typename tmp::output_type::stack_type()));
6567
auto re_obj = ctre::regular_expression<re>(re());
@@ -70,15 +72,15 @@ template <auto & input> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto match(std:
7072

7173
#if __cpp_nontype_template_parameter_class
7274
template <ctll::basic_fixed_string input, typename ForwardIt> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto match(ForwardIt first, ForwardIt last) noexcept {
73-
constexpr auto _input = input;
75+
constexpr auto _input = input; // workaround for GCC 9 bug 88092
7476
using tmp = typename ctll::parser<ctre::pcre, _input, ctre::pcre_actions>::template output<pcre_context<>>;
7577
static_assert(tmp(), "Regular Expression contains syntax error.");
7678
using re = decltype(ctll::front(typename tmp::output_type::stack_type()));
7779
return ctre::regular_expression(re()).match(first, last);
7880
}
7981
#else
8082
template <auto & input, typename ForwardIt> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto match(ForwardIt first, ForwardIt last) noexcept {
81-
constexpr auto _input = input;
83+
constexpr auto & _input = input;
8284
using tmp = typename ctll::parser<ctre::pcre, _input, ctre::pcre_actions>::template output<pcre_context<>>;
8385
static_assert(tmp(), "Regular Expression contains syntax error.");
8486
using re = decltype(ctll::front(typename tmp::output_type::stack_type()));
@@ -90,8 +92,7 @@ template <auto & input, typename ForwardIt> CTRE_FLATTEN constexpr CTRE_FORCE_IN
9092

9193
#if __cpp_nontype_template_parameter_class
9294
template <ctll::basic_fixed_string input> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto search(std::string_view sv) noexcept {
93-
94-
constexpr auto _input = input;
95+
constexpr auto _input = input; // workaround for GCC 9 bug 88092
9596
using tmp = typename ctll::parser<ctre::pcre, _input, ctre::pcre_actions>::template output<pcre_context<>>;
9697
static_assert(tmp(), "Regular Expression contains syntax error.");
9798
using re = decltype(ctll::front(typename tmp::output_type::stack_type()));
@@ -100,8 +101,8 @@ template <ctll::basic_fixed_string input> CTRE_FLATTEN constexpr CTRE_FORCE_INLI
100101
}
101102
#else
102103
template <auto & input> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto search(std::string_view sv) noexcept {
103-
104-
using tmp = typename ctll::parser<ctre::pcre, input, ctre::pcre_actions>::template output<pcre_context<>>;
104+
constexpr auto & _input = input;
105+
using tmp = typename ctll::parser<ctre::pcre, _input, ctre::pcre_actions>::template output<pcre_context<>>;
105106
static_assert(tmp(), "Regular Expression contains syntax error.");
106107
using re = decltype(ctll::front(typename tmp::output_type::stack_type()));
107108
auto re_obj = ctre::regular_expression(re());
@@ -112,7 +113,7 @@ template <auto & input> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto search(std
112113

113114
#if __cpp_nontype_template_parameter_class
114115
template <ctll::basic_fixed_string input, typename ForwardIt> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto search(ForwardIt first, ForwardIt last) noexcept {
115-
constexpr auto _input = input;
116+
constexpr auto _input = input; // workaround for GCC 9 bug 88092
116117
using tmp = typename ctll::parser<ctre::pcre, _input, ctre::pcre_actions>::template output<pcre_context<>>;
117118
static_assert(tmp(), "Regular Expression contains syntax error.");
118119
using re = decltype(ctll::front(typename tmp::output_type::stack_type()));
@@ -121,7 +122,7 @@ template <ctll::basic_fixed_string input, typename ForwardIt> CTRE_FLATTEN const
121122
}
122123
#else
123124
template <auto & input, typename ForwardIt> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto search(ForwardIt first, ForwardIt last) noexcept {
124-
125+
constexpr auto & _input = input;
125126
using tmp = typename ctll::parser<ctre::pcre, input, ctre::pcre_actions>::template output<pcre_context<>>;
126127
static_assert(tmp(), "Regular Expression contains syntax error.");
127128
using re = decltype(ctll::front(typename tmp::output_type::stack_type()));

include/ctre/literals.hpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@ namespace ctre {
1515
// in C++20 we have `class nontype template parameters`
1616

1717
#if !__cpp_nontype_template_parameter_class
18-
template <typename CharT, CharT... input> static inline constexpr auto _fixed_string_reference = ctll::ctll::basic_fixed_string<CharT, sizeof...(input)>({input...});
18+
template <typename CharT, CharT... input> static inline constexpr auto _fixed_string_reference = ctll::basic_fixed_string<CharT, sizeof...(input)>({input...});
1919
#endif
2020

2121
namespace literals {
2222

23-
#if false
24-
2523
#ifndef _MSC_VER
24+
#ifndef ISABLE_GNU_EXTENSION_LITERALS
2625

2726
// add this when we will have concepts
2827
// requires ctll::parser<ctre::pcre, _fixed_string_reference<CharT, charpack...>, ctre::pcre_actions>::template correct_with<pcre_context<>>
2928

3029
#if !__cpp_nontype_template_parameter_class
3130
template <typename CharT, CharT... charpack> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto operator""_ctre() noexcept {
32-
constexpr auto & input = _fixed_string_reference<CharT, charpack...>;
31+
constexpr auto & _input = _fixed_string_reference<CharT, charpack...>;
3332
#else
3433
template <ctll::basic_fixed_string input> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto operator""_ctre() noexcept {
34+
constexpr auto _input = input; // workaround for GCC 9 bug 88092
3535
#endif
36-
using tmp = typename ctll::parser<ctre::pcre, input, ctre::pcre_actions>::template output<pcre_context<>>;
36+
using tmp = typename ctll::parser<ctre::pcre, _input, ctre::pcre_actions>::template output<pcre_context<>>;
3737
static_assert(tmp(), "Regular Expression contains syntax error.");
3838
using re = decltype(front(typename tmp::output_type::stack_type()));
3939
return ctre::regular_expression(re());
@@ -55,49 +55,54 @@ template <typename CharT, CharT... charpack> CTRE_FLATTEN constexpr CTRE_FORCE_I
5555
namespace test_literals {
5656

5757
#ifndef _MSC_VER
58+
#ifndef ISABLE_GNU_EXTENSION_LITERALS
5859

5960
#if !__cpp_nontype_template_parameter_class
6061
template <typename CharT, CharT... charpack> CTRE_FLATTEN constexpr inline auto operator""_ctre_test() noexcept {
61-
constexpr auto & input = _fixed_string_reference<CharT, charpack...>;
62+
constexpr auto & _input = _fixed_string_reference<CharT, charpack...>;
6263
#else
6364
template <ctll::basic_fixed_string input> CTRE_FLATTEN constexpr inline auto operator""_ctre_test() noexcept {
65+
constexpr auto _input = input; // workaround for GCC 9 bug 88092
6466
#endif
65-
return ctll::parser<ctre::pcre, input>::correct;
67+
return ctll::parser<ctre::pcre, _input>::correct;
6668
}
6769

6870
#if !__cpp_nontype_template_parameter_class
6971
template <typename CharT, CharT... charpack> CTRE_FLATTEN constexpr inline auto operator""_ctre_gen() noexcept {
70-
constexpr auto & input = _fixed_string_reference<CharT, charpack...>;
72+
constexpr auto & _input = _fixed_string_reference<CharT, charpack...>;
7173
#else
7274
template <ctll::basic_fixed_string input> CTRE_FLATTEN constexpr inline auto operator""_ctre_gen() noexcept {
75+
constexpr auto _input = input; // workaround for GCC 9 bug 88092
7376
#endif
74-
using tmp = typename ctll::parser<ctre::pcre, input, ctre::pcre_actions>::template output<pcre_context<>>;
77+
using tmp = typename ctll::parser<ctre::pcre, _input, ctre::pcre_actions>::template output<pcre_context<>>;
7578
static_assert(tmp(), "Regular Expression contains syntax error.");
7679
return typename tmp::output_type::stack_type();
7780
}
7881

7982

8083
#if !__cpp_nontype_template_parameter_class
8184
template <typename CharT, CharT... charpack> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto operator""_ctre_syntax() noexcept {
82-
constexpr auto & input = _fixed_string_reference<CharT, charpack...>;
85+
constexpr auto & _input = _fixed_string_reference<CharT, charpack...>;
8386
#else
8487
template <ctll::basic_fixed_string input> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto operator""_ctre_syntax() noexcept {
88+
constexpr auto _input = input; // workaround for GCC 9 bug 88092
8589
#endif
86-
return ctll::parser<ctre::pcre, input, ctre::pcre_actions>::template correct_with<pcre_context<>>;
90+
return ctll::parser<ctre::pcre, _input, ctre::pcre_actions>::template correct_with<pcre_context<>>;
8791
}
8892

8993

9094
#if !__cpp_nontype_template_parameter_class
9195
template <typename CharT, CharT... charpack> CTRE_FLATTEN constexpr inline auto operator""_simple_test() noexcept {
92-
constexpr auto & input = _fixed_string_reference<CharT, charpack...>;
96+
constexpr auto & _input = _fixed_string_reference<CharT, charpack...>;
9397
#else
9498
template <ctll::basic_fixed_string input> CTRE_FLATTEN constexpr inline auto operator""_simple_test() noexcept {
99+
constexpr auto _input = input; // workaround for GCC 9 bug 88092
95100
#endif
96-
return ctll::parser<ctre::simple, input>::correct;
101+
return ctll::parser<ctre::simple, _input>::correct;
97102
}
98103

99104
#endif
100-
105+
#endif
101106
#endif
102107

103108

include/ctre/range.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ template <typename BeginIterator, typename EndIterator, typename RE> struct rege
2020

2121

2222
template <typename BeginIterator, typename EndIterator, typename RE> constexpr auto range(BeginIterator begin, EndIterator end, RE) noexcept {
23-
//return regex_range<BeginIterator, EndIterator, RE>(begin, end);
23+
return regex_range<BeginIterator, EndIterator, RE>(begin, end);
2424
}
2525

2626
#if __cpp_nontype_template_parameter_class

result.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ enum class type {
1111
};
1212

1313
std::pair<type, std::string_view> match(std::string_view subject) {
14-
using namespace ctre::literals;
1514

15+
#if __cpp_nontype_template_parameter_class
16+
if (auto [matched, identifier, number] = ctre::match<"(?:([a-z]++)|([0-9]++))">(subject); matched) {
17+
#else
18+
using namespace ctre::literals;
1619
if (auto [matched, identifier, number] = "(?:([a-z]++)|([0-9]++))"_ctre.match(subject); matched) {
20+
#endif
1721
if (identifier) return {type::identifier, std::string_view{identifier}};
1822
else if (number) return {type::number, std::string_view{number}};
1923
else return {type::matched, std::string_view{matched}};

test.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
#include <iostream>
55

66

7-
static constexpr ctre::pattern pattern = "(?:hello|cau|guten tag|ola)|(?:hello|cau|guten tag|ola)|(?:hello|cau|guten tag|ola)|(?:hello|cau|guten tag|ola)|(?:hello|cau|guten tag|ola)|(?:hello|cau|guten tag|ola)|(?:hello|cau|guten tag|ola)";
8-
9-
bool fnc(std::string_view view) {
10-
return ctre::match<pattern>(view);
11-
}
7+
//static constexpr ctre::pattern pattern = "(?:hello|cau|guten tag|ola)|(?:hello|cau|guten tag|ola)|(?:hello|cau|guten tag|ola)|(?:hello|cau|guten tag|ola)|(?:hello|cau|guten tag|ola)|(?:hello|cau|guten tag|ola)|(?:hello|cau|guten tag|ola)";
8+
//
9+
//bool fnc(std::string_view view) {
10+
// return ctre::match<pattern>(view);
11+
//}
12+
//
13+
//int main() {
14+
// std::cout << fnc("hello") << "\n";
15+
//}
1216

1317
int main() {
14-
std::cout << fnc("hello") << "\n";
18+
1519
}

tests/benchmark-exec/baseline.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <fstream>
44
#include <regex>
55
#include "ctre.hpp"
6+
#include <re2/re2.h>
7+
#include <boost/regex.hpp>
68

79
extern "C" {
810

0 commit comments

Comments
 (0)