In commit b589f5d25e5acdbfd94791e23c0ba0f6fdcd59c6, the enum metafunctions had to stop using basic_value to explicitly opt-into the == syntax for constexpr.
The change didn't add the default constructor.
I except @flag_enums to model std::regular.
Those already generate a none value initialized with 0 that is the perfect default value.
I was also expecting @enums to model std::regular.
But those don't have a none value,
and the first enumerator, which is initialized with 0, doesn't necessarily represent a default value.
But regularity just makes it easier to work with in some contexts.
Title:
@enum
and@flag_enum
are not models ofstd::regular
.Description:
From https://github.com/hsutter/cppfront/issues/761#issuecomment-1778298138:
The change didn't add the default constructor. I except
@flag_enum
s to modelstd::regular
. Those already generate anone
value initialized with0
that is the perfect default value.I was also expecting
@enum
s to modelstd::regular
. But those don't have anone
value, and the first enumerator, which is initialized with0
, doesn't necessarily represent a default value. But regularity just makes it easier to work with in some contexts.Minimal reproducer (https://cpp2.godbolt.org/z/v3Ec5zM7r):
Commands:
```bash cppfront main.cpp2 clang++18 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -Werror=unused-value -Werror=unused-parameter -I . main.cpp ```Expected result: Both types to model
std::regular
.Actual result and error: Both static assertions failed.
Cpp2 lowered to Cpp1:
```C++ //=== Cpp2 type declarations ==================================================== #include "cpp2util.h" #line 1 "/app/example.cpp2" class engine; #line 2 "/app/example.cpp2" #line 5 "/app/example.cpp2" class perms; //=== Cpp2 type definitions and function declarations =========================== #line 1 "/app/example.cpp2" class engine { private: cpp2::i8 _value; private: constexpr engine(cpp2::inOutput:
```output Step cmake returned: 0 -- The CXX compiler identification is Clang 18.0.0 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /opt/compiler-explorer/clang-trunk/bin/clang++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done (0.5s) -- Generating done (0.0s) -- Build files have been written to: /app/build Step build returned: 1 [1/3] Generating main.cpp main.cpp2... ok (all Cpp2, passes safety checks) [2/3] Building CXX object CMakeFiles/main.dir/main.cpp.o FAILED: CMakeFiles/main.dir/main.cpp.o /opt/compiler-explorer/clang-trunk/bin/clang++ --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -I/app -I/app -std=c++23 -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -Werror=unused-value -Werror=unused-parameter -stdlib=libc++ -Wno-read-modules-implicitly -MD -MT CMakeFiles/main.dir/main.cpp.o -MF CMakeFiles/main.dir/main.cpp.o.d -o CMakeFiles/main.dir/main.cpp.o -c /app/build/main.cpp main.cpp2:10:17: error: static assertion failed 10 | static_assert(std::default_initializable