[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
Tue Mar 27 02:47:53 PDT 2018


CarlosAlbertoEnciso added a comment.

In https://reviews.llvm.org/D44826#1046906, @dblaikie wrote:

>


First of all, thanks very much for your feedback.

> While implementing the warning is great (wonder if there's any codebase
>  that isn't -Wunused-using clean, that we could use to compare Clang and
>  GCC's behavior broadly - make sure it's catching the same cases (or
>  justify/investigate differences)) - and using it to motivate the debug info
>  is an improvement to the debug info - it won't quite address all the wasted
>  debug info, unfortunately :/

You are making a very good point. The -Wunused-using is just addressing
one of the factors affecting the debug info size.

> Consider this:
> 
> namespace a {
> 
>   struct b;
> 
> };
>  namespace x {
> 
>   using a::b;
>   inline void f(b*) {
>   }
> 
> }
> 
> Now the using declaration is used, but if 'f' is never called in this
>  translation unit, it's a bit weird to produce debug info for the using decl
>  and could still substantially bloat debug info. (indeed most of the bloat
>  that the using decl/directive debug info is producing is probably from
>  directives that are used, but not in a way that's relevant to a certain
>  translation unit)

The modified patch catches that 'referenced' but 'unused' using declaration.

> I've not looked at the change yet, but if it's particularly
>  expensive/complicated to wire up the debug info side, it might not be worth
>  it given it's probably not a significant savings & somewhat of a dead-end
>  compared to what would be needed for a more complete fix. But I guess it's
>  probably not expensive/complicated, so probably some fine low hanging fruit
>  to pick until a more complete fix/improvement is implemented.

The warning generation check is done at the point where a lexical scope
is closed and it does not 'see' further changes on the same using after that
point.

The second part (do not generate debug info) uses a similar approach, with
the only difference that the checks and debug info generation is done at
the end of the compilation unit, when more information is available.


Repository:
  rC Clang

https://reviews.llvm.org/D44826





More information about the cfe-commits mailing list