llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.84k stars 11.91k forks source link

[clang] Diagnose invalid specializations of type traits #101509

Open ldionne opened 3 months ago

ldionne commented 3 months ago

The following code is ill-formed, but we don't diagnose it:

#include <type_traits>

template <>
struct std::common_type<int, int> { using type = long; }; // should warn

struct Foo { };
template <>
struct std::common_type<Foo> { using type = int; }; // should warn

template <>
struct is_integral<Foo> { }; // should warn

// etc...

It would be nice if Clang caught invalid specializations of std::common_type, and in fact perhaps of the other type trait classes as well.

Extracted from https://github.com/llvm/llvm-project/pull/99473#discussion_r1691981664.

MitalAshok commented 3 months ago

Related: #101469 (libc++ can use this for the is_integral case to get the warning)