[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)
Nikolas Klauser via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 19 07:43:14 PDT 2024
================
@@ -3058,6 +3058,141 @@ void Sema::NoteAllFoundTemplates(TemplateName Name) {
}
}
+static std::optional<QualType> commonTypeImpl(Sema &S,
+ TemplateName BaseTemplate,
+ SourceLocation TemplateLoc,
+ ArrayRef<TemplateArgument> Ts) {
+ auto lookUpCommonType = [&](TemplateArgument T1,
+ TemplateArgument T2) -> std::optional<QualType> {
+ // Don't bother looking for other specializations if both types are
+ // builtins - users aren't allowed to specialize for them
+ if (T1.getAsType()->isBuiltinType() && T2.getAsType()->isBuiltinType())
+ return commonTypeImpl(S, BaseTemplate, TemplateLoc, {T1, T2});
----------------
philnik777 wrote:
There are two cases where `lookUpCommonType` is called:
- `sizeof...(Ts)` is 1 - in that case we now call `commonTypeImpl` with two types
- `sizeof...(Ts)` is 2 and `decay_t<T1/T2>` is a different type that `T1/T2` - we now call `commonTypeImpl` with the decayed types instead, which won't go into the same branch, since a decayed type doesn't decay any further.
https://github.com/llvm/llvm-project/pull/99473
More information about the cfe-commits
mailing list