IotWebConf icon indicating copy to clipboard operation
IotWebConf copied to clipboard

IotWebConfTParameterBuilder.h won't compile with too recent compiler

Open hn3000 opened this issue 10 months ago • 0 comments

Trying to build https://github.com/rzeldent/esp32cam-rtsp I followed their instructions in README.md and updated my PlatformIO toolchain for esp32 to the newest version. I also updated PlatformIO itself (I'm on macOS, installed it through homebrew and apparently now have "PlatformIO Core, version 6.1.17" ).

After that I ran into problems with compilation of IotWebConf:

The file IotWebConf/src/IotWebConfTParameterBuilder.h generated a lot of compiler errors like

.pio/libdeps/.../IotWebConf/src/IotWebConfTParameterBuilder.h:65:42: error: expected unqualified-id before 'const'
   65 |   PrimitiveBuilder<ValueType, ParamType>(const char* id) :
      |                                          ^~~~~
.pio/libdeps/.../IotWebConf/src/IotWebConfTParameterBuilder.h:65:42: error: expected ')' before 'const'
   65 |   PrimitiveBuilder<ValueType, ParamType>(const char* id) :
      |                                         ~^~~~~
      |                                          )
.pio/libdeps/.../IotWebConf/src/IotWebConfTParameterBuilder.h:102:43: error: expected unqualified-id before 'const'
  102 |   Builder<IntTParameter<ValueType, base>>(const char* id) :
      |                                           ^~~~~
.pio/libdeps/.../IotWebConf/src/IotWebConfTParameterBuilder.h:102:43: error: expected ')' before 'const'
  102 |   Builder<IntTParameter<ValueType, base>>(const char* id) :
      |                                          ~^~~~~
      |                                           )

The error messages are misleading -- the problem is that since C++20 it is no longer allowed to declare the constructor with template parameters ( http://eel.is/c++draft/diff.cpp17.class#2 ).

So to fix the issue, I changed the constructor declarations to look like this

  PrimitiveBuilder(const char* id) :  AbstractBuilder<ParamType>(id) { }

instead of

  PrimitiveBuilder<ValueType, ParamType>(const char* id) :
    AbstractBuilder<ParamType>(id) { };

The version without the parameters should also be legal in earlier versions of C++.

(I found the link to the spec change in https://stackoverflow.com/questions/71978335/class-templates-constructor-declaration-doesnt-compile-for-c20-but-compiles#71978837 ).

hn3000 avatar Mar 08 '25 19:03 hn3000