Skip to content

Commit

Permalink
Skip the preprocessor macros when parsing initializer lists instead o…
Browse files Browse the repository at this point in the history
…f crashing. (#139)
  • Loading branch information
velmafia authored and myint committed Nov 4, 2018
1 parent e7da41e commit c36c147
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cpp/ast.py
Expand Up @@ -1090,6 +1090,10 @@ def _get_method(self, return_type_and_name, modifiers, templated_types,
initializers = {}
if token.name == ':':
while token.name != ';' and token.name != '{':
# skip preprocesors macros
if token.name.startswith(('#if', '#elif', '#else', '#endif')):
token = self._get_next_token()
continue
member, token = self.get_name()
member = member[0]
if token.name == '(' or token.name == '{':
Expand Down
14 changes: 14 additions & 0 deletions test/ctor_init_list.h
@@ -0,0 +1,14 @@
class Foo {
public:
int first,
#if defined(TEST)
int second;
#endif
};

Foo::Foo():
first(1)
#if defined(TEST) // this 3 lines
,second(2) // generated
#endif // IndexError: list index out of range
{}

0 comments on commit c36c147

Please sign in to comment.