cppclean icon indicating copy to clipboard operation
cppclean copied to clipboard

IndexError: pop from empty list

Open DethRaid opened this issue 8 years ago • 7 comments

Ran this on my code base. I handle dependencies as git submodules, so they're all in my working tree and cppclean ran on all of them. It spit out a bunch of warnings, then a stack trace:

Traceback (most recent call last):
  File "/usr/local/bin/cppclean", line 145, in <module>
    sys.exit(main())
  File "/usr/local/bin/cppclean", line 120, in main
    entire_ast = list([_f for _f in builder.generate() if _f])
  File "/usr/local/bin/cppclean", line 120, in <listcomp>
    entire_ast = list([_f for _f in builder.generate() if _f])
  File "/usr/local/lib/python3.5/dist-packages/cpp/ast.py", line 647, in generate
    if self.namespaces.pop():
IndexError: pop from empty list

DethRaid avatar Nov 01 '17 05:11 DethRaid

I'm seeing the same issue, with the same stack trace (although I'm on Python 3.6).

pgcrooks avatar Jul 03 '18 08:07 pgcrooks

I'm getting this issue as well, using Python 2.7, with a similar but longer stacktrace:

 File "c:\Python27\lib\runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "c:\Python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Python27\Scripts\cppclean.py", line 145, in <module>
    sys.exit(main())
  File "C:\Python27\Scripts\cppclean.py", line 138, in main
    quiet=args.quiet):
  File "c:\Python27\lib\site-packages\cpp\find_warnings.py", line 597, in run
    hunter.find_warnings()
  File "c:\Python27\lib\site-packages\cpp\find_warnings.py", line 126, in find_warnings
    self._find_source_warnings()
  File "c:\Python27\lib\site-packages\cpp\find_warnings.py", line 542, in _find_source_warnings
    included_files, forward_declarations = self._read_and_parse_includes()
  File "c:\Python27\lib\site-packages\cpp\find_warnings.py", line 177, in _read_and_parse_includes
    module = self._get_module(node)
  File "c:\Python27\lib\site-packages\cpp\find_warnings.py", line 151, in _get_module
    ast_list = [_f for _f in builder.generate() if _f]
  File "c:\Python27\lib\site-packages\cpp\ast.py", line 651, in generate
    result = self._generate_one(token)
  File "c:\Python27\lib\site-packages\cpp\ast.py", line 675, in _generate_one
    return method()
  File "c:\Python27\lib\site-packages\cpp\ast.py", line 1177, in handle_class
    return self._handle_class_and_struct(Class)
  File "c:\Python27\lib\site-packages\cpp\ast.py", line 1174, in _handle_class_and_struct
    return self._get_class(class_type, None)
  File "c:\Python27\lib\site-packages\cpp\ast.py", line 1486, in _get_class
    body = list(ast.generate())
  File "c:\Python27\lib\site-packages\cpp\ast.py", line 651, in generate
    result = self._generate_one(token)
  File "c:\Python27\lib\site-packages\cpp\ast.py", line 675, in _generate_one
    return method()
  File "c:\Python27\lib\site-packages\cpp\ast.py", line 1180, in handle_struct
    return self._handle_class_and_struct(Struct)
  File "c:\Python27\lib\site-packages\cpp\ast.py", line 1174, in _handle_class_and_struct
    return self._get_class(class_type, None)
  File "c:\Python27\lib\site-packages\cpp\ast.py", line 1486, in _get_class
    body = list(ast.generate())
  File "c:\Python27\lib\site-packages\cpp\ast.py", line 647, in generate
    if self.namespaces.pop():
IndexError: pop from empty list

regomatic avatar Jul 25 '18 18:07 regomatic

Already fixed, likely by https://github.com/myint/cppclean/commit/4d695a63cd74f9fc434a4626430d6a353e6f7eba

Ede123 avatar Sep 23 '18 14:09 Ede123

Hi,

I installed using 'pip install --upgrade cppclean' with python 2.7.6 and I still got this error.

I saw that it was fixed on Github, but it installed an older version of 'ast.py' which doesn't contain the fix.

TomerJLevy avatar Jul 30 '19 07:07 TomerJLevy

I am now receiving this error.

Traceback (most recent call last):
  File "/home/stack/.local/bin/cppclean", line 166, in <module>
    sys.exit(main())
  File "/home/stack/.local/bin/cppclean", line 155, in main
    if module.run(filename, source, entire_ast,
  File "/home/stack/.local/lib/python3.9/site-packages/cpp/find_warnings.py", line 633, in run
    hunter.find_warnings()
  File "/home/stack/.local/lib/python3.9/site-packages/cpp/find_warnings.py", line 129, in find_warnings
    self._find_source_warnings()
  File "/home/stack/.local/lib/python3.9/site-packages/cpp/find_warnings.py", line 575, in _find_source_warnings
    included_files, forward_declarations = self._read_and_parse_includes()
  File "/home/stack/.local/lib/python3.9/site-packages/cpp/find_warnings.py", line 182, in _read_and_parse_includes
    module = self._get_module(node)
  File "/home/stack/.local/lib/python3.9/site-packages/cpp/find_warnings.py", line 156, in _get_module
    ast_list = [_f for _f in builder.generate() if _f]
  File "/home/stack/.local/lib/python3.9/site-packages/cpp/find_warnings.py", line 156, in <listcomp>
    ast_list = [_f for _f in builder.generate() if _f]
  File "/home/stack/.local/lib/python3.9/site-packages/cpp/ast.py", line 675, in generate
    result = self._generate_one(token)
  File "/home/stack/.local/lib/python3.9/site-packages/cpp/ast.py", line 702, in _generate_one
    return method()
  File "/home/stack/.local/lib/python3.9/site-packages/cpp/ast.py", line 1440, in handle_template
    return self._get_class(Class,
  File "/home/stack/.local/lib/python3.9/site-packages/cpp/ast.py", line 1558, in _get_class
    body = list(ast.generate())
  File "/home/stack/.local/lib/python3.9/site-packages/cpp/ast.py", line 675, in generate
    result = self._generate_one(token)
  File "/home/stack/.local/lib/python3.9/site-packages/cpp/ast.py", line 702, in _generate_one
    return method()
  File "/home/stack/.local/lib/python3.9/site-packages/cpp/ast.py", line 1457, in handle_template
    return self.get_method(FUNCTION_NONE, templated_types)
  File "/home/stack/.local/lib/python3.9/site-packages/cpp/ast.py", line 947, in get_method
    return self._get_method(
  File "/home/stack/.local/lib/python3.9/site-packages/cpp/ast.py", line 994, in _get_method
    name = return_type_and_name.pop()
IndexError: pop from empty list

Installed today with pip install --upgrade cppclean

StackDoubleFlow avatar Mar 13 '21 00:03 StackDoubleFlow

I am getting the same error as StackDoubleFlow.

DJMcMayhem avatar Sep 29 '23 21:09 DJMcMayhem

OK, after some further investigation, it appears that this happens because of the spaceship operator. This is the line of code that causes cppclean to get tripped up for me:

    friend int operator<=>(const VersionNumber &a, const VersionNumber &b);

DJMcMayhem avatar Sep 29 '23 22:09 DJMcMayhem