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(dcl)) + } else if (!isa(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(); } } + +namespace GH151531 { +struct w { + int n; +}; + +template void f() { static_assert(X->n == 42); } + +template void g() { f<&X>(); } + +void test() { + constexpr w X = {42}; + g(); +} +}