Author: Corentin Jabot Date: 2025-09-17T14:38:08+02:00 New Revision: ce5124856e019792783de9630d0c5a1f0aaf2d9d
URL: https://github.com/llvm/llvm-project/commit/ce5124856e019792783de9630d0c5a1f0aaf2d9d DIFF: https://github.com/llvm/llvm-project/commit/ce5124856e019792783de9630d0c5a1f0aaf2d9d.diff LOG: [Clang] Fix an incorrect assertion in `Sema::CheckAddressOfOperand` (#159314) Not all non-type template arguments are modeled as NonTypeTemplateParmDecl. Fixes #151531 Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaExpr.cpp clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 518ed9e0f4b3e..80f4e83a11b70 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -396,6 +396,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>(); +} +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
