https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128018

            Bug ID: 128018
           Summary: Warnings for static in inline should have an option to
                    disable them
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rasheeqhere at gmail dot com
  Target Milestone: ---

GCC produces a warning for this code that cannot be turned off except with -w:

    static inline int foo() { return 42;    }
    inline        int bar() { return foo(); }

This makes sense pre-C2y, since ISO C23 and earlier expressly forbid non-static
inline functions from referring to names with internal linkage, and also from
defining static local variables.

These restrictions have been removed for C2y with N3622. However, gcc continues
to emit these warnings at -std=c2y. Implementations are of course free to
continue diagnosing this situation, but there ought to be a way to turn off the
warning now, for those cases where the programmer has determined there to be no
problem.

The way Clang does it, the two cases of the warning (reference to static
file-scope declaration in inline vs. definition of static local in inline) have
different names, -Wstatic-in-inline and -Wstatic-local-in-inline. The first one
is always off by default, and the second one is always on by default. GCC could
also support both options, but leave both of them on by default to preserve its
current behavior.

Reply via email to