llvm / llvm/llvm-project

[clang] Clang accepts out-of-line definition of an enum member of a local class

Open
#197,865 4 comments 0 reactions 0 assignees View on GitHub
accepts-invalid c++ clang:frontend cwg-issue
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

[[class.local]/3](https://eel.is/c++draft/class.local#3) says that the only member of a local class that can be defined out-of-line is a nested class:

> A class nested within a local class is a local class. A member of a local class `X` shall be declared only in the definition of `X` or, if the member is a nested class, in the nearest enclosing block scope of X.

But Clang currently accepts out-of-line definitions for enums too:

```cpp
void f() {
class A { enum E : int; };
enum A::E : int {};
}
```

Granted, so do all other major implementations: https://godbolt.org/z/9GTEzsT8x, so maybe we should consider this a standard defect. If others agree, I could file a core issue for it. We'll also have to make sure we don't repeat #193472 for enums.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.