In GNOME's gobject object-oriented code, each type has a "get_type" function. Something like, eg:
static GType our_type = 0;
if (our_type == 0)
our_type = g_boxed_type_register_static (I_("PangoLayoutLine"),
Since these functions are called quite frequently (as part of casts among other things), people have started marking them with __attribute__((const)) so the compiler can optimize away multiple calls to them. However, there is a down side to it. Sometimes one needs to make sure the type is registered, so they call the _get_type() function to ensure that, but the compiler, seeing the ((const)) attribute, optimizes away the call.
This is of course a bug to mark functions with side-effects as ((const)). That's why a new function attribute like "idempotent" is useful. What it means is that subsequent calls to this function return the same value as the first call, have no side-effect, and can be optimized away, but not the first call...
The Java front-end has the same problem.
More information about GObject requirements here:
Note that I was thinking of similar attribute for C++ iostream initialization code.
Currently every unit including iostream gets a call to the iostream constructor. With LTO
we merge the constructors together and get _alot_ of redundant calls to the construction
code. Declaring that only first call is needed would save some (quite minor) startup
overehead. (overhead of iostream startup is large, but after inlning all together it
boils down to cca 7000 redundant calls in Mozilla startup that executes quite quickly)
Also note that internally we have looping const/looping pure that can be optimized in this manner, so to large degree this is just matter of exporting this out to user attributes + declaring sane behaviour on functions returning void.