Skip to content

Commit 40911e6

Browse files
committed
🐛 Workaround GCC 12 bug
Problem: - GCC 12 fails to compile flow nodes. Solution: - Persuade GCC that the run and log functions have linkage.
1 parent bcbb631 commit 40911e6

File tree

2 files changed

+31
-33
lines changed

2 files changed

+31
-33
lines changed

include/flow/step.hpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,25 @@ struct rt_node {
2323
rt_node const &) -> bool = default;
2424
};
2525

26+
namespace detail {
27+
template <typename Cond, typename F> constexpr auto run_func() -> void {
28+
if (Cond{}) {
29+
F{}();
30+
}
31+
}
32+
33+
template <typename ct_node, typename Cond, stdx::ct_string Type,
34+
stdx::ct_string Name>
35+
constexpr auto log_func() -> void {
36+
if (Cond{}) {
37+
using log_spec_t = decltype(get_log_spec<ct_node>());
38+
CIB_LOG(typename log_spec_t::flavor, log_spec_t::level, "flow.{}({})",
39+
stdx::ct_string_to_type<Type, sc::string_constant>(),
40+
stdx::ct_string_to_type<Name, sc::string_constant>());
41+
}
42+
}
43+
} // namespace detail
44+
2645
template <stdx::ct_string Type, stdx::ct_string Name,
2746
subgraph_identity Identity, typename Cond, typename F>
2847
struct ct_node {
@@ -40,19 +59,8 @@ struct ct_node {
4059
constexpr static auto condition = Cond{};
4160

4261
constexpr operator rt_node() const {
43-
return rt_node{
44-
[] {
45-
if (condition) {
46-
F{}();
47-
}
48-
},
49-
[] {
50-
if (condition) {
51-
using log_spec_t = decltype(get_log_spec<ct_node>());
52-
CIB_LOG(typename log_spec_t::flavor, log_spec_t::level,
53-
"flow.{}({})", type_t{}, name_t{});
54-
}
55-
}};
62+
return rt_node{detail::run_func<Cond, F>,
63+
detail::log_func<ct_node, Cond, Type, Name>};
5664
}
5765

5866
constexpr auto operator*() const {

test/flow/CMakeLists.txt

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
1-
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" AND ${CMAKE_CXX_COMPILER_VERSION}
2-
VERSION_LESS 13)
3-
message(
4-
WARNING
5-
"GCC has a constexpr bug before version 13 that prevents flow steps from compiling. Not adding flow tests."
6-
)
7-
else()
8-
add_unit_test(
9-
"flow_separate_actions_test"
10-
CATCH2
11-
FILES
12-
"flow_cib_func.cpp"
13-
"separate_actions.cpp"
14-
LIBRARIES
15-
warnings
16-
cib)
1+
add_unit_test(
2+
"flow_separate_actions_test"
3+
CATCH2
4+
FILES
5+
"flow_cib_func.cpp"
6+
"separate_actions.cpp"
7+
LIBRARIES
8+
warnings
9+
cib)
1710

18-
add_tests(flow logging log_levels custom_log_levels)
19-
endif()
20-
21-
add_tests(graph graph_builder)
11+
add_tests(flow graph graph_builder logging log_levels custom_log_levels)
2212

2313
add_subdirectory(fail)

0 commit comments

Comments
 (0)