[binutils-gdb] [contrib] Accept _("") and operator() in check_GNU_style_lib.py

Tom de Vries vries@sourceware.org
Thu Nov 20 09:47:06 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4e1825f080b9106ff28c75bfd0d55c93dcd9f674

commit 4e1825f080b9106ff28c75bfd0d55c93dcd9f674
Author: Tom de Vries <tdevries@suse.de>
Date:   Thu Nov 20 10:46:54 2025 +0100

    [contrib] Accept _("") and operator() in check_GNU_style_lib.py
    
    Currently contrib/check_GNU_style_lib.py warns about '_("foo")', expecting
    '_ ("foo")' instead:
    ...
    $ cat tmp.patch
      ...
    +const char *
    +foo (void)
    +{
    +  return _("foo");
    +}
    $ ./contrib/check_GNU_style.py tmp.patch
    === ERROR type #1: there should be exactly one space between function name \
      and parenthesis (1 error(s)) ===
    test.c:4:10:  return _("foo");
    $
    ...
    
    However '_("")' is an exception [1] to the rule, so skip the ERROR in this
    case.
    
    Likewise for 'operator()', which seems common enough:
    ...
    $ find gdb* -type f \
        | egrep -v '/testsuite/|ChangeLog' \
        | xargs grep "::operator()" \
        | wc -l
    27
    ...
    for example in gdb/dwarf2/read.c:
    ...
    dwo_file_hash::operator() (const dwo_file_up &file) const noexcept
    ...
    
    [1] https://sourceware.org/gdb/wiki/Internals%20GDB-C-Coding-Standards#Gettext_macro

Diff:
---
 contrib/check_GNU_style_lib.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/contrib/check_GNU_style_lib.py b/contrib/check_GNU_style_lib.py
index faf30c4d9a2..b069abe88e8 100755
--- a/contrib/check_GNU_style_lib.py
+++ b/contrib/check_GNU_style_lib.py
@@ -164,7 +164,7 @@ class SentenceDotEndCheck:
 class FunctionParenthesisCheck:
     # TODO: filter out GTY stuff
     def __init__(self):
-        self.re = re.compile(r'\w(\s{2,})?(\()')
+        self.re = re.compile(r'\w+(\s{2,})?(\()')
 
     def check(self, filename, lineno, line):
         if '#define' in line:
@@ -172,6 +172,8 @@ class FunctionParenthesisCheck:
 
         m = self.re.search(line)
         if m != None:
+            if m.group() == '_(' or m.group() == 'operator(':
+                return None
             return CheckError(filename, lineno,
                 line[:m.start(2)] + error_string(m.group(2)) + line[m.end(2):],
                 'there should be exactly one space between function name ' \


More information about the Binutils-cvs mailing list