[llvm-bugs] [Bug 44305] New: Wmissing-variable-declarations and Wmissing-prototypes should also suggest inline

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Dec 15 09:15:01 PST 2019


https://bugs.llvm.org/show_bug.cgi?id=44305

            Bug ID: 44305
           Summary: Wmissing-variable-declarations and Wmissing-prototypes
                    should also suggest inline
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: david at doublewise.net
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

<source>:1:5: warning: no previous extern declaration for non-static variable
'x' [-Wmissing-variable-declarations]

int x = 5;

    ^

<source>:1:1: note: declare 'static' if the variable is not intended to be used
outside of this translation unit

int x = 5;

^

<source>:3:6: warning: no previous prototype for function 'f'
[-Wmissing-prototypes]

void f() {}

     ^

<source>:3:1: note: declare 'static' if the function is not intended to be used
outside of this translation unit

void f() {}

^

static 

2 warnings generated.

Compiler returned: 0




The warning message just suggests "static" if the variable / function is not
supposed to be used outside of this translation unit. This is not the best fix
for things declared in headers, where the suggestion should be to declare them
inline (variables in C++17 mode). Ideally, the compiler would be smart and see
that this variable / function arrived in the current translation unit via
`include` and tell me to use inline in that case, otherwise tell me to use
static.

This is somewhat related to https://bugs.llvm.org/show_bug.cgi?id=17566, which
is complaining about the emphasis of "extern" on a variable declaration,
despite that usage being (probably?) less common than static variables.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191215/70ced4f8/attachment.html>


More information about the llvm-bugs mailing list