[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 26 04:38:04 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Pil Eghoff (pileghoff)

<details>
<summary>Changes</summary>

Fixes #<!-- -->79435 

Im not sure if this is the best solution, but it seems to work well.
Should i be adding tests for this? If i should, i would need some help on how. 
I was able to run the test suite, but i have no idea where this test would go. My guess would be `tautological-constant-compare.c`, but that test seems to be C++ specific.

---
Full diff: https://github.com/llvm/llvm-project/pull/79588.diff


1 Files Affected:

- (modified) clang/lib/Sema/SemaChecking.cpp (+1-1) 


``````````diff
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 4d280f25cc04c2..8e3bd1cd46076d 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16166,7 +16166,7 @@ static void CheckConditionalOperator(Sema &S, AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema &S, Expr *E, SourceLocation CC) {
-  if (S.getLangOpts().Bool)
+  if (S.getLangOpts().Bool && !S.getLangOpts().C23)
     return;
   if (E->IgnoreParenImpCasts()->getType()->isAtomicType())
     return;

``````````

</details>


https://github.com/llvm/llvm-project/pull/79588


More information about the cfe-commits mailing list