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.