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

--- Comment #1 from Owen Smith <ojman101 at protonmail dot com> ---
----------------------------------------------------------------
#include <type_traits>

template <typename, typename>
class IsSafelyCastable : public std::false_type {};

template <>
class IsSafelyCastable<int, float> : public std::true_type {};

template <typename T>
struct Foo {
    template <typename U>
    explicit(!IsSafelyCastable<T, U>::value) operator Foo<U>() { return {}; }
};

int main() {
    Foo<float> a;
    Foo<int> b = a;
}
----------------------------------------------------------------

Inlining the definition yields the correct error with GCC 9.3.0:

----------------------------------------------------------------
main.cpp: In function 'int main()':
main.cpp:17:18: error: conversion from 'Foo<float>' to non-scalar type
'Foo<int>' requested
   17 |     Foo<int> b = a;
      | 
----------------------------------------------------------------

Reply via email to