https://github.com/Serosh-commits updated https://github.com/llvm/llvm-project/pull/233138
From cb0947634c41a24b761863b47be410467ef8e6c4 Mon Sep 17 00:00:00 2001 From: Serosh-commits <[email protected]> Date: Sun, 18 Oct 2026 02:59:23 +0530 Subject: [PATCH 1/2] [clang] Handle invalid template template arguments in partial ordering --- clang/lib/Sema/SemaTemplateDeduction.cpp | 6 ++---- clang/test/SemaTemplate/gh227649.cpp | 6 ++++++ 2 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 clang/test/SemaTemplate/gh227649.cpp diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index 1544fd56b82ae2..651114329d4e9e 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -6609,11 +6609,9 @@ bool Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs( case TemplateDeductionResult::Success: return true; - // It doesn't seem possible to get a non-deduced mismatch when partial - // ordering TTPs, except with an invalid template parameter list which has - // a parameter after a pack. + // An invalid template parameter list can produce a non-deduced mismatch + // while finishing the deduction. case TemplateDeductionResult::NonDeducedMismatch: - assert(PArg->isInvalidDecl() && "Unexpected NonDeducedMismatch"); return false; // Substitution failures should have already been diagnosed. diff --git a/clang/test/SemaTemplate/gh227649.cpp b/clang/test/SemaTemplate/gh227649.cpp new file mode 100644 index 00000000000000..02784971cb6907 --- /dev/null +++ b/clang/test/SemaTemplate/gh227649.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck %s +// CHECK: error: use of undeclared identifier 'foo' + +template <template <decltype(foo())> typename> struct S {}; +template <int &p> struct P; +S<P> s; From c667e4ad3f25ca1b7dd1724eb44237f8a36aa015 Mon Sep 17 00:00:00 2001 From: Serosh-commits <[email protected]> Date: Sun, 18 Oct 2026 02:59:23 +0530 Subject: [PATCH 2/2] address review --- clang/lib/Sema/SemaTemplate.cpp | 4 ++++ clang/lib/Sema/SemaTemplateDeduction.cpp | 6 ++++-- clang/test/SemaTemplate/gh227649.cpp | 5 ++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 5667cf53fee0b5..74d064ced4d8c0 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -1595,6 +1595,8 @@ NamedDecl *Sema::ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, if (T.isNull()) { T = Context.IntTy; // Recover with an 'int' type. Invalid = true; + } else if (T->containsErrors()) { + Invalid = true; } CheckFunctionOrTemplateParamDeclarator(S, D); @@ -2447,6 +2449,8 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams, for (TemplateParameterList::iterator NewParam = NewParams->begin(), NewParamEnd = NewParams->end(); NewParam != NewParamEnd; ++NewParam) { + Invalid |= (*NewParam)->isInvalidDecl(); + // Whether we've seen a duplicate default argument in the same translation // unit. bool RedundantDefaultArg = false; diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index 651114329d4e9e..1544fd56b82ae2 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -6609,9 +6609,11 @@ bool Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs( case TemplateDeductionResult::Success: return true; - // An invalid template parameter list can produce a non-deduced mismatch - // while finishing the deduction. + // It doesn't seem possible to get a non-deduced mismatch when partial + // ordering TTPs, except with an invalid template parameter list which has + // a parameter after a pack. case TemplateDeductionResult::NonDeducedMismatch: + assert(PArg->isInvalidDecl() && "Unexpected NonDeducedMismatch"); return false; // Substitution failures should have already been diagnosed. diff --git a/clang/test/SemaTemplate/gh227649.cpp b/clang/test/SemaTemplate/gh227649.cpp index 02784971cb6907..730e343bced319 100644 --- a/clang/test/SemaTemplate/gh227649.cpp +++ b/clang/test/SemaTemplate/gh227649.cpp @@ -1,6 +1,5 @@ -// RUN: %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck %s -// CHECK: error: use of undeclared identifier 'foo' +// RUN: %clang_cc1 -fsyntax-only -verify %s -template <template <decltype(foo())> typename> struct S {}; +template <template <decltype(foo())> typename> struct S {}; // expected-error {{use of undeclared identifier 'foo'}} template <int &p> struct P; S<P> s; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
