inclyc created this revision. Herald added a project: All. inclyc updated this revision to Diff 452665. inclyc added a comment. inclyc added reviewers: aaron.ballman, rtrieu. inclyc published this revision for review. Herald added a project: clang. Herald added a subscriber: cfe-commits.
comments Fixes https://github.com/llvm/llvm-project/issues/57151 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D131892 Files: clang/lib/Sema/SemaExpr.cpp clang/test/SemaCXX/warn-comma-operator.cpp Index: clang/test/SemaCXX/warn-comma-operator.cpp =================================================================== --- clang/test/SemaCXX/warn-comma-operator.cpp +++ clang/test/SemaCXX/warn-comma-operator.cpp @@ -140,6 +140,16 @@ // CHECK: fix-it:{{.*}}:{[[@LINE-8]]:46-[[@LINE-8]]:46}:")" } + +void void_func(); +int int_func() { return 0; } + +void buggy(){ + void_func(), int_func(); // expected no -Wcomma because of the returning type `void` + // Reported by https://github.com/llvm/llvm-project/issues/57151 + // Descriptions about -Wcomma: https://reviews.llvm.org/D3976 +} + #ifdef __cplusplus class S2 { public: Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -13958,7 +13958,7 @@ } // Only ignore explicit casts to void. -static bool IgnoreCommaOperand(const Expr *E) { +static bool IgnoreCommaOperand(const Expr *E, const ASTContext &Context) { E = E->IgnoreParens(); if (const CastExpr *CE = dyn_cast<CastExpr>(E)) { @@ -13973,6 +13973,9 @@ } } + if (const CallExpr *CE = dyn_cast<CallExpr>(E)) + if (const Type *T = CE->getCallReturnType(Context).getTypePtrOrNull()) + return T->isVoidType(); return false; } @@ -14014,7 +14017,7 @@ } // Only allow some expressions on LHS to not warn. - if (IgnoreCommaOperand(LHS)) + if (IgnoreCommaOperand(LHS, Context)) return; Diag(Loc, diag::warn_comma_operator);
Index: clang/test/SemaCXX/warn-comma-operator.cpp =================================================================== --- clang/test/SemaCXX/warn-comma-operator.cpp +++ clang/test/SemaCXX/warn-comma-operator.cpp @@ -140,6 +140,16 @@ // CHECK: fix-it:{{.*}}:{[[@LINE-8]]:46-[[@LINE-8]]:46}:")" } + +void void_func(); +int int_func() { return 0; } + +void buggy(){ + void_func(), int_func(); // expected no -Wcomma because of the returning type `void` + // Reported by https://github.com/llvm/llvm-project/issues/57151 + // Descriptions about -Wcomma: https://reviews.llvm.org/D3976 +} + #ifdef __cplusplus class S2 { public: Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -13958,7 +13958,7 @@ } // Only ignore explicit casts to void. -static bool IgnoreCommaOperand(const Expr *E) { +static bool IgnoreCommaOperand(const Expr *E, const ASTContext &Context) { E = E->IgnoreParens(); if (const CastExpr *CE = dyn_cast<CastExpr>(E)) { @@ -13973,6 +13973,9 @@ } } + if (const CallExpr *CE = dyn_cast<CallExpr>(E)) + if (const Type *T = CE->getCallReturnType(Context).getTypePtrOrNull()) + return T->isVoidType(); return false; } @@ -14014,7 +14017,7 @@ } // Only allow some expressions on LHS to not warn. - if (IgnoreCommaOperand(LHS)) + if (IgnoreCommaOperand(LHS, Context)) return; Diag(Loc, diag::warn_comma_operator);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits