https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128873

            Bug ID: 128873
           Summary: GCC incorrectly handles access to class members in
                    attributes preceding out-of-class member definitions.
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: daniel-dev at hotmail dot de
  Target Milestone: ---

The following code is rejected by GCC:

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;

Error:

error: 'constexpr const int C::kAlign3' is private within this context
   __attribute__((aligned(C::kAlign3))) int C::s3 = 0;
                         ^~~~~~~
IMO according https://eel.is/c++draft/class.access.general#6

C::kAlign3 should be accessible in the definition of C::s3, just as C::kAlign2
is accessible in the definition of C::s2.


Compiler Explorer: https://godbolt.org/z/z8sMan6o6

Reply via email to