A: 

It's not really (afaik) the compiler that does this, but when writing C# in Visual Studio when using the plugin ReSharper, you can get compile time hints that indicate that it is possible to declare something as const. On the other hand, that doesn't go under the category "without telling you so", so it might not be what you're looking for...

Tomas Lycken
Of course, I would like the compiler be able to detect them automatically instead of having to use another external tool.
Eduardo
+1  A: 

To do so is inherently risky in languages that have pointers and lack global compilation & analysis. So, if a an operation is declared non-const, the compiler must assume it could have side-effects.

Example:

//getx.cpp
int GetX(int input)
{
   int* pData = (int*) input;
   *pData = 50;
   return 0;
}
// gety.cpp
int GetY(int input)
{
   return GetX(input + 4);
}
// main.cpp
int main()
{
   int arg[] { 0, 4 };
   return GetY((int)arg);
}

The compiler while compiling GetY can't tell that GetX treats its argument as a pointer and dereferences and modifies data in a non-functional, side-effect-prone manner. That information is only available during linking so you'd have to re-invent the concept of linking to include a lot of code generation and analysis to support such a feature.

David Gladfelter
Of course, if GetX is not pure mathematical then GetX is not as it calls a non pure mathematical function (maybe we should call them procedures). If a function calls an external function it should assume is not pure mathematical.
Eduardo
But the problem is that "external" means in a different translation unit (different .c file). That's a big limitation.
David Gladfelter