https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110594

            Bug ID: 110594
           Summary: std::variant's converting constructor does not resolve
                    alternative correctly
           Product: gcc
           Version: 13.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xgao at nvidia dot com
  Target Milestone: ---

Created attachment 55502
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55502&action=edit
minimum repro

According to https://en.cppreference.com/w/cpp/utility/variant/variant, I would
expect the attached program to output:

int64_t: 1
variant is int

However, I am getting:

int64_t: 1
variant is complex

gcc-9 seems to have the correct behavior for the attached program, however, the
implementation of std::variant in gcc-9 has another problem that the following
example in that cppreference.com page does not work:

std::variant<float, long, double> z = 0; // OK, holds long
                                         // float and double are not candidates

Thanks to the help of jjsjann123 (https://github.com/jjsjann123), this is
potentially related to the SFINAE in the "variant" header:

  // Helper used to check for valid conversions that don't involve narrowing.
  template<typename _Ti> struct _Arr { _Ti _M_x[1]; };

seems that this will block int64_t from being selected as shown in
https://godbolt.org/z/Gcr4j53rd. However, the following code is totally valid:

int64_t x[] = {size_t(1)};

so probably that SFINAE might be wrong.

Reply via email to