-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
bugSomething isn't workingSomething isn't workingfixedSomething works now, yay!Something works now, yay!
Description
Describe the bug
Creating a vector of shared_ptr of a template instantiated incomplete type fails to compile with type uses undefined class
Test case
Source:
#include <vector>
#include <memory>
template <typename T>
struct holder {
T t;
};
class fwd;
using hptr = std::shared_ptr<holder<fwd>>;
std::vector<hptr> vec(5);Output:
example.cpp
<source>(6): error C2079: 'holder<fwd>::t' uses undefined class 'fwd'
C:/data/msvc/14.36.32530-Pre/include\vector(2043): note: see reference to class template instantiation 'holder<fwd>' being compiled
C:/data/msvc/14.36.32530-Pre/include\vector(2033): note: while compiling class template member function 'void std::vector<hptr,std::allocator<hptr>>::_Tidy(void) noexcept'
C:/data/msvc/14.36.32530-Pre/include\vector(765): note: see the first reference to 'std::vector<hptr,std::allocator<hptr>>::_Tidy' in 'std::vector<hptr,std::allocator<hptr>>::~vector'
<source>(12): note: see the first reference to 'std::vector<hptr,std::allocator<hptr>>::~vector' in 'void __cdecl `dynamic atexit destructor for 'vec''(void)'
<source>(12): note: see reference to class template instantiation 'std::vector<hptr,std::allocator<hptr>>' being compiled
Godbolt: https://godbolt.org/z/738sMK337
STL version
- visual studio 17.6.0
- reproducible with godbolt msvc latest
Additional info
It seems the problem is in <vector> and not in memory. Instantiating hptr from the demo when no std::vector is involved compiles fine,
This code, for example, compiles:
#include <memory>
template <typename T>
struct holder {
T t;
};
class fwd;
using hptr = std::shared_ptr<holder<fwd>>;
template <typename T>
struct my_vec {
T* data;
my_vec(int n) { data = new T[n]; }
~my_vec() { delete[] data; }
};
my_vec<hptr> vec(5);Godbolt link: https://godbolt.org/z/zWd6E13Y3
This is also DevCom-10535345 / VSO-1926908 / AB#1926908.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingfixedSomething works now, yay!Something works now, yay!