<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/70605>70605</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Enum not in scope inside its (fixed underlying) enum type specifier
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          alexshpilkin
      </td>
    </tr>
</table>

<pre>
    Quoth C23 draft [N3096](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf) in 6.2.1p7 (I haven’t seen the more recent but paywalled N3149):

> Structure, union, and enumeration tags have scope that begins just after the appearance of the tag in a type specifier that declares the tag.

In [Clang trunk](https://godbolt.org/z/evfchebb6) with `-std=c23` as well as Clang 16.0.6 with `-std=c2x`, on the other hand, I can refer to the enclosing scope’s definition of the tag being declared inside the *enum-type-specifier*, even though I wouldn’t have been able to do that later inside the *enumerator-list*:

```c
struct foo { int x; };
void bar(void) { enum foo : typeof(((struct foo *)0)->x); }
// void baz(void) { enum foo { A = sizeof(((struct foo *)0)->x) }; }
// ^^^ error: use of 'foo' with tag type that does not match previous declaration
```

So this looks to be wrong as far as C23 is concerned. Replacing `typeof` by `decltype`, I also see this being accepted in C++ mode with `-std=c++11`, `c++14`, `c++17` and `c++20`. I don’t know if that’s correct for C++, but I would be surprised if so, because it’s certainly inconsistent with how the typical instance of the CRTP works.

See also https://github.com/llvm/llvm-project/issues/57836 re this feature in C generally.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVd2OozgTfRrnptQITALhIhedTkfKzej7ZvYFjF2Apx0b2SZ05ulXZejZzPSutFoJBSgq9XPOqbIIQfcW8cB2R7Y7bcQUB-cPwuB7GEZt3rTdtE7dD_-fXBzghZegvOgisN3xS5k3FdudGN8PMY6Blc-Mnxk_z_OcuRHtU4gqc75n_Pw9yoLxc5Cck0Nfb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