circle icon indicating copy to clipboard operation
circle copied to clipboard

Circle crashes during compilation when using "overloaded" helper and template_brackets feature

Open cmarcelo opened this issue 2 years ago • 1 comments

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;
}

cmarcelo avatar May 22 '23 05:05 cmarcelo

Also, in theory the deduction guide could be removed, but compiler also crashes when I remove it.

cmarcelo avatar May 22 '23 06:05 cmarcelo