One function
CLikeNestingStackStates in terryyin/lizard
The author described this change as “Fix handling of attributes after namespace names”. It counts as a record because the checks below fail on the code as it stood at f24703ad1 and pass on 222af4a63, with nothing else changed between the two runs.
Projectterryyin/lizard
Fix saved2016-09-28
Sharing licenceMIT · LICENSE.txt
Change size+12 −7
What the code was meant to do, written into the code itself as a docstring
Machinery to track nesting levels of tokens. The main indicators of nesting are braces: '{' and '}'. However, the code is complicated due to braceless structures, which are control-flow structures in C-like languages. Moreover, using braces as nesting level indicators leads to a big caveat; C++ initializer lists, uniform initialization, and any other constructs with braces add extra nesting level. Another complication comes from nested classes inside function bodies and control-flow declarations/bodies. The handling of these complex cases is unspecified and can be ignored.
The change
| 80 | 80 | else: | |
| 81 | 81 | self._state = self.__declare_structure | |
| 82 | 82 | ||
| 83 | - | @CodeStateMachine.read_until_then(')({[;') | |
| 84 | - | def _read_namespace(self, token, saved): | |
| 83 | + | def _read_namespace(self, token): | |
| 84 | + | """Processes declarations right after namespace/class keywords.""" | |
| 85 | 85 | if token == "[": | |
| 86 | 86 | self._state = self._read_attribute | |
| 87 | - | self._state(token) | |
| 88 | 87 | else: | |
| 89 | - | self._state = self._state_global | |
| 90 | - | if token == "{": | |
| 91 | - | self.context.add_namespace(''.join(itertools.takewhile( | |
| 92 | - | lambda x: x not in [":", "final"], saved))) | |
| 88 | + | self._state = self._read_namespace_name | |
| 89 | + | self._state(token) | |
| 90 | + | ||
| 91 | + | @CodeStateMachine.read_until_then(')({;') | |
| 92 | + | def _read_namespace_name(self, token, saved): | |
| 93 | + | """Processes namespace/class/struct names from declrations.""" | |
| 94 | + | self._state = self._state_global | |
| 95 | + | if token == "{": | |
| 96 | + | self.context.add_namespace(''.join(itertools.takewhile( | |
| 97 | + | lambda x: x not in [":", "final", "["], saved))) | |
| 93 | 98 | ||
| 94 | 99 | @CodeStateMachine.read_inside_brackets_then("<>", "_state_global") | |
| 95 | 100 | def _template_declaration(self, _): |
The check that tells the two apart
fail→pass·test/test_languages/testCAndCPP.py::Test_cpp11_Attributes::test_class
fail→pass·test/test_languages/testCAndCPP.py::Test_cpp11_Attributes::test_namespace
Check file test/test_languages/testCAndCPP.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before itf24703ad131fd90b7d9e2d2dba555ec4604fcc5f
Broken version dated2016-09-28
Modulelizard_languages.clike
Units changedCLikeNestingStackStates
Fingerprint910b1dcb2ca8035b
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in terryyin/lizard
- 2026-08-08fix(java): do not report control structures as methods
- 2026-07-02HalsteadClassifier
- 2026-07-02fix(csv): emit columns for extensions with multiple FUNCTION_INFO fields
- 2026-06-15fix(golike): register generic functions with [...] type params
- 2026-06-15fix(java): enhance parsing of generic and qualified type names in anonymous classes
- 2026-06-11fix(script): stop a '#' comment continuing past a trailing backslash (#317)