Issue 244855
Summary Incorrectly handling access to class members in attributes preceding out-of-class member definitions
Labels new issue
Assignees
Reporter daniel-petrovic
    The following code is rejected:

```cpp
class C {
public:
    static constexpr int kAlign2 = 8;

private:
    static constexpr int kAlign3 = 8;

    static int s1;
 static int s2;
    static int s3;
};

__attribute__((aligned(8))) int C::s1 = 0;
__attribute__((aligned(C::kAlign2))) int C::s2 = 0;
__attribute__((aligned(C::kAlign3))) int C::s3 = 0;
```
with error:
```
<source>:15:27: error: 'kAlign3' is a private member of 'C'
 15 | __attribute__((aligned(C::kAlign3))) int C::s3 = 0;
      | ^
<source>:6:26: note: declared private here
    6 | static constexpr int kAlign3 = 8
```

Godbolt: https://godbolt.org/z/cab43rhca

The code should be well-formed according to https://eel.is/c++draft/class.access.general#6. 

The clang doesn't seem to defer access check to the private member C::kAlign3 until the declarator C::s3 is available, at which point it provides the relevant access context.

The regression regarding **GNU style attributes** seems to have happened between 15.0.0 and 16.0.0.
This issue is currently present in gcc too: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128873

BUT

in contrary to gcc, clang also rejects member access in leading standard attributes like alignas and [[ ]]. 
And for those variants  I could not find any working older version (or I may have missed it).

Note: PR [#240734](https://github.com/llvm/llvm-project/pull/240734) introduced support for mixing GNU-style and standard attributes in namespace scope. This exposed some issues that previously existed only at global scope, making them observable in namespace scope as well.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to