-
Notifications
You must be signed in to change notification settings - Fork 13
Description
Hi @serhmarch, thank you for your effort, your soultion does a real help. I've noticed such a potentional issue and probably it might improve your library
Environment
- ModbusLib version: v4.0 (also reproducible on main)
- Compiler: Visual Studio 2017 (v141)
- Platform: AMD64 | Windows 10.0.26200
- Build system: CMake 3.28.2
- Generator: Visual Studio 15 2017 | x64
Descrtiption
On MSVC the build fails with error C2600 for the (bool) constructors of ModbusAscPort and ModbusRtuPort when those classes also use using ModbusSerialPort::ModbusSerialPort;. MSVC treats the definition as if we were trying to define a compiler-generated special member.
2>D:\repos\modbus\build\_deps\modbuslib-src\src\ModbusAscPort.cpp(26,45): error C2600: ModbusAscPort::ModbusAscPort: cannot define a compiler-generated special member function (must be declared in the class first) 2>D:\repos\modbus\build\_deps\modbuslib-src\src\ModbusAscPort.cpp(26,45): error C2600: ModbusAscPort::ModbusAscPort(bool blocking) : 2>D:\repos\modbus\build\_deps\modbuslib-src\src\ModbusAscPort.cpp(26,45): error C2600:
Root Cause
The issue is in src/ModbusRtuPort.h, line 23, and src/ModbusAscPort.h, line 23
ModbusAscPort(bool blocking = false);
in src/ModbusRtuPort.cpp, line 26 (the same forAscPort and probably TcpPort)
ModbusRtuPort::ModbusRtuPort(bool blocking) :
due to default value of blocking MSVS compiler supposes that default compiler (which is actually generated) is defined.
Proposed fix
There are several ways to fix this if you consider it as worth to fix. The easiest way - to remove default parameter from constructors. It makes their usage a bit more complicated (you have to set the parameter manually), hovewer, it keeps the set of constructors clear.
msvc-c2600-no-default-arg.patch
Testing and affects
After applying this fix library successfuly builds with MSVS compilers 2017 (v141)