[libcxx-commits] [clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Aug 1 09:15:03 PDT 2024


================
@@ -3058,6 +3058,133 @@ void Sema::NoteAllFoundTemplates(TemplateName Name) {
   }
 }
 
+static QualType commonTypeImpl(Sema &S, TemplateName BaseTemplate,
+                               SourceLocation TemplateLoc,
+                               ArrayRef<TemplateArgument> Ts) {
+  auto lookUpCommonType = [&](TemplateArgument T1,
+                              TemplateArgument T2) -> QualType {
+    // Don't bother looking for other specializations if both types are
+    // builtins - users aren't allowed to specialize for them
----------------
ldionne wrote:

I believe it would make sense for such a diagnostic to work today, even without the builtin. For example, it would be nice for the following code to be diagnosed with a warning (or an error, whatever):

```c++
#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

// etc...
```

I don't think this should be tied to the implementation of the builtin, i.e. it should be diagnosed where the user writes the invalid specialization, not where we use `std::common_type_t`. As such, I think it would make sense to tackle this as a follow-up and I filed an issue for it: https://github.com/llvm/llvm-project/issues/101509

https://github.com/llvm/llvm-project/pull/99473


More information about the libcxx-commits mailing list