For instance, if I have this code:
class SomeDataProcessor
{
public:
bool calc(const SomeData & d1, const SomeData & d2) const;
private:
//Some n
GCC has the pure
attribute (used as __attribute__((pure))
) for functions which tells the compiler that redundant calls can be eliminated. It's used e.g. on strlen
.
I'm not aware of any compiler doing this automatically, especially considering the fact that the functions to be called may not be available in source form, and the object file formats contain no metadata about whether a function is pure or not.