Yigal Chripun:

> Regardless of usefulness (or good design) of such variables, this sounds
> extremely dangerous. The compiler must not change semantics of the
> program based on optimization. optimizing away such variables most
> definitely alters the semantics.

Maybe you have misunderstood, or I have explained the things badly. So I 
explain again.

I have seen that LDC (when it performs link-time optimization, that's not done 
in all situations) keeps just one copy of constants inside the binary even if 
such constants are present in more than one template instance. In the 
situations where LTO is available I think this doesn't cause problems.

Then I am half-seriously proposing a syntax like:
T foo(T)(T x) {
  static static int y;
  // ...
}

Where the y is now static to (shared among) all instances of the templated 
function foo. This may be a little error-prone and maybe not that useful, but 
again here the compiler doesn't change the semantics of the program, because 
using a double static keyword the programmer has stated such intention.

Bye,
bearophile

Reply via email to