Skip to content

Commit 3370da5

Browse files
zyn0217vg0204
authored andcommitted
[Clang][Sema] Use StructuralValues to model dependent NTTP arguments (llvm#93556)
This patch takes Richard's approach of no longer modeling dependent NTTP arguments with TemplateParamObjectDecls. Clang used to do so, which left behind a problem in that we might mess up dependent and non-dependent arguments that boil down to the same canonical type because there's a default argument on the NTTP. The problem of "canonical expression" is still present because this patch doesn't touch the profiling part. Namely, llvm#92292 seems different. Fixes llvm#84052
1 parent 46d0457 commit 3370da5

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ Bug Fixes to C++ Support
810810
- Clang now diagnoses unexpanded parameter packs in attributes. (Fixes #GH93269).
811811
- Clang now allows ``@$``` in raw string literals. Fixes (#GH93130).
812812
- Fix an assertion failure when checking invalid ``this`` usage in the wrong context. (Fixes #GH91536).
813+
- Clang no longer models dependent NTTP arguments as ``TemplateParamObjectDecl`` s. Fixes (#GH84052).
813814

814815
Bug Fixes to AST Handling
815816
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/AST/TemplateBase.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,13 @@ static const ValueDecl *getAsSimpleValueDeclRef(const ASTContext &Ctx,
221221

222222
// We model class non-type template parameters as their template parameter
223223
// object declaration.
224-
if (V.isStruct() || V.isUnion())
224+
if (V.isStruct() || V.isUnion()) {
225+
// Dependent types are not supposed to be described as
226+
// TemplateParamObjectDecls.
227+
if (T->isDependentType() || T->isInstantiationDependentType())
228+
return nullptr;
225229
return Ctx.getTemplateParamObjectDecl(T, V);
230+
}
226231

227232
// Pointers and references with an empty path use the special 'Declaration'
228233
// representation.

clang/test/SemaTemplate/temp_arg_nontype_cxx2c.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsyntax-only -std=c++20 -Wconversion -verify %s
1+
// RUN: %clang_cc1 -fsyntax-only -std=c++2c -Wconversion -verify %s
22

33
struct Test {
44
int a = 0;
@@ -102,3 +102,24 @@ void bar() {
102102
}
103103

104104
}
105+
106+
namespace GH84052 {
107+
108+
template <class... T>
109+
concept C = sizeof(T...[1]) == 1; // #C
110+
111+
struct A {};
112+
113+
template <class T, C<T> auto = A{}> struct Set {}; // #Set
114+
115+
template <class T> void foo() {
116+
Set<T> unrelated;
117+
}
118+
119+
Set<bool> sb;
120+
Set<float> sf;
121+
// expected-error@-1 {{constraints not satisfied for class template 'Set'}}
122+
// expected-note@#Set {{because 'C<decltype(GH84052::A{}), float>' evaluated to false}}
123+
// expected-note@#C {{evaluated to false}}
124+
125+
} // namespace GH84052

0 commit comments

Comments
 (0)