Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcc incompatiblity: -Wunused-functions warns about unused functions in unnamed namespaces #10158

Closed
nico opened this issue Apr 24, 2011 · 2 comments
Labels
bugzilla Issues migrated from bugzilla c++ clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer wontfix Issue is real, but we can't or won't fix it. Not invalid

Comments

@nico
Copy link
Contributor

nico commented Apr 24, 2011

Bugzilla Link 9786
Resolution WONTFIX
Resolved on Apr 23, 2011 22:41
Version unspecified
OS All
CC @akyrtzi,@DougGregor

Extended Description

$ cat test.cc
namespace {
void f() {}
}
$ gcc -Wunused-functions test.cc
$ clang -Wunused-functions test.cc
test.cc:2:6: warning: unused function 'f' [-Wunused-function]
void f() {}
^
1 warning generated.

clang r129794 suggests that clang tries to be compatible with gcc here, so this warning should be moved to -Wunneeded-internal-declaration.

@akyrtzi
Copy link
Contributor

akyrtzi commented Apr 24, 2011

$ cat test.cc
namespace {
void f() {}
}
$ gcc -Wunused-functions test.cc
$ clang -Wunused-functions test.cc
test.cc:2:6: warning: unused function 'f' [-Wunused-function]
void f() {}
^
1 warning generated.

clang r129794 suggests that clang tries to be compatible with gcc here, so this
warning should be moved to -Wunneeded-internal-declaration.

r129794 is more gcc compatible in that there is no -Wunused-function warning emitted if you reference the function anywhere, e.g:

static void foo() {}

template
void tf() {
foo();
}

clang would show that 'foo' is unused while gcc would show nothing. After r129794 this becomes -Wunneeded-internal-declaration which is much more clear. Also warning for these cases can be disabled separate from -Wunused-function.

In general, warning about unused functions in unnamed namespaces is works-as-expected IMO, unless there is a compelling argument against it.

@nico
Copy link
Contributor Author

nico commented Apr 24, 2011

Fair enough.

If -Wunneeded-internal-declaration wasn't introduced to make -Wunused-function gcc-compatible, then the difference between these two flags is pretty subtle imho. Oh well :-)

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
@Quuxplusone Quuxplusone added clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer wontfix Issue is real, but we can't or won't fix it. Not invalid labels Jan 18, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++ clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer wontfix Issue is real, but we can't or won't fix it. Not invalid
Projects
None yet
Development

No branches or pull requests

3 participants