https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92034

            Bug ID: 92034
           Summary: extern template declarations cannot have internal
                    linkage (unnamed namespace)
           Product: gcc
           Version: 9.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: alisdairm at me dot com
  Target Milestone: ---

According to [temp.explicit] p15, final sentence (after the note), 'extern
template' declarations cannot have internal linkage.  That means it would be an
error to declare an 'extern template' instantiation in an unnamed namespace:

namespace {

// define class template
template <class TYPE>
class ExternTemplateClass {};

// don't instantiate in this translation unit
extern template class ExternTemplateClass<char>;

// instantiate in this translation unit
template class ExternTemplateClass<char>;

}  // close unnamed namespace

While this should have been a diagnosable error since C++11, the recently
release Clang 9.0 is the first compiler to diagnose this specific case.  After
looking into breakage updating that compiler, we determined the diagnostic is
correct, so are filing issues against other compilers we use.

An interactive example can be seen online with Compiler Explorer:
   https://godbolt.org/z/Ot3YOd

Reply via email to