Skip to content

Instantly share code, notes, and snippets.

@abigailbunyan
Created May 23, 2017 09:08
Show Gist options
  • Save abigailbunyan/539cffa79465e0fc5db6170f1ab2c085 to your computer and use it in GitHub Desktop.
Save abigailbunyan/539cffa79465e0fc5db6170f1ab2c085 to your computer and use it in GitHub Desktop.
Clang overly zealous -Wmissing-prototypes warning
void global() {}
namespace { void anonymous() {} }
namespace detail { void detail() {} }
namespace detail { namespace { void detail_anonymous() {} } }
namespace { namespace detail { void anonymous_detail() {} } }
$ clang++-5.0 -Wmissing-declarations -Wmissing-prototypes test.cpp -c
test.cpp:1:6: warning: no previous prototype for function 'global' [-Wmissing-prototypes]
void global() {}
^
test.cpp:3:25: warning: no previous prototype for function 'detail' [-Wmissing-prototypes]
namespace detail { void detail() {} }
^
test.cpp:5:37: warning: no previous prototype for function 'anonymous_detail' [-Wmissing-prototypes]
namespace { namespace detail { void anonymous_detail() {} } }
^
3 warnings generated.
$ clang++-5.0 --version
clang version 5.0.0-svn303516-1~exp1 (trunk)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ g++-6 -Wmissing-declarations -Wmissing-prototypes -c test.cpp
cc1plus: warning: command line option ‘-Wmissing-prototypes’ is valid for C/ObjC but not for C++
test.cpp: In function ‘void global()’:
test.cpp:1:6: warning: no previous declaration for ‘void global()’ [-Wmissing-declarations]
void global() {}
^~~~~~
test.cpp: In function ‘void detail::detail()’:
test.cpp:3:25: warning: no previous declaration for ‘void detail::detail()’ [-Wmissing-declarations]
namespace detail { void detail() {} }
^~~~~~
$ g++-6 --version
g++-6 (Ubuntu 6.3.0-12ubuntu2) 6.3.0 20170406
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@abigailbunyan
Copy link
Author

I think it's a bug here that anonymous_detail is warned on by Clang. The intent of -Wmissing-declarations/-Wmissing-prototypes is that it warns on functions which should be marked static or moved to an anonymous namespace, but anonymous_detail is already indirectly in an anonymous namespace.

@abigailbunyan
Copy link
Author

gcc.godbolt.org shows that both GCC and Clang do correctly remove anonymous_detail: https://godbolt.org/g/CwrbQa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment