https://github.com/zyn0217 updated https://github.com/llvm/llvm-project/pull/93556
>From 76639804b9e5391169e76c5b07650c11d64003de Mon Sep 17 00:00:00 2001 From: Younan Zhang <zyn7...@gmail.com> Date: Tue, 28 May 2024 22:11:25 +0800 Subject: [PATCH] [Clang][Sema] Use StructuralValues to model dependent NTTP arguments --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/AST/TemplateBase.cpp | 7 +++++- .../SemaTemplate/temp_arg_nontype_cxx2c.cpp | 23 ++++++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 49ab222bec405..722efd08721c3 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -710,6 +710,7 @@ Bug Fixes to C++ Support - Correctly treat the compound statement of an ``if consteval`` as an immediate context. Fixes (#GH91509). - When partial ordering alias templates against template template parameters, allow pack expansions when the alias has a fixed-size parameter list. Fixes (#GH62529). +- 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 3310d7dc24c59..e6b23eddb5888 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@-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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits