[clang] bb42511 - [Clang][Sema] Use StructuralValues to model dependent NTTP arguments (#93556)
via cfe-commits
cfe-commits at lists.llvm.org
Tue May 28 21:58:48 PDT 2024
Author: Younan Zhang
Date: 2024-05-29T12:58:44+08:00
New Revision: bb42511f64fd44f2ff1beb0dd38a653a8f2c20df
URL: https://github.com/llvm/llvm-project/commit/bb42511f64fd44f2ff1beb0dd38a653a8f2c20df
DIFF: https://github.com/llvm/llvm-project/commit/bb42511f64fd44f2ff1beb0dd38a653a8f2c20df.diff
LOG: [Clang][Sema] Use StructuralValues to model dependent NTTP arguments (#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, #92292 seems different.
Fixes https://github.com/llvm/llvm-project/issues/84052
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/AST/TemplateBase.cpp
clang/test/SemaTemplate/temp_arg_nontype_cxx2c.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9091f6341bd9b..bd92818f0c09d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -810,6 +810,7 @@ Bug Fixes to C++ Support
- Clang now diagnoses unexpanded parameter packs in attributes. (Fixes #GH93269).
- Clang now allows ``@$``` in raw string literals. Fixes (#GH93130).
- Fix an assertion failure when checking invalid ``this`` usage in the wrong context. (Fixes #GH91536).
+- Clang no longer models dependent NTTP arguments as ``TemplateParamObjectDecl`` s. Fixes (#GH84052).
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp
index a7ee973b7f7d0..b50daf5fbed6a 100644
--- a/clang/lib/AST/TemplateBase.cpp
+++ b/clang/lib/AST/TemplateBase.cpp
@@ -221,8 +221,13 @@ static const ValueDecl *getAsSimpleValueDeclRef(const ASTContext &Ctx,
// We model class non-type template parameters as their template parameter
// object declaration.
- if (V.isStruct() || V.isUnion())
+ if (V.isStruct() || V.isUnion()) {
+ // Dependent types are not supposed to be described as
+ // TemplateParamObjectDecls.
+ if (T->isDependentType() || T->isInstantiationDependentType())
+ return nullptr;
return Ctx.getTemplateParamObjectDecl(T, V);
+ }
// Pointers and references with an empty path use the special 'Declaration'
// representation.
diff --git a/clang/test/SemaTemplate/temp_arg_nontype_cxx2c.cpp b/clang/test/SemaTemplate/temp_arg_nontype_cxx2c.cpp
index 9fb6b440b6b2a..e74c031eba4c1 100644
--- a/clang/test/SemaTemplate/temp_arg_nontype_cxx2c.cpp
+++ b/clang/test/SemaTemplate/temp_arg_nontype_cxx2c.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c++20 -Wconversion -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++2c -Wconversion -verify %s
struct Test {
int a = 0;
@@ -102,3 +102,24 @@ void bar() {
}
}
+
+namespace GH84052 {
+
+template <class... T>
+concept C = sizeof(T...[1]) == 1; // #C
+
+struct A {};
+
+template <class T, C<T> auto = A{}> struct Set {}; // #Set
+
+template <class T> void foo() {
+ Set<T> unrelated;
+}
+
+Set<bool> sb;
+Set<float> sf;
+// expected-error at -1 {{constraints not satisfied for class template 'Set'}}
+// expected-note@#Set {{because 'C<decltype(GH84052::A{}), float>' evaluated to false}}
+// expected-note@#C {{evaluated to false}}
+
+} // namespace GH84052
More information about the cfe-commits
mailing list