[libcxx-commits] [clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 31 12:54:47 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
+ if (T1.getAsType()->isBuiltinType() && T2.getAsType()->isBuiltinType())
+ return commonTypeImpl(S, BaseTemplate, TemplateLoc, {T1, T2});
+
+ TemplateArgumentListInfo Args;
+ Args.addArgument(TemplateArgumentLoc(
+ T1, S.Context.getTrivialTypeSourceInfo(T1.getAsType())));
+ Args.addArgument(TemplateArgumentLoc(
+ T2, S.Context.getTrivialTypeSourceInfo(T2.getAsType())));
+ QualType BaseTemplateInst =
+ S.CheckTemplateIdType(BaseTemplate, TemplateLoc, Args);
+ if (S.RequireCompleteType(TemplateLoc, BaseTemplateInst,
+ diag::err_incomplete_type))
+ return QualType();
+ return S.getTypeMember(BaseTemplateInst, "type");
----------------
philnik777 wrote:
Nice idea! Looks like it works just fine and doesn't have any impact on the performance. The only downside is that we don't diagnose incomplete `common_type`s anymore, since they SFINAE away now. OTOH http://eel.is/c++draft/type.traits#meta.trans.other-4.2 could be read as requiring that behaviour so who knows.
https://github.com/llvm/llvm-project/pull/99473
More information about the libcxx-commits
mailing list