Overly zealous warning from -Wmissing-prototypes

Hi cfe-dev. I believe I’ve found a bug in Clang’s -Wmissing-prototypes warning.

Consider the following C++ code:

void global() {}

namespace { void anonymous() {} }

namespace detail { void detail() {} }

namespace detail { namespace { void detail_anonymous() {} } }

namespace { namespace detail { void anonymous_detail() {} } }

When compiled with GCC -Wmissing-declarations, the functions global() and

detail() give warnings. However, when compiled with Clang -Wmissing-prototypes,

global(), detail() and anonymous_detail() all give warnings. Despite this,

Clang is unable to optimize out anonymous_detail() when it’s unused

As an aside: GCC uses ‘-Wmissing-declarations’ to warn if a global function is

defined without a previous declaration and ‘-Wmissing-prototypes’ only to warn

in C/Obj-C cases where a function has a previous declaration that’s not a

prototype. Clang uses ‘-Wmissing-prototypes’ for both of these, and the flag

‘-Wmissing-declarations’ is enabled by default and applies to miscellaneous

other cases.

I’ve filed a Bugzilla bug at https://bugs.llvm.org/show_bug.cgi?id=33141 .

Thanks,

Abigail