Skip to content

Commit ce51248

Browse files
authored
[Clang] Fix an incorrect assertion in Sema::CheckAddressOfOperand (#159314)
Not all non-type template arguments are modeled as NonTypeTemplateParmDecl. Fixes #151531
1 parent 6a726e9 commit ce51248

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ Bug Fixes to C++ Support
396396
the function type.
397397
- Fix an assertion failure when a ``constexpr`` variable is only referenced through
398398
``__builtin_addressof``, and related issues with builtin arguments. (#GH154034)
399+
- Fix an assertion failure when taking the address on a non-type template parameter argument of
400+
object type. (#GH151531)
399401

400402
Bug Fixes to AST Handling
401403
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaExpr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14725,8 +14725,9 @@ QualType Sema::CheckAddressOfOperand(ExprResult &OrigOp, SourceLocation OpLoc) {
1472514725
return MPTy;
1472614726
}
1472714727
}
14728-
} else if (!isa<FunctionDecl, NonTypeTemplateParmDecl, BindingDecl,
14729-
MSGuidDecl, UnnamedGlobalConstantDecl>(dcl))
14728+
} else if (!isa<FunctionDecl, TemplateParamObjectDecl,
14729+
NonTypeTemplateParmDecl, BindingDecl, MSGuidDecl,
14730+
UnnamedGlobalConstantDecl>(dcl))
1473014731
llvm_unreachable("Unknown/unexpected decl type");
1473114732
}
1473214733

clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,3 +371,18 @@ namespace ReportedRegression2 {
371371
fn<str>();
372372
}
373373
}
374+
375+
namespace GH151531 {
376+
struct w {
377+
int n;
378+
};
379+
380+
template <const w *X> void f() { static_assert(X->n == 42); }
381+
382+
template <w X> void g() { f<&X>(); }
383+
384+
void test() {
385+
constexpr w X = {42};
386+
g<X>();
387+
}
388+
}

0 commit comments

Comments
 (0)