llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Corentin Jabot (cor3ntin) <details> <summary>Changes</summary> Not all non-type template arguments are modeled as NonTypeTemplateParmDecl. Fixes #<!-- -->151531 --- Full diff: https://github.com/llvm/llvm-project/pull/159314.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+2) - (modified) clang/lib/Sema/SemaExpr.cpp (+3-2) - (modified) clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp (+15) ``````````diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index f184eb1068f76..14f652c49c5b8 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -379,6 +379,8 @@ Bug Fixes to C++ Support the function type. - Fix an assertion failure when a ``constexpr`` variable is only referenced through ``__builtin_addressof``, and related issues with builtin arguments. (#GH154034) +- Fix an assertion failure when taking the address on a non-type template parameter argument of + object type. (#GH151531) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 73b16ae09e922..03def26fe53bd 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -14725,8 +14725,9 @@ QualType Sema::CheckAddressOfOperand(ExprResult &OrigOp, SourceLocation OpLoc) { return MPTy; } } - } else if (!isa<FunctionDecl, NonTypeTemplateParmDecl, BindingDecl, - MSGuidDecl, UnnamedGlobalConstantDecl>(dcl)) + } else if (!isa<FunctionDecl, TemplateParamObjectDecl, + NonTypeTemplateParmDecl, BindingDecl, MSGuidDecl, + UnnamedGlobalConstantDecl>(dcl)) llvm_unreachable("Unknown/unexpected decl type"); } diff --git a/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp b/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp index 56ceb7af4ccd9..8450ff037e184 100644 --- a/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp +++ b/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp @@ -371,3 +371,18 @@ namespace ReportedRegression2 { fn<str>(); } } + +namespace GH151531 { +struct w { + int n; +}; + +template <const w *X> void f() { static_assert(X->n == 42); } + +template <w X> void g() { f<&X>(); } + +void test() { + constexpr w X = {42}; + g<X>(); +} +} `````````` </details> https://github.com/llvm/llvm-project/pull/159314 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
