Issue 174211
Summary Clang accepts invalid program containing conversion operator with brace initialization
Labels clang
Assignees
Reporter ranaanoop
    The following invalid program is accepted by clang but rejected by both gcc and msvc: [Dem](https://godbolt.org/z/G4Pfdnbno)
```
template<typename T>
struct B {
    consteval B(T t) : m_t{ t } { };

    template<typename U>
    operator B<U>() const { return B<U>(static_cast<U>(m_t), typename B<U>::private_ctor_tag{}); }

    operator T() const { return m_t; }

private:
    struct private_ctor_tag{};
    B(T t, private_ctor_tag) : m_t{ t } { };

    template<typename U>
    friend struct B;

    T m_t;
};

struct A {
    B<double> b;
};

int main() {

    constexpr B<int> my_b{ 42 };

    // okay on all compilers
    A a0{ .b = my_b };

    // okay only with clang. msvc and gcc give errors.
    A a1{ .b{ my_b } };
    A a2{ .b = { my_b } };

    return 0;
}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to