[PATCH] D44826: Add -Wunused-using, a warning that finds unused using declarations.
Carlos Alberto Enciso via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 23 06:35:08 PDT 2018
CarlosAlbertoEnciso created this revision.
CarlosAlbertoEnciso added reviewers: rsmith, erichkeane, probinson, dblaikie.
CarlosAlbertoEnciso added a project: clang.
Herald added subscribers: cfe-commits, JDevlieghere, aprantl.
Add -Wunused-using, a warning that finds unused using declarations.
Also added an alias -Wunused-usings.
This patch uses a similar approach as the work done for the typedefs
as discussed in:
https://reviews.llvm.org/rC217298
It uses the 'used' and 'referenced' available bits for the declarations.
As consequence of a previous work on Debug Information done by:
https://reviews.llvm.org/D6173
The size of the Debug Information increased by a considerable factor,
as discussed in:
http://clang-developers.42468.n3.nabble.com/r222220-causes-real-debug-info-bloat-td4045257.html
For the below test:
namespace nsp {
void foo();
}
using foo;
A debug information entries are generated for the namespace
and for the using declaration.
In order to reduce the debug information for those specific cases,
the work is divided in 2 parts:
- Emit a warning for the unused using
- Do not generate debug information for the unused using
The current patch deals with the first part and it covers global
and local detection of unused using declarations.
For the below test, I have marked the generated warnings
namespace nsp {
void foo();
int var;
}
using foo; <-- warning
using var; <-- warning
void bar() {
using foo; <-- warning
using var; <-- warning
}
However, there is a specific case, where an unused using
escapes the warning.
Adding the following function 'bar'
void bar() {
nsp::var = 1;
}
it causes the warning to the global unused 'using var'
not being issued, as the assignment sets the 'used' bit,
despite of using the qualified 'var'.
namespace nsp {
void foo();
int var;
}using var
using foo; <-- warning
using var; <-- MISSING warning
void bar() {
using foo; <-- warning
using var; <-- warning
}
void bar() {
nsp::var = 1;
}
Thanks for your view on this issue and on the general approach.
Repository:
rC Clang
https://reviews.llvm.org/D44826
Files:
include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticSemaKinds.td
include/clang/Sema/ExternalSemaSource.h
include/clang/Sema/MultiplexExternalSemaSource.h
include/clang/Sema/Sema.h
include/clang/Serialization/ASTBitCodes.h
include/clang/Serialization/ASTReader.h
lib/Sema/MultiplexExternalSemaSource.cpp
lib/Sema/Sema.cpp
lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclCXX.cpp
lib/Serialization/ASTReader.cpp
lib/Serialization/ASTWriter.cpp
test/FixIt/fixit.cpp
test/Modules/Inputs/module.map
test/Modules/Inputs/warn-unused-using.h
test/Modules/warn-unused-using.cpp
test/SemaCXX/coreturn.cpp
test/SemaCXX/warn-unused-using-serialize.cpp
test/SemaCXX/warn-unused-using.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44826.139581.patch
Type: text/x-patch
Size: 20016 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180323/9d5053c0/attachment-0001.bin>
More information about the cfe-commits
mailing list