Describe the bug
Using as on a std::optional in an inspect expression causes a C++ compiler error.
To Reproduce
Run cppfront on this code:
main: () -> int = {
opt: std::optional<int> = 10;
std::cout << "Value: " << inspect opt -> int {
is int = opt as int;
is _ = 0;
} << "\n";
return 0;
}
and then compile with a C++ compiler. Clang reports:
main.cpp2:5:185: error: no viable conversion from returned value of type 'const nonesuch_' to function return type 'int'
5 | if (cpp2::impl::is<int>(_expr)) { if constexpr( requires{cpp2::impl::as<int>(opt);} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF((cpp2::impl::as<int>(opt))),int> ) return cpp2::impl::as<int>(opt); else return int{}; else return int{}; }
| ^~~~~~~~~~~~~~~~~~~~~~~~
Describe the bug Using
as
on astd::optional
in aninspect
expression causes a C++ compiler error.To Reproduce Run cppfront on this code:
and then compile with a C++ compiler. Clang reports:
Repro on Godbolt