<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/63829>63829</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang wrongly believes that std::variant is not constexpr constructible if any Ti is not constexpr constructible
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          wanghan02
      </td>
    </tr>
</table>

<pre>
    Example could be found below or on [Compiler Explorer](https://godbolt.org/z/bx86vEa9e). clang trunk (and previous versions) does not compile while gcc and VC++ does.

```
#include <variant>

struct S1 {
    constexpr S1(int) {};
};

struct S2 {
    S2() {}
};

constexpr std::variant<S1, S2> var(S1(2)); // clang error: constexpr variable cannot have non-literal type 'const std::variant<S1, S2>'
constexpr std::variant<S1, S2> var2(std::in_place_type<S1>, 2); // clang error: constexpr variable cannot have non-literal type 'const std::variant<S1, S2>'
```

According to [variant.ctor#19](https://timsong-cpp.github.io/cppwp/n4868/variant.ctor#19) and [variant.ctor#34](https://timsong-cpp.github.io/cppwp/n4868/variant.ctor#34):

> Remarks: The expression inside noexcept is equivalent to is_­nothrow_­constructible_­v<Tj, T>[.](https://timsong-cpp.github.io/cppwp/n4868/variant.ctor#19.sentence-1) If Tj's selected constructor is a constexpr constructor, this constructor is a constexpr constructor[.](https://timsong-cpp.github.io/cppwp/n4868/variant.ctor#19.sentence-2)

> Remarks: If TI's selected constructor is a constexpr constructor, this constructor is a constexpr constructor[.](https://timsong-cpp.github.io/cppwp/n4868/variant.ctor#34.sentence-1)

If the selected constructor is a constexpr constructor, std::variant's converting constructor is also a constexpr constructor. IMO clang is wrong here. I haven't checked other constructors, probably have the same behavior as these 2 above.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUVk1v4zYQ_TX0ZRBBGsr6OOhgOzaQQ1GgG_QaUNTY4oYmVZKSk_76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