[PATCH] D46190: For a used declaration, mark any associated usings as referenced.

Carlos Alberto Enciso via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 4 04:58:42 PDT 2018


CarlosAlbertoEnciso added inline comments.


================
Comment at: lib/Sema/Sema.cpp:1884-1885
+      ND = NA->getAliasedNamespace();
+      if (auto *NNS = NA->getQualifier())
+        MarkNamespaceAliasReferenced(NNS->getAsNamespaceAlias());
+    }
----------------
rsmith wrote:
> The loop and recursion here -- and indeed this whole function -- seem unnecessary.
> 
> ```
> namespace A {} // #1 
> namespace X {
>   namespace B = A; // #2
> }
> namespace Y = X; // #3
> namespace C = Y::B; // #4
> ```
> 
> Declaration `#4` should mark `#2` and `#3` referenced. So the only 'unreferenced namespace alias' warning we should get here is for `#4` -- and there is no need for marking `#4` as referenced to affect `#2` or `#3`.
The function and recursion is to be able to handle cases like:

```
namespace N {
  int var;
}

void Foo() {
  namespace NA = N;
  namespace NB = NA;
  NB::var = 4;
}
```
'var' is referenced and N, NA and NB should be marked as 'referenced' as well.



================
Comment at: lib/Sema/Sema.cpp:1890-1891
+
+/// \brief Mark as referenced any 'using declaration' that have introduced
+/// the given declaration in the current context.
+void Sema::MarkUsingReferenced(Decl *D, CXXScopeSpec *SS, Expr *E) {
----------------
rsmith wrote:
> Why is this ever appropriate? I would think we should just mark the named declaration from the relevant lookup as referenced in all cases.
My intention is to detect cases where the using statements do not affect other declarations.

```
namespace N {
  int var;
}

void Foo() {
  using N::var;    <- No Referenced
  N::var = 1;      <- Used
}
```



https://reviews.llvm.org/D46190





More information about the cfe-commits mailing list