Skip to content

IotWebConfTParameterBuilder.h won't compile with too recent compiler #290

@hn3000

Description

@hn3000

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 ).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions