Author: Oleksandr T. Date: 2024-11-29T21:26:59+02:00 New Revision: be75a14207ab0dac6ad9f9097957f14a918ac611
URL: https://github.com/llvm/llvm-project/commit/be75a14207ab0dac6ad9f9097957f14a918ac611 DIFF: https://github.com/llvm/llvm-project/commit/be75a14207ab0dac6ad9f9097957f14a918ac611.diff LOG: [Clang] fix crash due to incorrect argument position in merging deduced template arguments (#118041) Fixes #113659 Added: clang/test/SemaTemplate/template-args-deduction-aggregates.cpp Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaTemplateDeduction.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 9882a1c42d50c4..f2e14a2cb0ea7b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -762,6 +762,7 @@ Bug Fixes to C++ Support missing placeholder return type. (#GH78694) - Fixed a bug where bounds of partially expanded pack indexing expressions were checked too early. (#GH116105) - Fixed an assertion failure caused by using ``consteval`` in condition in consumed analyses. (#GH117385) +- Fix a crash caused by incorrect argument position in merging deduced template arguments. (#GH113659) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index 62a0c30d995020..fad20b37a7d9a2 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -376,7 +376,7 @@ checkDeducedTemplateArguments(ASTContext &Context, for (TemplateArgument::pack_iterator XA = X.pack_begin(), XAEnd = X.pack_end(), YA = Y.pack_begin(), YAEnd = Y.pack_end(); - XA != XAEnd; ++XA, ++YA) { + XA != XAEnd; ++XA) { if (YA != YAEnd) { TemplateArgument Merged = checkDeducedTemplateArguments( Context, DeducedTemplateArgument(*XA, X.wasDeducedFromArrayBound()), @@ -384,6 +384,7 @@ checkDeducedTemplateArguments(ASTContext &Context, if (Merged.isNull() && !(XA->isNull() && YA->isNull())) return DeducedTemplateArgument(); NewPack.push_back(Merged); + ++YA; } else { NewPack.push_back(*XA); } diff --git a/clang/test/SemaTemplate/template-args-deduction-aggregates.cpp b/clang/test/SemaTemplate/template-args-deduction-aggregates.cpp new file mode 100644 index 00000000000000..afe78d0873bb33 --- /dev/null +++ b/clang/test/SemaTemplate/template-args-deduction-aggregates.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++20 + +// expected-no-diagnostics + +namespace GH113659 { +template <class... Args> struct S {}; +struct T {}; +struct U {}; + +template <class... Args> struct B : S<Args...>, Args... {}; +B b{S<T, U>{}}; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits