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

            Bug ID: 90493
           Summary: const variable template specialization is always local
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rafael at espindo dot la
  Target Milestone: ---

Without templates, things are simple:

// this is local
const int bar = 42;

// this is global
extern const int bar = 42;

Just adding a template is also OK

// this is local
template <typename T> const int foo = 42;

// this is global
template <typename T> extern const int foo = 42;

But with specializations there doesn't seem to be any way of getting a global
symbol

template <typename T> extern const int foo = 41;
// this is local
template <> const int foo<int> = 42;

// this is an error:
// error: explicit template specialization cannot have a storage class
template <> extern const int foo<int> = 42;


clang both accept the storage class in the specialization and always produces a
global symbol for template variables. Maybe doing both is a bug in clang, but
we should have some way of defining a global variable template specialization.

Reply via email to