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

2021-08-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71113

Andrew Pinski  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2021-08-10
 Ever confirmed|0   |1

--- Comment #2 from Andrew Pinski  ---
Confirmed.

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

2016-05-14 Thread freddie_chopin at op dot pl
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71113

--- Comment #1 from Freddie Chopin  ---
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*)0x2000
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
00600a70 l O .bss   0008  xxx1
00400658 l O .rodata0008  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.