<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - function static variable instantiated at -O2 despite extern template"
   href="https://bugs.llvm.org/show_bug.cgi?id=45351">bug 45351</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 - function static variable instantiated at -O2 despite extern template"
   href="https://bugs.llvm.org/show_bug.cgi?id=45351#c1">Comment # 1</a>
              on <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - function static variable instantiated at -O2 despite extern template"
   href="https://bugs.llvm.org/show_bug.cgi?id=45351">bug 45351</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>Clang is allowed to do this inlining. I can't site the standard, but this came
up for me personally while adding extern template decls to LLVM.

Function templates that are declared extern can be inlined if they are marked
inline. Defining a method inside a class body implicitly makes it inline. So,
to avoid the inlining without resorting to fno-inline, write the code like
this:

template <typename T>
struct S {
  int func();
};

template <typename T>
int S<T>::func() {
  static int function_local_static = 0;
  return ++function_local_static;
}

extern template class S<int>;

int user()
{
    return S<int>().func();
}

This will prohibit instantiation of S::func and even allow you to specialize it
out of line.</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>