Skip to content

Commit 3fec1c7

Browse files
authored
Fix C identifier lists for functions returning pointers (#255)
1 parent c5357db commit 3fec1c7

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

wpiformat/wpiformat/cidentlist.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@ def run_pipeline(self, config_file, name, lines):
3838
#
3939
# "def\\s+\w+" matches preprocessor directives "#ifdef" and "#ifndef" so
4040
# their contents aren't used as a return type.
41+
#
42+
# "\w+\**\s+\w+\s*" matches a function return type with 0 or more
43+
# trailing asterisks, spaces, a function name, then spaces before the
44+
# open parenthesis
4145
preproc_str = r"#else|#endif|"
4246
comment_str = r"/\*|\*/|//|" + linesep + r"|"
4347
string_str = r"\\\\|\\\"|\"|"
4448
char_str = r"\\'|'|"
4549
extern_str = r"(?P<ext_decl>extern \"C(\+\+)?\")\s+(?P<ext_brace>\{)?|"
46-
braces_str = r"\{|\}|;|def\s+\w+|\w+\s+\w+\s*(?P<paren>\(\))"
50+
braces_str = r"\{|\}|;|def\s+\w+|\w+\**\s+\w+\s*(?P<paren>\(\))"
4751
postfix_str = r"(?=\s*(;|\{))"
4852
token_regex = regex.compile(
4953
preproc_str

wpiformat/wpiformat/test/test_cidentlist.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,4 +484,14 @@ def test_cidentlist():
484484
)
485485
test.add_latest_input_as_output(True)
486486

487+
# Ensure extern "C" function with pointer return type gets matched
488+
test.add_input(
489+
"./Test.cpp",
490+
'extern "C" void* func() {}' + os.linesep,
491+
)
492+
test.add_output(
493+
'extern "C" void* func(void) {}' + os.linesep,
494+
True,
495+
)
496+
487497
test.run(OutputType.FILE)

0 commit comments

Comments
 (0)