[PATCH] D46190: For an ODR declaration, set the 'Used' bit on its associated declarations.

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 30 15:20:36 PDT 2018


rsmith added a comment.

In https://reviews.llvm.org/D46190#1082616, @CarlosAlbertoEnciso wrote:

> My initial approach was based on the following test case:
>
>   void Bar() {
>     typedef int I_Ref;
>     I_Ref var_bar;
>   }
>  
>   void Foo() {
>     typedef int I_Used;
>     I_Used var_foo;
>     var_foo = 2;
>   }
>  
>   void Test() {
>     Foo();
>   }
>


[...]

> The typedef 'I_Ref' is marked as 'referenced' due to its association with 'var_bar'.
>  The typedef 'I_Used' is marked as 'referenced' despite that its association with 'var_foo' which is 'used'
>  Both 'typedefs' are marked as 'referenced'.

This is already the correct outcome. Both typedefs are referenced; this is correct because they are named by the source code. Neither typedef is marked as "used"; this is correct because a typedef cannot be odr-used.

Let's look at your original example again (I've cleaned it up and extended it a bit, but hopefully this matches your intent):

  namespace nsp {
    int var1, var2;
  }
  
  using nsp::var1;
  using nsp::var2;
  
  void bar() {
    nsp::var1 = 1;
    var2 = 1;
  }

Now, what should happen here is:

- The use of `nsp::var1` in `bar` marks `nsp::var1` as referenced (because it was named), and marks `nsp::var1` as used (because it was odr-used by the assignment). The `UsingShadowDecl` for `::var1` is not marked as referenced (nor used), so we emit an unused-using-declaration warning.
- The use of `var2` in `bar` marks `::var2` as referenced (because it was named), and marks `nsp::var2` as used (because it was odr-used by the assignment). The `UsingShadowDecl` for `::var2` is marked as referenced, so we do not warn on it.


Repository:
  rC Clang

https://reviews.llvm.org/D46190





More information about the cfe-commits mailing list