Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/lib/Analysis/UnsafeBufferUsage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4458,6 +4458,10 @@ void clang::checkUnsafeBufferUsage(const Decl *D,
SmallVector<Stmt *> Stmts;

if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
// Consteval functions are free of UB by the spec, so we don't need to
// visit them or produce diagnostics.
if (FD->isConsteval())
return;
// We do not want to visit a Lambda expression defined inside a method
// independently. Instead, it should be visited along with the outer method.
// FIXME: do we want to do the same thing for `BlockDecl`s?
Expand Down
7 changes: 7 additions & 0 deletions clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,4 +406,11 @@ void testMultiLineDeclStmt(int * p) {
foo(ap1[1]); // expected-note{{used in buffer access here}}
}

#if __cplusplus >= 202002L
consteval void testConstevalPtrArithmetic(int idx) {
int y[3] = {0, 1, 2};
foo(y[idx]);
}
#endif

#endif