<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><span class="vcard"><a class="email" href="mailto:rnk@google.com" title="Reid Kleckner <rnk@google.com>"> <span class="fn">Reid Kleckner</span></a>
</span> changed
              <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - "extern template" seems to invoke explicit instanciation but it should prohibit it."
   href="http://llvm.org/bugs/show_bug.cgi?id=20825">bug 20825</a>
        <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">Status</td>
           <td>NEW
           </td>
           <td>RESOLVED
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">CC</td>
           <td>
                
           </td>
           <td>rnk@google.com
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Resolution</td>
           <td>---
           </td>
           <td>INVALID
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - "extern template" seems to invoke explicit instanciation but it should prohibit it."
   href="http://llvm.org/bugs/show_bug.cgi?id=20825#c1">Comment # 1</a>
              on <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - "extern template" seems to invoke explicit instanciation but it should prohibit it."
   href="http://llvm.org/bugs/show_bug.cgi?id=20825">bug 20825</a>
              from <span class="vcard"><a class="email" href="mailto:rnk@google.com" title="Reid Kleckner <rnk@google.com>"> <span class="fn">Reid Kleckner</span></a>
</span></b>
        <pre>I think you can forward declare your specialization of the static data member
like so:

// Start .h
template <typename T> class A {
public:
  static const char *info;
};

template <> const char *A<int>::info;
template <> const char *A<char>::info;

extern template class A<int>;
extern template class A<char>;

// Start .cpp
#include <iostream>

template <> const char *A<int>::info = "This is int";
template <> const char *A<char>::info = "This is char";

int main(int, char **) {
  std::cout << "A<int>:" << A<int>::info << "\n";
  std::cout << "A<char>:" << A<char>::info << "\n";
  return 0;
}

template class A<int>;
template class A<char>;

----

Otherwise, the compiler can do things like inline the generic, unspecialized
version of an inline function into your program.  Consider:

template <typename T>
struct A { static int f() { return sizeof(int); } };
extern template struct A<int>;
int main() {
  return A<int>::f();
}

After optimizations, main will return 4, even if some other TU contains:

template <> int A<int>::f() { return 5; };

This specialization can be similarly forward declared as:

template <> int A<int>::f();</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>