[Issue 10950] [CTFE] enum "char[]" not correctly duplicated when used.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Sep 4 04:53:53 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10950



--- Comment #7 from Don <clugdbug at yahoo.com.au> 2013-09-04 04:53:51 PDT ---
My thinking on this is still not completely clear.

If you have an enum, by definition it does not have an address - it's a
manifest constant. If you are using it in an expression which needs an address,
it has to make one up. Something bad is inevitable. Currently in many cases it
duplicates the value whenever it needs the address, so you may get a different
address each time.

There are two possible approaches I can see.
(1) Treat strings as requiring an address, therefore banning it at declaration.
Most of these should be changed from 'enum' into 'static const'.

(2) Allow the declaration, but don't permit the address to be used.
So, for example, you could declare:
enum int [] x = [23, 5, 66, 123];

and then later in the code, you could use x[3]. It gets const-folded away, so
it's OK - there is no address.
But auto z = x;  should not compile because x has no runtime address.

This is the only legitimate use of an enum reference type, that I can think of.
The benefit of it, is that you can store CTFE results, so that they don't need
to be used again. But it would be a simple optimisation to make a no-parameter
CTFE function to remember its result, so I don't think it's a big win.

So I currently favour resolution (1).

Regardless of this, almost all occurrences of 'enum string' in Phobos should
actually be 'static string'. They are causing executable bloat.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list