diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index f110bcd5..0af66d4e 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -2076,8 +2076,8 @@ namespace chaiscript { const auto prev_stack_top = m_match_stack.size(); if (Keyword("enum")) { - if (!Keyword("class")) { - throw exception::eval_error("Expected 'class' after 'enum' (only 'enum class' is supported)", + if (!Keyword("class") && !Keyword("struct")) { + throw exception::eval_error("Expected 'class' or 'struct' after 'enum' (only 'enum class'/'enum struct' is supported)", File_Position(m_position.line, m_position.col), *m_filename); } diff --git a/unittests/enum.chai b/unittests/enum.chai index 7f85de73..1821af7a 100644 --- a/unittests/enum.chai +++ b/unittests/enum.chai @@ -102,3 +102,9 @@ assert_equal(4, Flags::Execute.to_underlying()) auto f = Flags::Flags(2) assert_true(f == Flags::Write) + +// enum struct syntax (equivalent to enum class, like C++) +enum struct Direction { North, East, South, West } +assert_equal(0, Direction::North.to_underlying()) +assert_equal(3, Direction::West.to_underlying()) +assert_true(Direction::East != Direction::South)