This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/71113] Adding "const" to value in constexpr constructor places const object in .bss instead of .rodata


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

--- Comment #1 from Freddie Chopin <freddie_chopin at op dot pl> ---
BTW, I've come to the code as above from a slightly different scenario -
initially I tried using references, but it was failing (placed in RAM, not in
flash) no matter what I did. Now I think that the two problems may be related,
so one more example:

-- >8 -- >8 -- >8 -- >8 -- >8 -- >8 -- >8 -- >8 --

class X
{
public:

        constexpr X(int& ref) :
                ref_{ref}
        {

        }

private:

        int& ref_;
};

#define PERIPHERAL1     (int*)0x20000000
const X xxx1 {*PERIPHERAL1};
int something;
const X xxx2 {something};

int main()
{

}

-- >8 -- >8 -- >8 -- >8 -- >8 -- >8 -- >8 -- >8 --

Test compilation:

-- >8 -- >8 -- >8 -- >8 -- >8 -- >8 -- >8 -- >8 --

$ g++ test.cpp && objdump -x --syms --demangle a.out | grep xxx
0000000000600a70 l     O .bss   0000000000000008              xxx1
0000000000400658 l     O .rodata        0000000000000008              xxx2

-- >8 -- >8 -- >8 -- >8 -- >8 -- >8 -- >8 -- >8 --

The object with reference to "real" int is placed in .rodata, the one with the
reference to "peripheral" - in .bss.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]