Created
May 23, 2017 09:08
-
-
Save abigailbunyan/539cffa79465e0fc5db6170f1ab2c085 to your computer and use it in GitHub Desktop.
Clang overly zealous -Wmissing-prototypes warning
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void global() {} | |
namespace { void anonymous() {} } | |
namespace detail { void detail() {} } | |
namespace detail { namespace { void detail_anonymous() {} } } | |
namespace { namespace detail { void anonymous_detail() {} } } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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. |
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
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, butanonymous_detail
is already indirectly in an anonymous namespace.