================
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wconditional-scope %s
+
+int *get_something();
+int *get_something_else();
+int *get_something_else_again();
+
+int test() {
+  if (int *ptr = get_something()) {
+    return ptr[0] * ptr[0];
+  }
+  else if (int *ptr2 = get_something_else()) {
+    // expected-warning@+1{{variable ptr used in else/else if block is out of 
scope}}
----------------
shafik wrote:

I don't think this diagnostic is a good explanation of the problem.

The issue is that `ptr` must be a `nullptr` in the `else` branch and therefore  
dereferencing it will be undefined behavior. 

It is definitely in scope otherwise that would be ill-formed.

https://github.com/llvm/llvm-project/pull/156436
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to