diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -5216,6 +5216,10 @@ bool Variadic1 = NumParams1 && FD1->parameters().back()->isParameterPack(); bool Variadic2 = NumParams2 && FD2->parameters().back()->isParameterPack(); if (Variadic1 != Variadic2) { + bool ClangABICompat15 = Context.getLangOpts().getClangABICompat() <= + LangOptions::ClangABI::Ver15; + if (ClangABICompat15) + return Variadic1 ? FT2 : FT1; if (Variadic1 && NumParams1 > NumParams2) return FT2; if (Variadic2 && NumParams2 > NumParams1) diff --git a/clang/test/CodeGen/partial-order-variadic.cpp b/clang/test/CodeGen/partial-order-variadic.cpp --- a/clang/test/CodeGen/partial-order-variadic.cpp +++ b/clang/test/CodeGen/partial-order-variadic.cpp @@ -1,5 +1,9 @@ -// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15 %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s -// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s --check-prefixes=CHECK,AFTER-15 +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fclang-abi-compat=15 \ +// RUN: -DCLANG_ABI_COMPAT=15 %s -emit-llvm -disable-llvm-passes -o - \ +// RUN: | FileCheck %s --check-prefixes=CHECK,BEFORE-15 +// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -emit-llvm \ +// RUN: -disable-llvm-passes -o - \ +// RUN: | FileCheck %s --check-prefixes=CHECK,AFTER-15 // CHECK: %struct.S = type { i8 } // CHECK: @_Z2ggiRi @@ -18,7 +22,14 @@ template void h(const T&) {} template void h(int*); -#if !defined(CLANG_ABI_COMPAT) +#if defined(CLANG_ABI_COMPAT) + +// BEFORE-15: _Z2g2IiJEEvT_DpT0_ +template void g2(T, U...) {}; +template void g2(T, int x = 0) {}; +template void g2(int); + +#else // AFTER-15: @_Z1fIiJEEvPT_DpT0_ template void f(T*, U...){}