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

            Bug ID: 95094
           Summary: alignof(reference_to_type) doesn't return
                    alignof(referenced_type) as it ought to, by the
                    standard
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sinbal2l at gmail dot com
  Target Milestone: ---

>From the C++ standard:

7.6.2.5 Alignof [expr.alignof]p3

3 When alignof is applied to a reference type, the result is the alignment of
the *referenced* type.  

IINM, in the latest version, the returned value is of the reference itself:

#include <stdio.h>

int main() {
    alignas(32) double d;
    double &ref_d = d;

    printf("Alignment of d: %d\n", alignof(d));             // 32
    printf("Alignment of ref_d: %d\n", alignof(ref_d));     // 8
}

https://godbolt.org/z/S9UJUv

P.S. thank you very much for doing such a great job! (3) (94594)

Reply via email to