<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 --- - clang and GCC disagree on attribute usage for explicitly instantiated templates"
   href="https://llvm.org/bugs/show_bug.cgi?id=24815">24815</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang and GCC disagree on attribute usage for explicitly instantiated templates
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Linux
          </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++11
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>dcheng@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Sorry, I don't really know the build magic so I don't have any good examples.
In Chrome, we have some templated classes with explicit instantiations that
look something like this:

#define EXPORT __attribute((visibility("default")))
template <class T>
class EXPORT Property {
  // ...
};

extern template class Property<uint8>;
extern template class Property<bool>;
// etc

When building with clang, uses of the explicitly instantiated templates outside
the shared library fail to link: the linker complains that there are undefined
references to Property<uint8>'s constructor, destructor, etc.

To fix this for clang, I tried exporting the explicit template instantiations:
extern template class EXPORT Property<uint8>;
extern template class EXPORT Property<bool>;


But now this doesn't compile in GCC:
../../dbus/property.h:437:42: error: type attributes ignored after type is
already defined [-Werror=attributes]
 extern template class CHROME_DBUS_EXPORT Property<uint8>;
                                          ^
../../dbus/property.h:447:42: error: type attributes ignored after type is
already defined [-Werror=attributes]
 extern template class CHROME_DBUS_EXPORT Property<bool>;

It turns out GCC ignores attributes on explicit template instantiations
(<a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=17470">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=17470</a>): their fix for this was to
change it so the original template definition controls visibility, and any
attributes on explicit instantiations are ignored (and trigger a
warning/error).</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>