From f132b6ce1ddefae6dda954dc661ffbab12088d02 Mon Sep 17 00:00:00 2001 From: Thomas Bleher Date: Thu, 29 Jun 2023 10:15:57 +0200 Subject: [PATCH] Do not mark visit functions as pure Marking a function as pure implies that it does not have any observable side effects (only the return value is used). So if the compiler detects that the return value of a pure function is not used, it may eliminate the call to the pure function. This would be wrong, however, if the passed in Visitor has side effects which are needed by the program. Fix this by not marking the visit functions as pure. --- src/c4/yml/node.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/c4/yml/node.hpp b/src/c4/yml/node.hpp index dcb06f28a..d97aa7f42 100644 --- a/src/c4/yml/node.hpp +++ b/src/c4/yml/node.hpp @@ -503,7 +503,7 @@ struct RoNodeMethods /** visit every child node calling fn(node) */ template - C4_ALWAYS_INLINE C4_PURE bool visit(Visitor fn, size_t indentation_level=0, bool skip_root=true) const noexcept + C4_ALWAYS_INLINE bool visit(Visitor fn, size_t indentation_level=0, bool skip_root=true) const noexcept { return detail::_visit(*(ConstImpl const*)this, fn, indentation_level, skip_root); } @@ -517,7 +517,7 @@ struct RoNodeMethods /** visit every child node calling fn(node, level) */ template - C4_ALWAYS_INLINE C4_PURE bool visit_stacked(Visitor fn, size_t indentation_level=0, bool skip_root=true) const noexcept + C4_ALWAYS_INLINE bool visit_stacked(Visitor fn, size_t indentation_level=0, bool skip_root=true) const noexcept { return detail::_visit_stacked(*(ConstImpl const*)this, fn, indentation_level, skip_root); }