[C++0x] implementing forward declarations for enums

Ed Smith-Rowland 3dw4rd@verizon.net
Wed Sep 22 02:41:00 GMT 2010

On 09/20/2010 09:58 AM, Rodrigo Rivas wrote:
> Hello all.
> This patch tries to implement the C++0x featue "Forward declarations
> for enums" aka "opaque enum declarations":
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2764.pdf
> Please note that this is a WIP, and as such lacks formatting,
> comments, testcases, etc.
> Except for the things noted below, I think it works pretty well.
> 1
> A enum declaration should fail if adds a list of constants and it
> already have one. I check it with "TYPE_VALUES (type)", but this is
> incorrect because an empty list will not be seen.
> So, the current patch will accept incorrect code like:
> enum class Foo { };
> enum class Foo { A, B, C};
> I think that a new flag is needed for ENUMERAL_TYPE, but I don't know which one.
> 2
> I am calling "finish_enum" several types, for each of the opaque
> declarations until it gets a list of constants. It doesn't seem to
> cause problems except with the debug information. With default flags
> and everything, gdb sees only the first declaration:
> enum class Foo;
> enum class Foo {A, B, C}
> Foo f;
> (gdb) ptype f;
> enum Foo {}
> I don't see an easy way to solve it...
> 3
> I don't like very much the added parameter to the "start_enum"
> function, but I don't see how to do it without breaking existing code.
> Comments are most welcomed.
> Regards.
> Rodrigo

I did a very cursory look at the patch.

I had to initialize the variable nested_being_defined to get it to 
compile (possible uninitialized warning).  I initialized it to false.
I added some test cases mostly from the paper.

make check is still running.  I know I don't have the deja-gnu error 
trapping right so there will be FAILs that shouldn't be there.

I'll look in greater detail at your other points tonight.

It looks like the first two are related.  What does an enum look like in 
tree?  Maybe the tree for enum could have a has_definition flag.
Set it to -1 on the first declaration.  Subsequent declarations would 
know not to finish_enum.  Set it to 1 on seeing the definition.  
subsequent definitions would fail.


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: enumdecl.txt
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20100922/729aa7ac/attachment.txt>

More information about the Gcc mailing list