<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><span class="vcard"><a class="email" href="mailto:kamikaze@bsdforen.de" title="Dominic Fandrey <kamikaze@bsdforen.de>"> <span class="fn">Dominic Fandrey</span></a>
</span> changed
              <a class="bz_bug_link 
          bz_status_REOPENED "
   title="REOPENED --- - link success with static template member depends on optimisation level"
   href="http://llvm.org/bugs/show_bug.cgi?id=20593">bug 20593</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>RESOLVED
           </td>
           <td>REOPENED
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Resolution</td>
           <td>INVALID
           </td>
           <td>---
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_REOPENED "
   title="REOPENED --- - link success with static template member depends on optimisation level"
   href="http://llvm.org/bugs/show_bug.cgi?id=20593#c3">Comment # 3</a>
              on <a class="bz_bug_link 
          bz_status_REOPENED "
   title="REOPENED --- - link success with static template member depends on optimisation level"
   href="http://llvm.org/bugs/show_bug.cgi?id=20593">bug 20593</a>
              from <span class="vcard"><a class="email" href="mailto:kamikaze@bsdforen.de" title="Dominic Fandrey <kamikaze@bsdforen.de>"> <span class="fn">Dominic Fandrey</span></a>
</span></b>
        <pre>New code, works with -O1 and -O2, shouldn't work, because the uninitialised
static member is used.

--- foo.hpp ---
#ifndef _FOO_HPP_
#define _FOO_HPP_

#include <memory>

template <class T>
class foo {
    private:
    static std::allocator<T> alloc;

    T * const payload;

    public:
    foo(T const val) : payload(foo<T>::alloc.allocate(1)) {
        this->payload[0] = val;
    }

    virtual ~foo() {
        foo<T>::alloc.deallocate(payload, 1);
    }

    T const & getPayload() const {
        return this->payload[0];
    }
};

#endif /* _FOO_HPP_ */

--- main.cpp ---
#include "foo.hpp"
#include <iostream>

int main() {
    foo<int> bar(1337);
    std::cout << &bar.getPayload() << ": " << bar.getPayload() << '\n';
    return 0;
}


<span class="quote">> c++ -O2 main.cpp && ./a.out                                       </span >
0x801c06058: 1337
<span class="quote">> c++ -O1 main.cpp && ./a.out                                       </span >
0x801c06058: 1337
<span class="quote">> c++ -O0 main.cpp && ./a.out                                       </span >
/tmp/main-e745e6.o: In function `foo<int>::foo(int)':
main.cpp:(.text._ZN3fooIiEC2Ei[_ZN3fooIiEC2Ei]+0xc): undefined reference to
`foo<int>:
:alloc'
/tmp/main-e745e6.o: In function `foo<int>::~foo()':
main.cpp:(.text._ZN3fooIiED2Ev[_ZN3fooIiED2Ev]+0xc): undefined reference to
`foo<int>:
:alloc'
c++: error: linker command failed with exit code 1 (use -v to see invocation)</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>