I am currently converting an autoconf based codebase to thecmake build system. I am building various libraries and components during the process. While compiling a library I get the following error:
In file included from /home/primrose/work/Peano/src/peano4/grid/Spacetree.h:18,
from /home/primrose/work/Peano/src/peano4/parallel/SpacetreeSet.cpph:7,
from /home/primrose/work/Peano/src/peano4/parallel/SpacetreeSet.h:723,
from /home/primrose/work/Peano/src/peano4/datamanagement/CellMarker.cpp:4:
/home/primrose/work/Peano/src/peano4/stacks/STDVectorStack.h:92:21: error: expected unqualified-id before ‘const’
92 | STDVectorStack<T>(const STDVectorStack<T>& stack):
| ^~~~~
/home/primrose/work/Peano/src/peano4/stacks/STDVectorStack.h:92:21: error: expected ‘)’ before ‘const’
92 | STDVectorStack<T>(const STDVectorStack<T>& stack):
| ~^~~~~
| )
The relevant (as far as I believe) part of the code is as follows. In my current build Parallel should not be defined:
STDVectorStack(const STDVectorStack<T>& stack):
_data(),
_currentElement(0),
_ioMode(IOMode::None)
#ifdef Parallel
,
_ioMPIRequest(nullptr)
#endif
{
assertionMsg(stack._currentElement == 0, "may not copy non-empty stack");
#ifdef Parallel
assertionMsg(stack._ioMPIRequest == nullptr, "may not copy sending/receiving stack");
#endif
}
(Copy constructor is only invoked when the other stack is empty, in case you find the logic of the code peculiar) Furthermore the issue can be fixed by changing this copy constructor to:
STDVectorStack<T>(const STDVectorStack<T>& stack):
_data(),
_currentElement(0),
_ioMode(IOMode::None)
#ifdef Parallel
,
_ioMPIRequest(nullptr)
#endif
{
assertionMsg(stack._currentElement == 0, "may not copy non-empty stack");
#ifdef Parallel
assertionMsg(stack._ioMPIRequest == nullptr, "may not copy sending/receiving stack");
#endif
}
The library I build compiles without an error. (I can't yet test if the library is functioning right.)
I assume that it is an error to add the template argument to the copy constructor, such an answer I have seen for example in this question: Copy constructor of template class.
Does the C++ standard explicitly disallow a copy constructor in the form of: STDVectorStack<T>(const STDVectorStack<T>& stack), should I remove such template arguments in the copy constructors or is there a way to make the build system work without changing the code? (I want to change the code as little as possible other than adding the CMake files)