gcc/msvc compile the following, clang does not. Is there a workaround?

74 views Asked by At
#include <optional>
#include <variant>
#include <vector>

// A
static_assert(
    std::optional<
        std::vector< int >
    >{ std::vector< int >{ 1, 2, 3 } }
);
// B
static_assert(
    std::optional<
        std::variant<
            std::vector< int >
        >
    >{ std::vector< int >{ 1, 2, 3 } }
);

https://godbolt.org/z/jbdfPYqe1

These samples do not compile using clang (18). They do compile using gcc/msvc.

What exactly causes this behavior and is there a workaround?

1

There are 1 answers

0
André Lehto On

Now, I haven't found the exact information in the clang documentation yet, but I am assuming that what you are trying to do is not yet supported by Clang. Although Clang is slowly starting to support C++ 20, it is only doing so partially, and I am assuming that what you are trying to do has not yet become supported.