================
@@ -1035,3 +1035,19 @@ void instantiate() {
ignoreInstantiations<true>();
ignoreInstantiations<false>();
}
+
+void if_with_init_statement() {
+ bool x = true;
+ if (bool y = x; y == true) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: redundant boolean literal
supplied to boolean operator [readability-simplify-boolean-expr]
+ // CHECK-FIXES: if (bool y = x; y) {
+ }
----------------
Anshul200677 wrote:
The braces are necessary to preserve the scope of the variable declared in the
init-statement.
For example, in if (int i = 0; true) ..., the variable i is scoped to the if
statement. If we strip the braces and generate int i = 0; ..., the variable i
would leak into the surrounding scope. This could cause naming conflicts
(redefinition errors) or change the lifetime of the object (destructors running
too late).
The braces ensure the generated code preserves the original semantics of the
init-statement.
https://github.com/llvm/llvm-project/pull/172220
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits