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

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 18 13:18:58 PDT 2018


rsmith added a comment.

The right way to handle this is to pass both the ultimately-selected declaration and the declaration found by name lookup into the calls to `MarkAnyDeclReferenced` and friends. We should mark the selected declaration as `Used` (when appropriate), and mark the found declaration as `Referenced`.

We should not be trying to reconstruct which using declarations are in scope after the fact. Only declarations actually found by name lookup and then selected by the context performing the lookup should be marked referenced. (There may be cases where name lookup discards equivalent lookup results that are not redeclarations of one another, though, and to handle such cases properly, you may need to teach name lookup to track a list of found declarations rather than only one.)



================
Comment at: lib/Sema/Sema.cpp:1884-1885
+      ND = NA->getAliasedNamespace();
+      if (auto *NNS = NA->getQualifier())
+        MarkNamespaceAliasReferenced(NNS->getAsNamespaceAlias());
+    }
----------------
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`.


================
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) {
----------------
Why is this ever appropriate? I would think we should just mark the named declaration from the relevant lookup as referenced in all cases.


https://reviews.llvm.org/D46190





More information about the cfe-commits mailing list