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.
This commit is contained in:
Thomas Bleher
2023-06-29 10:15:57 +02:00
parent 81b2685f06
commit f132b6ce1d

View File

@@ -503,7 +503,7 @@ public:
/** visit every child node calling fn(node) */
template<class Visitor>
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 @@ public:
/** visit every child node calling fn(node, level) */
template<class Visitor>
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);
}