From fdb9f072a7495f8a0a782032fdf7d9218c8ae16e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 20 Apr 2012 20:26:13 +0000 Subject: [PATCH] Fix parsing of forward declaration of C++0x enums git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13010 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../cpp0x_strongly_typed_enumerations.i | 21 +++++++++++++------ Source/CParse/parser.y | 7 ++++--- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Examples/test-suite/cpp0x_strongly_typed_enumerations.i b/Examples/test-suite/cpp0x_strongly_typed_enumerations.i index 776af5822..2532d8c6e 100644 --- a/Examples/test-suite/cpp0x_strongly_typed_enumerations.i +++ b/Examples/test-suite/cpp0x_strongly_typed_enumerations.i @@ -7,6 +7,12 @@ %warnfilter(302) Val3; %warnfilter(302) Val4; +/* Forward declarations (illegally accepted by SWIG - oh well!) */ +enum Enum1 : short; +enum Enum3; +enum ; +enum : unsigned short; + %inline %{ enum class Enum1 { Val1, @@ -21,13 +27,16 @@ enum class Enum2 : short { Val3 = 100, Val4 }; +%} -/* Forward declarations. GCC doesn't support them */ -//enum Enum3; // Illegal in C++ and C++0x; no size is explicitly specified. -//enum Enum4 : unsigned int; // Legal in C++0x. -//enum class Enum5; // Legal in C++0x, because enum class declarations have a default type of "int". -//enum class Enum6 : unsigned int; // Legal C++0x. -//enum Enum2 : unsigned short; // Illegal in C++0x, because Enum2 was previously declared with a different type. +// SWIG should fail this one +enum Enum2 : unsigned short; // Illegal in C++0x, because Enum2 was previously declared with a different type. + +%inline %{ +/* Forward declarations. */ +enum Enum4 : unsigned int; // Legal in C++0x. +enum class Enum5; // Legal in C++0x, because enum class declarations have a default type of "int". +enum class Enum6 : unsigned int; // Legal C++0x. enum Enum4 : unsigned int { Val1, Val2, Val3 = 100, Val4 diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 38bb29392..562d69d50 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -3326,14 +3326,15 @@ c_enum_inherit : COLON primitive_type { ; /* ------------------------------------------------------------ enum [class] Name; + enum [class] Name [: base_type]; ------------------------------------------------------------ */ -c_enum_forward_decl : storage_class c_enum_keyword c_enum_inherit ID SEMI { +c_enum_forward_decl : storage_class c_enum_keyword ename c_enum_inherit SEMI { SwigType *ty = 0; $$ = new_node("enumforward"); - ty = NewStringf("enum %s", $4); + ty = NewStringf("enum %s", $3); Setattr($$,"enumkeyword",$2); - Setattr($$,"name",$4); + Setattr($$,"name",$3); Setattr($$,"type",ty); Setattr($$,"sym:weak", "1"); add_symbols($$);