https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126185
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I think this is just a buggy testcase.
members_of only accepts a reflection of a class type or a namespace, not an
enum so the throw is correct.
Using enumerators_of works but you need define_static_array to promote it to
static storage. And the deduction for auto return type must match which is
doesn't here (std::basic_string_view<char> vs const char*).
Fixed test:
```
#include <meta>
#include <type_traits>
#include <iostream>
#include <expected>
#include <string>
#include <cstdint>
enum class ERRORCODE : std::uint16_t {
SUCCESS = 0x00,
FAIL = 0x01,
WRONG_TYPE = 0x02
};
template<typename T1, typename T2>
constexpr std::expected<T1, ERRORCODE> SomarValores(const T1& value_1, const
T2& value_2) {
if constexpr ((std::is_integral_v<T1> || std::is_floating_point_v<T1>) &&
(std::is_integral_v<T2> || std::is_floating_point_v<T2>)) {
return value_1 + value_2;
} else {
return std::unexpected(ERRORCODE::FAIL);
}
}
template<typename TipoDesconhecido>
constexpr auto InterpretarErro(const TipoDesconhecido& err) {
auto error = err.error_or(ERRORCODE::SUCCESS);
using typePers = typename TipoDesconhecido::error_type;
template for (constexpr auto member : define_static_array
(std::meta::enumerators_of(^^typePers))) {
if (error == [:member:])
return std::meta::identifier_of(member);
}
return std::string_view("UNKNOWN_ERROR");
}
int main() {
std::cout << "ErroR: " << InterpretarErro(SomarValores(true, 1.0f)) <<
std::endl;
return 0;
}
```
$ ./a.out
ErroR: SUCCESS