When using the "overloaded" helper for std::visit() (from https://en.cppreference.com/w/cpp/utility/variant/visit) together with the template_brackets feature, if we forget to add the ! (as noted below), compiler will crash.
Interestingly, if the usage of the helper is commented, compiler will properly give me the error message about the missing !.
#feature on template_brackets
#include <variant>
#include <iostream>
using t = std::variant!<bool, int>;
template <class... Ts> struct overloaded : Ts... {
using Ts::operator()...;
};
// NOTE: This is missing a !
template <class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
int main(int argc, char* argv[]) {
t v = true;
if (argc > 1)
v = 22;
// If comment this usage, proper error message about missing `!`.
#if 1
std::visit(overloaded {
[](bool) { std::cout << "bool!\n"; },
[](int) { std::cout << "int!\n"; },
}, v);
#endif
return 0;
}
When using the "overloaded" helper for std::visit() (from https://en.cppreference.com/w/cpp/utility/variant/visit) together with the template_brackets feature, if we forget to add the
!
(as noted below), compiler will crash.Interestingly, if the usage of the helper is commented, compiler will properly give me the error message about the missing
!
.