Skip to content

Commit 5aa6a92

Browse files
committed
Address comments and poke the CI
1 parent e017bed commit 5aa6a92

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -345,15 +345,23 @@ MultiLevelTemplateArgumentList Sema::getTemplateInstantiationArgs(
345345
using namespace TemplateInstArgsHelpers;
346346
const Decl *CurDecl = ND;
347347

348-
if (!ND)
348+
if (!CurDecl)
349349
CurDecl = Decl::castFromDeclContext(DC);
350350

351351
if (Innermost) {
352352
Result.addOuterTemplateArguments(const_cast<NamedDecl *>(ND),
353353
Innermost->asArray(), Final);
354-
if (CurDecl->getDeclContext()->isFileContext())
355-
if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(CurDecl))
356-
HandleDefaultTempArgIntoTempTempParam(TTP, Result);
354+
// Populate placeholder template arguments for TemplateTemplateParmDecls
355+
// that live in a file-scope DeclContext. This is essential for the case
356+
// e.g.
357+
//
358+
// template <class> concept Concept = false;
359+
// template <template <Concept C> class T> void foo(T<int>)
360+
//
361+
// where parameter C has a depth of 1 but the substituting argument `int`
362+
// has a depth of 0.
363+
if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(CurDecl))
364+
HandleDefaultTempArgIntoTempTempParam(TTP, Result);
357365
CurDecl = Response::UseNextDecl(CurDecl).NextDecl;
358366
}
359367

@@ -384,10 +392,8 @@ MultiLevelTemplateArgumentList Sema::getTemplateInstantiationArgs(
384392
R = Response::ChangeDecl(CTD->getLexicalDeclContext());
385393
} else if (!isa<DeclContext>(CurDecl)) {
386394
R = Response::DontClearRelativeToPrimaryNextDecl(CurDecl);
387-
if (CurDecl->getDeclContext()->isTranslationUnit()) {
388-
if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(CurDecl)) {
389-
R = HandleDefaultTempArgIntoTempTempParam(TTP, Result);
390-
}
395+
if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(CurDecl)) {
396+
R = HandleDefaultTempArgIntoTempTempParam(TTP, Result);
391397
}
392398
} else {
393399
R = HandleGenericDeclContext(CurDecl);

clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ concept True = true;
6868
template<typename T>
6969
concept False = false; // #False
7070

71+
template <class> struct S {};
72+
7173
template<template<True T> typename Wrapper>
7274
using Test = Wrapper<int>;
7375

@@ -77,10 +79,12 @@ using Test = Wrapper<int>; // expected-error {{constraints not satisfied for tem
7779
// expected-note@#TTP-Wrapper {{'int' does not satisfy 'False'}}
7880
// expected-note@#False {{evaluated to false}}
7981

80-
template <template<False> typename T> // #TTP-foo
81-
void foo(T<int>); // expected-error {{constraints not satisfied for template template parameter 'T' [with $0 = int]}}
82+
template <typename U, template<False> typename T>
83+
void foo(T<U>); // #foo
8284

83-
// expected-note@#TTP-foo {{'int' does not satisfy 'False'}}
84-
// expected-note@#False {{evaluated to false}}
85+
void bar() {
86+
foo<int>(S<int>{}); // expected-error {{no matching function for call to 'foo'}}
87+
// expected-note@#foo {{substitution failure [with U = int]: constraints not satisfied for template template parameter 'T' [with $0 = int]}}
88+
}
8589

8690
}

0 commit comments

Comments
 (0)