seanbaxter / circle

The compiler is available for download. Get it!
http://www.circle-lang.org/
2.42k stars 74 forks source link

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

Open cmarcelo opened 1 year ago

cmarcelo commented 1 year ago

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 commented 1 year ago

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