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

            Bug ID: 127411
           Summary: Compilation errors with nonprimitive register-mapped
                    variables in C++ mode
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pskocik at gmail dot com
  Target Milestone: ---

Example code:

typedef struct Long { long _; } Long; /*nonprimitive type*/
int main(void){
    (void)({ register long x asm("rdx"); asm volatile("":"+r"(x)); x;}); //✓
    (void)({ register Long x asm("rdx"); asm volatile("":"+r"(x)); x;}); //✗
g++ :(
    #if __cplusplus
        (void)[]{ register long x asm("rdx"); asm volatile("":"+r"(x)); return
x;}(); //✓
        (void)[]{ register Long x asm("rdx"); asm volatile("":"+r"(x)); return
x;}(); //✗ on g++ :(
    #endif
}

This works in C mode and on clang and clang++, but g++ reports:  `error:
address of explicit register variable ‘x’ requested` despite no explicit
address-taking.

https://godbolt.org/z/jxP5h3bMT

Reply via email to