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

            Bug ID: 102894
           Summary: make_any is not SFINAE-friendly
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: de34 at live dot cn
  Target Milestone: ---

std::make_any is specified in [any.nonmembers] p2-3 via "Effects: Equivalent
to: ...". According to [structure.specifications] p4, it propagates the
"Constraints:" of the constructor (in [any.cons] p11 and p17), and thus
SFINAE-friendly.

The following program should fail to compile. But currently it compiles with
libstdc++ due to lack of constraints. Note that std::make_optional is correctly
constrained in libstdc++.

Wandbox link:https://wandbox.org/permlink/noMWBjdCp0hg1pEZ

#include <type_traits>
#include <utility>
#include <any>

namespace test {
template<class T, class... Args>
auto test_make_any(int)
    -> decltype((void)std::make_any<T>(std::declval<Args>()...),
std::true_type{});
template<class, class...>
auto test_make_any(...) -> std::false_type;
template<class T, class... Args>
inline constexpr bool can_make_any = decltype(test_make_any<T,
Args...>(0))::value;
}

int main()
{
    static_assert(test::can_make_any<int, int, int>); // should not pass
}

Reply via email to