From: Richard Kreckel Date: Mon, 25 Nov 2024 23:21:28 +0000 (+0100) Subject: Avoid "expression with side effects..." warning using ex_to(). X-Git-Tag: release_1-8-8~8 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?a=commitdiff_plain;h=32702f847fb49da649f4362b0de3084890ac8129;p=ginac.git Avoid "expression with side effects..." warning using ex_to(). Clang++ warns that instantiations of this inline template function ex_to(const ex &) are "expression with side effects [that] will be evaluated despite being used as an operand to 'typeid'". Let's declare this ex_to() as a pure function (i.e. having no side effects) for compilers which support __attribute__((__pure__)). GCC seems to support this attribute since more than ten years. --- diff --git a/ginac/compiler.h b/ginac/compiler.h index e9682794..0216b681 100644 --- a/ginac/compiler.h +++ b/ginac/compiler.h @@ -27,10 +27,12 @@ #define unlikely(cond) __builtin_expect((cond), 0) #define likely(cond) __builtin_expect((cond), 1) #define attribute_deprecated __attribute__ ((deprecated)) +#define attribute_pure __attribute__((__pure__)) #else #define unlikely(cond) (cond) #define likely(cond) (cond) #define attribute_deprecated +#define attribute_pure #endif #endif // ndef GINAC_COMPILER_DEP_H diff --git a/ginac/ex.h b/ginac/ex.h index 5381a38a..37d74e7b 100644 --- a/ginac/ex.h +++ b/ginac/ex.h @@ -25,6 +25,7 @@ #include "basic.h" #include "ptr.h" +#include "compiler.h" #include #include @@ -973,7 +974,7 @@ inline bool is_exactly_a(const ex &obj) * @param e expression * @return reference to object of class T * @see is_exactly_a() */ -template +template attribute_pure inline const T &ex_to(const ex &e) { GINAC_ASSERT(is_a(e));