From c9eb594cefa0659639aae641dc6847c92196dc89 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 5 Apr 2023 13:37:22 -0700 Subject: Warn on dangling comparison operator. (#2779) Fixes #1685 Co-authored-by: Yong He --- source/slang/slang-check-stmt.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source/slang/slang-check-stmt.cpp') diff --git a/source/slang/slang-check-stmt.cpp b/source/slang/slang-check-stmt.cpp index a61f48af6..6efc3e52e 100644 --- a/source/slang/slang-check-stmt.cpp +++ b/source/slang/slang-check-stmt.cpp @@ -339,6 +339,16 @@ namespace Slang void SemanticsStmtVisitor::visitExpressionStmt(ExpressionStmt *stmt) { stmt->expression = CheckExpr(stmt->expression); + if (auto operatorExpr = as(stmt->expression)) + { + if (auto func = as(operatorExpr->functionExpr)) + { + if (func->name && func->name->text == "==") + { + getSink()->diagnose(operatorExpr, Diagnostics::danglingEqualityExpr); + } + } + } } void SemanticsStmtVisitor::tryInferLoopMaxIterations(ForStmt* stmt) -- cgit v1.2.3