ARTICLE AD BOX
This code prints:
1 when compiled with g++ v15.2.1, 0 when compiled with clang++, v21.1.6.The -std=c++17 flag is used with both compilers.
#include <iostream> #include <type_traits> #include <utility> namespace my_namespace { template <typename T> void format(std::ostream &os, const T &t) = delete; template <typename T, class = void> struct is_formattable : std::false_type {}; template <typename T> struct is_formattable<T, decltype(format<T>(std::declval<std::ostream &>(), std::declval<const T &>()), void{})> : std::true_type {}; } struct S { int a; }; namespace my_namespace { template <> void format<S>(std::ostream &os, const S &s) { os << "S[" << s.a << ']'; } } int main() { std::cout << my_namespace::is_formattable<S>::value << '\n'; }Is my code non-standard? Do I have undefined behavior somewhere? Is this a compiler bug?
