https://bugs.llvm.org/show_bug.cgi?id=43454

            Bug ID: 43454
           Summary: Hard error when checking validity of protected default
                    constructor in SFINAE context
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected]

The following code causes a hard compilation error on Clang trunk in all
standard modes, except C++17:

    #include <utility>
    #include <type_traits>

    struct Base { };
    struct Derived : Base { protected: Derived() = default; };


    template <class _Tp>
    void test_implicit_default_constructible(_Tp);

    template <class _Tp, class = void>
    struct is_implicitly_default_constructible
        : std::false_type
    { };

    template <class _Tp>
    struct is_implicitly_default_constructible<_Tp,
decltype(test_implicit_default_constructible<_Tp const&>({}))>
        : std::is_default_constructible<_Tp>
    { };
    static_assert(!is_implicitly_default_constructible<Derived>::value, "");

You can reproduce with:

    $ cat <file above> | clang++ -xc++ - -std=c++2a -fsyntax-only

    <stdin>:17:110: error: calling a protected constructor of class 'Derived'
        struct is_implicitly_default_constructible<_Tp,
decltype(test_implicit_default_constructible<_Tp const&>({}))>
                                                                               
                                 ^
    <stdin>:20:20: note: in instantiation of template class
'is_implicitly_default_constructible<Derived, void>' requested
          here
        static_assert(!is_implicitly_default_constructible<Derived>::value,
"");
                       ^
    <stdin>:5:40: note: declared protected here
        struct Derived : Base { protected: Derived() = default; };
                                           ^
    1 error generated.

Live repro: https://godbolt.org/z/e9-G8b


Instead, I would expect the static_assert to pass since Derived isn't default
constructible (because of access checking), and we check that inside a SFINAE
context (so no hard error should happen).

Note that Clang produces an error in C++14 and C++2a modes, but produces no
error in C++17 mode. GCC trunk, in comparison, produces no error in C++14,
C++17 and C++2a mode.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to