Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions clang/lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1619,8 +1619,9 @@ std::pair<const NamedDecl *, const Attr *>
CallExpr::getUnusedResultAttr(const ASTContext &Ctx) const {
// If the callee is marked nodiscard, return that attribute
const Decl *D = getCalleeDecl();
if (const auto *A = D->getAttr<WarnUnusedResultAttr>())
return {nullptr, A};
if (D != nullptr)
if (const auto *A = D->getAttr<WarnUnusedResultAttr>())
return {nullptr, A};

// If the return type is a struct, union, or enum that is marked nodiscard,
// then return the return type attribute.
Expand Down
9 changes: 9 additions & 0 deletions clang/test/SemaCXX/warn-unused-result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,12 @@ void use2() {
(void)G{"Hello"};
}
} // namespace nodiscard_specialization

namespace GH117975 {
// Test for a regression for ICE in CallExpr::getUnusedResultAttr
int f() { return 0; }
void id_print_name() {
(int) // expected-warning {{expression result unused}}
((int(*)())f)();
}
} // namespace GH117975
Loading