<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - Nested Template Visibility is Not Right"
   href="https://bugs.llvm.org/show_bug.cgi?id=36132">36132</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Nested Template Visibility is Not Right
          </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>C++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>bluechristlove@163.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Code:

#define HIDDEN __attribute__((visibility("hidden")))
#define PROTECTED __attribute__((visibility("protected")))
#define DEFAULT __attribute__((visibility("default")))
template <typename T> class HIDDEN C {
public:
  template <typename U> class PROTECTED D {
  public:
    void f();
  };
};

int main() {
  C<int>::D<int> d;
  d.f();
}

When we compile it and dump the symbol proporty:

Symbol table '.symtab' contains 6 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS c.C
     2: 0000000000000000     0 SECTION LOCAL  DEFAULT    2
     3: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND .TOC.
     4: 0000000000000000     0 NOTYPE  GLOBAL HIDDEN   UND C<int>::D<int>::f()
     5: 0000000000000000    76 FUNC    GLOBAL DEFAULT [<localentry>: 8]     2
main

We can see that function's visibility is HIDDEN. But it should belongs to D's
visibility: PROTECTED.

When we use GCC:
Symbol table '.symtab' contains 12 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS c.C
     2: 0000000000000000     0 SECTION LOCAL  DEFAULT    1
     3: 0000000000000000     0 SECTION LOCAL  DEFAULT    3
     4: 0000000000000000     0 SECTION LOCAL  DEFAULT    4
     5: 0000000000000000     0 SECTION LOCAL  DEFAULT    5
     6: 0000000000000000     0 SECTION LOCAL  DEFAULT    7
     7: 0000000000000000     0 SECTION LOCAL  DEFAULT    8
     8: 0000000000000000     0 SECTION LOCAL  DEFAULT    6
     9: 0000000000000000    84 FUNC    GLOBAL DEFAULT [<localentry>: 8]     1
main
    10: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND .TOC.
    11: 0000000000000000     0 NOTYPE  GLOBAL PROTECTED  UND
C<int>::D<int>::f()
We can see that GCC's behaviour is right.

Additionally, if we don't use nested template, i.e.

#define HIDDEN __attribute__((visibility("hidden")))
#define PROTECTED __attribute__((visibility("protected")))
#define DEFAULT __attribute__((visibility("default")))
  template<typename T>
  class HIDDEN C {
public:
    class PROTECTED D {
public:
      void f();
    };
  };

int main() {
  C<int>::D d;
  d.f();
}

Clang can get the right visibility.</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>