Skip to content

Commit 6b34aa8

Browse files
committed
fix merge
1 parent 2bc3149 commit 6b34aa8

File tree

1 file changed

+13
-39
lines changed

1 file changed

+13
-39
lines changed

clang/lib/Sema/SemaStmt.cpp

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,8 @@ static bool DiagnoseNoDiscard(Sema &S, const NamedDecl *OffendingDecl,
226226
return S.Diag(Loc, diag::warn_unused_result) << A << true << Msg << R1 << R2;
227227
}
228228

229-
static void DiagnoseUnused(Sema &S, const Expr *E,
230-
std::optional<unsigned> DiagID) {
231-
// When called from Sema::DiagnoseUnusedExprResult, DiagID is a diagnostic for
232-
// where this expression is not used. When called from
233-
// Sema::DiagnoseDiscardedNodiscard, DiagID is std::nullopt and this function
234-
// will only diagnose [[nodiscard]], [[gnu::warn_unused_result]] and similar
229+
namespace {
230+
void DiagnoseUnused(Sema &S, const Expr *E, std::optional<unsigned> DiagID) {
235231
bool NoDiscardOnly = !DiagID.has_value();
236232

237233
// If we are in an unevaluated expression context, then there can be no unused
@@ -294,17 +290,10 @@ static void DiagnoseUnused(Sema &S, const Expr *E,
294290
if (E->getType()->isVoidType())
295291
return;
296292

297-
<<<<<<< HEAD
298-
if (DiagnoseNoDiscard(S,
299-
cast_if_present<WarnUnusedResultAttr>(
300-
CE->getUnusedResultAttr(S.Context)),
301-
Loc, R1, R2, /*isCtor=*/false))
302-
=======
303-
auto [OffendingDecl, A] = CE->getUnusedResultAttr(Context);
304-
if (DiagnoseNoDiscard(*this, OffendingDecl,
293+
auto [OffendingDecl, A] = CE->getUnusedResultAttr(S.Context);
294+
if (DiagnoseNoDiscard(S, OffendingDecl,
305295
cast_or_null<WarnUnusedResultAttr>(A), Loc, R1, R2,
306296
/*isCtor=*/false))
307-
>>>>>>> llvm_be_very_careful/main
308297
return;
309298

310299
// If the callee has attribute pure, const, or warn_unused_result, warn with
@@ -327,29 +316,19 @@ static void DiagnoseUnused(Sema &S, const Expr *E,
327316
if (const CXXConstructorDecl *Ctor = CE->getConstructor()) {
328317
const NamedDecl *OffendingDecl = nullptr;
329318
const auto *A = Ctor->getAttr<WarnUnusedResultAttr>();
330-
<<<<<<< HEAD
331-
A = A ? A : Ctor->getParent()->getAttr<WarnUnusedResultAttr>();
332-
if (DiagnoseNoDiscard(S, A, Loc, R1, R2, /*isCtor=*/true))
333-
=======
334319
if (!A) {
335320
OffendingDecl = Ctor->getParent();
336321
A = OffendingDecl->getAttr<WarnUnusedResultAttr>();
337322
}
338-
if (DiagnoseNoDiscard(*this, OffendingDecl, A, Loc, R1, R2,
323+
if (DiagnoseNoDiscard(S, OffendingDecl, A, Loc, R1, R2,
339324
/*isCtor=*/true))
340-
>>>>>>> llvm_be_very_careful/main
341325
return;
342326
}
343327
} else if (const auto *ILE = dyn_cast<InitListExpr>(E)) {
344328
if (const TagDecl *TD = ILE->getType()->getAsTagDecl()) {
345329

346-
<<<<<<< HEAD
347-
if (DiagnoseNoDiscard(S, TD->getAttr<WarnUnusedResultAttr>(), Loc, R1, R2,
348-
/*isCtor=*/false))
349-
=======
350-
if (DiagnoseNoDiscard(*this, TD, TD->getAttr<WarnUnusedResultAttr>(), Loc,
330+
if (DiagnoseNoDiscard(S, TD, TD->getAttr<WarnUnusedResultAttr>(), Loc,
351331
R1, R2, /*isCtor=*/false))
352-
>>>>>>> llvm_be_very_careful/main
353332
return;
354333
}
355334
} else if (ShouldSuppress)
@@ -363,13 +342,8 @@ static void DiagnoseUnused(Sema &S, const Expr *E,
363342
}
364343
const ObjCMethodDecl *MD = ME->getMethodDecl();
365344
if (MD) {
366-
<<<<<<< HEAD
367-
if (DiagnoseNoDiscard(S, MD->getAttr<WarnUnusedResultAttr>(), Loc, R1, R2,
345+
if (DiagnoseNoDiscard(S, nullptr, MD->getAttr<WarnUnusedResultAttr>(), Loc, R1, R2,
368346
/*isCtor=*/false))
369-
=======
370-
if (DiagnoseNoDiscard(*this, nullptr, MD->getAttr<WarnUnusedResultAttr>(),
371-
Loc, R1, R2, /*isCtor=*/false))
372-
>>>>>>> llvm_be_very_careful/main
373347
return;
374348
}
375349
} else if (const PseudoObjectExpr *POE = dyn_cast<PseudoObjectExpr>(E)) {
@@ -422,16 +396,21 @@ static void DiagnoseUnused(Sema &S, const Expr *E,
422396
return;
423397
}
424398

399+
// Don't diagnose discarded left of dot in static class member access
400+
// because its type is "used" to determine the class to access
401+
//if (DiagID == diag::warn_discarded_class_member_access)
402+
// return;
403+
425404
// Do not diagnose use of a comma operator in a SFINAE context because the
426405
// type of the left operand could be used for SFINAE, so technically it is
427406
// *used*.
428-
<<<<<<< HEAD
429407
if (DiagID == diag::warn_unused_comma_left_operand && S.isSFINAEContext())
430408
return;
431409

432410
S.DiagIfReachable(Loc, llvm::ArrayRef<const Stmt *>(E),
433411
S.PDiag(*DiagID) << R1 << R2);
434412
}
413+
} // namespace
435414

436415
void Sema::DiagnoseDiscardedNodiscard(const Expr *E) {
437416
DiagnoseUnused(*this, E, std::nullopt);
@@ -446,11 +425,6 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID) {
446425
return;
447426

448427
DiagnoseUnused(*this, E, DiagID);
449-
=======
450-
if (DiagID != diag::warn_unused_comma_left_operand || !isSFINAEContext())
451-
DiagIfReachable(Loc, S ? llvm::ArrayRef(S) : llvm::ArrayRef<Stmt *>(),
452-
PDiag(DiagID) << R1 << R2);
453-
>>>>>>> llvm_be_very_careful/main
454428
}
455429

456430
void Sema::ActOnStartOfCompoundStmt(bool IsStmtExpr) {

0 commit comments

Comments
 (0)