Skip to content

RuntimeError: generator raised StopIteration for a very simple code #159

@romintomasetti

Description

@romintomasetti

I came across a code for which cppclean stops prematurely with

Traceback (most recent call last):
  File "/home/romin/.local/lib/python3.8/site-packages/cpp/ast.py", line 887, in _get_matching_char
    token = get_next_token()
  File "/home/romin/.local/lib/python3.8/site-packages/cpp/ast.py", line 904, in _get_next_token
    return next(self.tokens)
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/romin/.local/bin/cppclean", line 166, in <module>
    sys.exit(main())
  File "/home/romin/.local/bin/cppclean", line 139, in main
    entire_ast = list([_f for _f in builder.generate() if _f])
  File "/home/romin/.local/bin/cppclean", line 139, in <listcomp>
    entire_ast = list([_f for _f in builder.generate() if _f])
  File "/home/romin/.local/lib/python3.8/site-packages/cpp/ast.py", line 675, in generate
    result = self._generate_one(token)
  File "/home/romin/.local/lib/python3.8/site-packages/cpp/ast.py", line 702, in _generate_one
    return method()
  File "/home/romin/.local/lib/python3.8/site-packages/cpp/ast.py", line 1246, in handle_class
    return self._handle_class_and_struct(Class)
  File "/home/romin/.local/lib/python3.8/site-packages/cpp/ast.py", line 1243, in _handle_class_and_struct
    return self._get_class(class_type, None)
  File "/home/romin/.local/lib/python3.8/site-packages/cpp/ast.py", line 1601, in _get_class
    return self._get_method(name_tokens, 0, None, False)
  File "/home/romin/.local/lib/python3.8/site-packages/cpp/ast.py", line 1009, in _get_method
    parameters = list(self._get_parameters())
RuntimeError: generator raised StopIteration

A MWE might be

#ifdef MYDEFINE
class Any
#else
class Any final
#endif
{
    public:
        Any(){};
};

int main()
{
    Any a;
    return 0;
} 

The problem is clearly caused by the #ifdef ... #endif statement surrounding the class.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions