ETLCPP / etl

Embedded Template Library
https://www.etlcpp.com
MIT License
2.04k stars 371 forks source link

Compilation Error with constexpr in etl::string_base::size() on ESP-WROVER-KIT (c++11) #892

Closed JorgeHSantana closed 1 month ago

JorgeHSantana commented 1 month ago

Hello ETLCPP Team,

I am encountering a compilation error when using the etl::string in my project with ESP-WROVER-KIT. The error is related to the constexpr specification of the size() method in etl::string_base.

Error details:

In file included from .pio/libdeps/esp-wrover-kit/Embedded Template Library/include/etl/string.h:35:0,
                 from src/main.cpp:2:
.pio/libdeps/esp-wrover-kit/Embedded Template Library/include/etl/basic_string.h:176:29: error: enclosing class of constexpr non-static member function 'etl::string_base::size_type etl::string_base::size() const' is not a literal type
     ETL_CONSTEXPR size_type size() const
                             ^
.pio/libdeps/esp-wrover-kit/Embedded Template Library/include/etl/basic_string.h:166:9: note: 'etl::string_base' is not literal because:
   class string_base : public private_basic_string::string_base_statics<>
         ^
.pio/libdeps/esp-wrover-kit/Embedded Template Library/include/etl/basic_string.h:166:9: note:   'etl::string_base' has a non-trivial destructor
*** [.pio\build\esp-wrover-kit\src\main.cpp.o] Error 1

Description: The issue seems to stem from the constexpr declaration of size() in a class (etl::string_base) that is not a literal type, primarily due to having a non-trivial destructor. According to the C++ standard, a class must be a literal type to contain constexpr methods.

Temporary Solution: I was able to compile successfully by removing the ETL_CONSTEXPR macro from the size() method in basic_string.h (line 176):

size_type size() const

However, modifying the library code directly is not ideal for maintenance reasons.

Request: Could you please look into this issue? Perhaps a revision in the use of constexpr in this context or an update to the library to support scenarios like this would be beneficial. Any guidance or fix would be greatly appreciated.

Thank you for your help and for maintaining such a useful library!

jwellbelove commented 1 month ago

Fixed in 20.38.15