[llvm-bugs] [Bug 24815] New: clang and GCC disagree on attribute usage for explicitly instantiated templates

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Sep 14 13:13:53 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=24815

            Bug ID: 24815
           Summary: clang and GCC disagree on attribute usage for
                    explicitly instantiated templates
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: dcheng at google.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

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
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=17470): 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).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150914/06ef182d/attachment.html>


More information about the llvm-bugs mailing list