[PATCH] D133289: [C2X] N3007 Type inference for object definitions

Shafik Yaghmour via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 21 11:17:16 PDT 2022


shafik added inline comments.


================
Comment at: clang/test/Sema/c2x-auto.c:49
+    auto b = 9;
+    auto c = a + b;
+  }
----------------
aaron.ballman wrote:
> to268 wrote:
> > shafik wrote:
> > > When I made the comment about the example from the proposal, this was what I was thinking about.
> > Do i need to treat shadowing when using `auto` as invalid?
> You shouldn't need to do anything special there, I think. It should naturally fall out that you cannot use a variable in its own initialization. Note, you don't even need an inner scope for that: https://godbolt.org/z/EYa3fMxqx (example is compiled in C++ mode).
The scope of the identifier begins after its `declarator` so `a` is being used in it's own deduction which can not be.

e.g.

```
  double a = 1.0;
    {
        int a = a*a; // undefined behavior a is used uninitialized within it's own initialization
    }
```



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133289/new/

https://reviews.llvm.org/D133289



More information about the cfe-commits mailing list