diff --git a/cpp/ast.py b/cpp/ast.py index 0103950..95ef5f1 100644 --- a/cpp/ast.py +++ b/cpp/ast.py @@ -1600,7 +1600,8 @@ def _get_class(self, class_type, visibility, templated_types): body = None if token.token_type == tokenize.SYNTAX and token.name == '{': - ast = ASTBuilder(self.get_scope(), self.filename, class_name, + name = class_name or '__unamed__' + ast = ASTBuilder(self.get_scope(), self.filename, name, visibility, self.namespace_stack, quiet=self.quiet) body = list(ast.generate()) diff --git a/test_ast.py b/test_ast.py index eeadfc3..92b7842 100755 --- a/test_ast.py +++ b/test_ast.py @@ -596,6 +596,12 @@ def test_variable_initialization_with_complex_expression(self): initial_value='fct()+42'), nodes[0]) + def test_variable_anonymous_class(self): + nodes = list(MakeBuilder('class {public:} a;').generate()) + self.assertEqual(1, len(nodes)) + self.assertEqual(VariableDeclaration('a', Type(Class(None, body=[]))), + nodes[0]) + def test_function_one_argument_with_name(self): for argument in ('Foo f', 'const Foo f', 'Foo& f', 'const Foo& f', 'unsigned int f', 'ns::foo f', 'std::vector f',