diff --git a/wpiformat/wpiformat/cidentlist.py b/wpiformat/wpiformat/cidentlist.py index e71ed8e..62ead08 100644 --- a/wpiformat/wpiformat/cidentlist.py +++ b/wpiformat/wpiformat/cidentlist.py @@ -38,12 +38,16 @@ def run_pipeline(self, config_file, name, lines): # # "def\\s+\w+" matches preprocessor directives "#ifdef" and "#ifndef" so # their contents aren't used as a return type. + # + # "\w+\**\s+\w+\s*" matches a function return type with 0 or more + # trailing asterisks, spaces, a function name, then spaces before the + # open parenthesis preproc_str = r"#else|#endif|" comment_str = r"/\*|\*/|//|" + linesep + r"|" string_str = r"\\\\|\\\"|\"|" char_str = r"\\'|'|" extern_str = r"(?Pextern \"C(\+\+)?\")\s+(?P\{)?|" - braces_str = r"\{|\}|;|def\s+\w+|\w+\s+\w+\s*(?P\(\))" + braces_str = r"\{|\}|;|def\s+\w+|\w+\**\s+\w+\s*(?P\(\))" postfix_str = r"(?=\s*(;|\{))" token_regex = regex.compile( preproc_str diff --git a/wpiformat/wpiformat/test/test_cidentlist.py b/wpiformat/wpiformat/test/test_cidentlist.py index 0f98774..39fa775 100644 --- a/wpiformat/wpiformat/test/test_cidentlist.py +++ b/wpiformat/wpiformat/test/test_cidentlist.py @@ -484,4 +484,14 @@ def test_cidentlist(): ) test.add_latest_input_as_output(True) + # Ensure extern "C" function with pointer return type gets matched + test.add_input( + "./Test.cpp", + 'extern "C" void* func() {}' + os.linesep, + ) + test.add_output( + 'extern "C" void* func(void) {}' + os.linesep, + True, + ) + test.run(OutputType.FILE)