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

--- Comment #25 from Erich Löw <Erich.Loew at outlook dot com> ---
With system GCC 15.0.1 I do as below....

I created: main.cc

#include <stdio.h>
#include <stdlib.h>

struct A { A() { } };

[[gnu::init_priority(99)]] A a;
[[gnu::init_priority(99)]] A a2;

struct B { B() { } };
[[gnu::init_priority(99)]] B b;

int main(int argc, char* argv[])
{
    void const *const addrA1 = (void const *const)&a;
    void const *const addrA2 = (void const *const)&a2;
    void const *const addrB  = (void const *const)&b;

    printf("Addr(a)  == 0x%016Xu\n", addrA1);
    printf("Addr(a2) == 0x%016Xu\n", addrA2);
    printf("Addr(b)  == 0x%016Xu\n", addrB);

    return 0;
}

The obligatory Makefile

# MAKE file

CXX = g++
LD  = g++ -s

INC = -I./

test: all

all: 118981

clean:
        -rm -f *.o *.so
        -rm -f 118981

118981 : main.cc
        $(CXX) $(INC) -c -o main.o main.cc
        $(LD) -o 118981 main.o

------------------------------------------------

Compiling with close to LATEST system GCC 15.0.1

root:/home/SETUP/Examples/GNU-118981> g++ --version
g++ (GCC) 15.0.1 20250218 (experimental)
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

shows results a you predicted

root:/home/SETUP/Examples/GNU-118981> make clean
rm -f *.o *.so
rm -f 118981
root:/home/SETUP/Examples/GNU-118981> make all
g++ -I./ -c -o main.o main.cc
main.cc:6:30: warning: requested ‘init_priority’ 99 is reserved for internal
use [-Wprio-ctor-dtor]
    6 | [[gnu::init_priority(99)]] A a;
      |                              ^
main.cc:7:30: warning: requested ‘init_priority’ 99 is reserved for internal
use [-Wprio-ctor-dtor]
    7 | [[gnu::init_priority(99)]] A a2;
      |                              ^~
main.cc:10:30: warning: requested ‘init_priority’ 99 is reserved for internal
use [-Wprio-ctor-dtor]
   10 | [[gnu::init_priority(99)]] B b;
      |                              ^
g++ -s -o 118981 main.o

Hence using 99 multiple times with system GCC works.

Now I check with interim xgcc in next comment slice.

--------------------------------------------------------------------------------------------

Reply via email to