<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW " title="NEW --- - Tag lookup should not find hidden declarations" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D23748&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=KO7VAw6gIlP1MTyGixCgMk6b3P435rAWBds4nl9KC1E&s=SB9xUgIGTju3IXtx6W2fwoiFgqDTosy5DuJCqwneIHU&e=">23748</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Tag lookup should not find hidden declarations
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Modules
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>rjmccall@apple.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=14432" name="attach_14432" title="a test case demonstrating the problem">attachment 14432</a> <a href="attachment.cgi?id=14432&action=edit" title="a test case demonstrating the problem">[details]</a></span>
a test case demonstrating the problem

Currently, LookupResult::isHiddenDeclarationVisible() is defined as follows:

  bool isHiddenDeclarationVisible() const {
    return AllowHidden || LookupKind == Sema::LookupTagName;
  }

This is trying to ensure that elaborated type specifiers are linked into
existing declaration chains even if those declarations are hidden.  This is
necessary in C because we don't perform a second redeclaration lookup when the
initial lookup didn't find anything.  (It's not necessary in C++ because we
have to perform that redeclaration lookup anyway, because of friends.)

Unfortunately, it can lead to incorrect results if the tag lookup finds
something hidden in an inner scope when it should have found something
non-hidden in an outer scope.  That can't happen in C because there's only one
open scope to which modules can add declarations, the global scope; but it can
happen in C++ because of namespaces.

I've attached a simple testcase which reproduces the problem.  The code should
compile because the elaborated type specifier should find the non-hidden
declaration ::A from Module.h instead of the hidden declaration ns::A from
Submodule.h.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>