Created
February 6, 2020 23:59
-
-
Save billti/bb83220ef70d2bd58e9889b83664b752 to your computer and use it in GitHub Desktop.
Errors with exported defaulted class members
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compile with: cl /std:c++17 /EHsc main.cpp | |
#include <list> | |
#include <string> | |
#include <memory> | |
#include <iostream> | |
#if defined(DLL_EXPORT) | |
#define EXPORT __declspec(dllexport) | |
#else | |
#define EXPORT | |
#endif | |
using std::string, std::list, std::unique_ptr, std::make_unique, std::move, std::cout; | |
class EXPORT Measure { | |
public: | |
#if defined(FIXME) | |
Measure() = default; | |
Measure(const Measure&) = delete; | |
Measure& operator=(const Measure&) = delete; | |
#endif | |
struct Request { | |
unique_ptr<string> a_string; | |
}; | |
list<Request> request_list_; | |
}; | |
int main() { | |
Measure measure; | |
Measure::Request req{make_unique<string>("test")}; | |
measure.request_list_.push_back(move(req)); | |
cout << *measure.request_list_.front().a_string; | |
} | |
/* | |
Compiling with /DDLL_EXPORT results in the below errors. Add /DFIXME to delete the default copy constructors/assignment to fix. | |
Note: Using the /Zc:dllexportInlines- flag with clang-cl.exe also fixes the problem. | |
main.cpp | |
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\list(1264): error C2280: 'Measure::Request &Measure::Request::operator =(const Measure::Request &)': attempting to reference a deleted function | |
main.cpp(26): note: compiler has generated 'Measure::Request::operator =' here | |
main.cpp(26): note: 'Measure::Request &Measure::Request::operator =(const Measure::Request &)': function was implicitly deleted because a data member invokes a deleted or inaccessible function 'std::unique_ptr<std::string,std::default_delete<std::string>> &std::unique_ptr<std::string,std::default_delete<std::string>>::operator =(const std::unique_ptr<std::string,std::default_delete<std::string>> &)' | |
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\memory(1913): note: 'std::unique_ptr<std::string,std::default_delete<std::string>> &std::unique_ptr<std::string,std::default_delete<std::string>>::operator =(const std::unique_ptr<std::string,std::default_delete<std::string>> &)': function was explicitly deleted | |
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\list(1273): note: see reference to function template instantiation 'void std::list<Measure::Request,std::allocator<Measure::Request>>::_Assign_cast<Measure::Request&,_Iter>(_UIter,const _UIter)' being compiled | |
with | |
[ | |
_Iter=std::_List_unchecked_const_iterator<std::_List_val<std::_List_simple_types<Measure::Request>>,std::_Iterator_base0>, | |
_UIter=std::_List_unchecked_const_iterator<std::_List_val<std::_List_simple_types<Measure::Request>>,std::_Iterator_base0> | |
] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment