wxIshiko / wxCharts

A library to create charts in wxWidgets applications
https://www.wxishiko.com/wxCharts/
MIT License
114 stars 50 forks source link

const member variable leads to compile error in C++17 in VS2019 #173

Closed playgithub closed 2 years ago

playgithub commented 3 years ago
class wxChartsElement
{
...
private:
    const wxChartTooltipProvider::ptr m_tooltipProvider
};
Severity    Code    Description Project File    Line    Suppression State
Error   C2280   'wxChartsLabel &wxChartsLabel::operator =(const wxChartsLabel &)': attempting to reference a deleted function   wxcharts    C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29910\include\xutility   4421    
Error   C2280   'wxChartsLabel &wxChartsLabel::operator =(const wxChartsLabel &)': attempting to reference a deleted function   wxcharts    C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29910\include\xutility   4661    

If remove const of the member variable, it builds successfully.


UPDATE C++14 has been tested, failed in the same way.

Kvaz1r commented 3 years ago

Something strange - I can't reproduce the error with current update VS(14.29.30037) and wxWidgets 3.1.4.

playgithub commented 3 years ago

Something strange - I can't reproduce the error with current update VS(14.29.30037) and wxWidgets 3.1.4.

In new C++ standard, implicit operator= will not be composed automatically in some cases. I'll make a simple sample to illustrate the problem.

GerHobbelt commented 2 years ago

This is what latest MSVC2019 says when compiled in C++17 mode (the compiler adds more diagnostic info this time, hope it helps):

4>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\xutility(4430,16): error C2280: 'wxChartsLabel &wxChartsLabel::operator =(const wxChartsLabel &)': attempting to reference a deleted function (compiling source file ../../thirdparty/owemdjee/wxCharts/src/wxchartsradialgrid.cpp)
4>Z:\lib\tooling\qiqqa\MuPDF\thirdparty\owemdjee\wxCharts\include\wx\charts\wxchartslabel.h(103): message : compiler has generated 'wxChartsLabel::operator =' here (compiling source file ../../thirdparty/owemdjee/wxCharts/src/wxchartsradialgrid.cpp)
4>Z:\lib\tooling\qiqqa\MuPDF\thirdparty\owemdjee\wxCharts\include\wx\charts\wxchartslabel.h(103,1): message : 'wxChartsLabel &wxChartsLabel::operator =(const wxChartsLabel &)': function was implicitly deleted because a base class invokes a deleted or inaccessible function 'wxChartsElement &wxChartsElement::operator =(const wxChartsElement &)' (compiling source file ../../thirdparty/owemdjee/wxCharts/src/wxchartsradialgrid.cpp)
4>Z:\lib\tooling\qiqqa\MuPDF\thirdparty\owemdjee\wxCharts\include\wx\charts\wxchartselement.h(79,1): message : 'wxChartsElement &wxChartsElement::operator =(const wxChartsElement &)': function was implicitly deleted because a data member 'wxChartsElement::m_tooltipProvider' has either no appropriate copy assignment operator or overload resolution was ambiguous (compiling source file ../../thirdparty/owemdjee/wxCharts/src/wxchartsradialgrid.cpp)
4>Z:\lib\tooling\qiqqa\MuPDF\thirdparty\owemdjee\wxCharts\include\wx\charts\wxchartselement.h(78): message : see declaration of 'wxChartsElement::m_tooltipProvider' (compiling source file ../../thirdparty/owemdjee/wxCharts/src/wxchartsradialgrid.cpp)
4>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\vector(1419): message : see reference to function template instantiation '_OutIt *std::_Move_unchecked<wxChartsLabel*,wxChartsLabel*>(_InIt,_InIt,_OutIt)' being compiled
4>        with
4>        [
4>            _OutIt=wxChartsLabel *,
4>            _InIt=wxChartsLabel *
4>        ] (compiling source file ../../thirdparty/owemdjee/wxCharts/src/wxchartsradialgrid.cpp)
4>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\vector(1407): message : while compiling class template member function 'std::_Vector_iterator<std::_Vector_val<std::_Simple_types<_Ty>>> std::vector<_Ty,std::allocator<_Ty>>::erase(std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>) noexcept(false)'
4>        with
4>        [
4>            _Ty=wxChartsLabel
4>        ] (compiling source file ../../thirdparty/owemdjee/wxCharts/src/wxchartsradialgrid.cpp)
4>Z:\lib\tooling\qiqqa\MuPDF\thirdparty\owemdjee\wxCharts\src\wxchartsradialgrid.cpp(52): message : see reference to function template instantiation 'std::_Vector_iterator<std::_Vector_val<std::_Simple_types<_Ty>>> std::vector<_Ty,std::allocator<_Ty>>::erase(std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>) noexcept(false)' being compiled
4>        with
4>        [
4>            _Ty=wxChartsLabel
4>        ]
4>Z:\lib\tooling\qiqqa\MuPDF\thirdparty\owemdjee\wxCharts\include\wx\charts\wxchartslabelgroup.h(32): message : see reference to class template instantiation 'std::vector<wxChartsLabel,std::allocator<wxChartsLabel>>' being compiled (compiling source file ../../thirdparty/owemdjee/wxCharts/src/wxchartsradialgrid.cpp)
4>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\xutility(4198,16): error C2280: 'wxChartsLabel &wxChartsLabel::operator =(const wxChartsLabel &)': attempting to reference a deleted function (compiling source file ../../thirdparty/owemdjee/wxCharts/src/wxchartsaxis.cpp)
4>Z:\lib\tooling\qiqqa\MuPDF\thirdparty\owemdjee\wxCharts\include\wx\charts\wxchartslabel.h(103): message : compiler has generated 'wxChartsLabel::operator =' here (compiling source file ../../thirdparty/owemdjee/wxCharts/src/wxchartsaxis.cpp)
4>Z:\lib\tooling\qiqqa\MuPDF\thirdparty\owemdjee\wxCharts\include\wx\charts\wxchartslabel.h(103,1): message : 'wxChartsLabel &wxChartsLabel::operator =(const wxChartsLabel &)': function was implicitly deleted because a base class invokes a deleted or inaccessible function 'wxChartsElement &wxChartsElement::operator =(const wxChartsElement &)' (compiling source file ../../thirdparty/owemdjee/wxCharts/src/wxchartsaxis.cpp)
4>Z:\lib\tooling\qiqqa\MuPDF\thirdparty\owemdjee\wxCharts\include\wx\charts\wxchartselement.h(79,1): message : 'wxChartsElement &wxChartsElement::operator =(const wxChartsElement &)': function was implicitly deleted because a data member 'wxChartsElement::m_tooltipProvider' has either no appropriate copy assignment operator or overload resolution was ambiguous (compiling source file ../../thirdparty/owemdjee/wxCharts/src/wxchartsaxis.cpp)
4>Z:\lib\tooling\qiqqa\MuPDF\thirdparty\owemdjee\wxCharts\include\wx\charts\wxchartselement.h(78): message : see declaration of 'wxChartsElement::m_tooltipProvider' (compiling source file ../../thirdparty/owemdjee/wxCharts/src/wxchartsaxis.cpp)
4>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\vector(1175): message : see reference to function template instantiation '_OutIt *std::_Copy_unchecked<_Iter,wxChartsLabel*>(_InIt,_InIt,_OutIt)' being compiled
4>        with
4>        [
4>            _OutIt=wxChartsLabel *,
4>            _Iter=const wxChartsLabel *,
4>            _InIt=const wxChartsLabel *
4>        ] (compiling source file ../../thirdparty/owemdjee/wxCharts/src/wxchartsaxis.cpp)
4>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\vector(1189): message : see reference to function template instantiation 'void std::vector<wxChartsLabel,std::allocator<wxChartsLabel>>::_Assign_range<const wxChartsLabel*>(_Iter,_Iter,std::forward_iterator_tag)' being compiled
4>        with
4>        [
4>            _Iter=const wxChartsLabel *
4>        ] (compiling source file ../../thirdparty/owemdjee/wxCharts/src/wxchartsaxis.cpp)
4>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\vector(1189): message : see reference to function template instantiation 'void std::vector<wxChartsLabel,std::allocator<wxChartsLabel>>::_Assign_range<const wxChartsLabel*>(_Iter,_Iter,std::forward_iterator_tag)' being compiled
4>        with
4>        [
4>            _Iter=const wxChartsLabel *
4>        ] (compiling source file ../../thirdparty/owemdjee/wxCharts/src/wxchartsaxis.cpp)
4>Z:\lib\tooling\qiqqa\MuPDF\thirdparty\owemdjee\wxCharts\src\wxchartsaxis.cpp(97): message : see reference to function template instantiation 'void std::vector<wxChartsLabel,std::allocator<wxChartsLabel>>::assign<std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,0>(_Iter,_Iter)' being compiled
4>        with
4>        [
4>            _Ty=wxChartsLabel,
4>            _Iter=std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<wxChartsLabel>>>
4>        ]
4>Z:\lib\tooling\qiqqa\MuPDF\thirdparty\owemdjee\wxCharts\src\wxchartsaxis.cpp(97): message : see reference to function template instantiation 'void std::vector<wxChartsLabel,std::allocator<wxChartsLabel>>::assign<std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,0>(_Iter,_Iter)' being compiled
4>        with
4>        [
4>            _Ty=wxChartsLabel,
4>            _Iter=std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<wxChartsLabel>>>
4>        ]
GerHobbelt commented 2 years ago

Seems removing the const for the offending member did the job. Pullreq: https://github.com/wxIshiko/wxCharts/pull/195

Tried a few other things to no avail; I'm rather rusty re C++ (haven't touched the language since pre-C++11): feedback welcome.