http://llvm.org/bugs/show_bug.cgi?id=20593
Dominic Fandrey <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |REOPENED Resolution|INVALID |--- --- Comment #3 from Dominic Fandrey <[email protected]> --- 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; } > c++ -O2 main.cpp && ./a.out 0x801c06058: 1337 > c++ -O1 main.cpp && ./a.out 0x801c06058: 1337 > c++ -O0 main.cpp && ./a.out /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) -- You are receiving this mail because: You are on the CC list for the bug.
_______________________________________________ LLVMbugs mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs
