This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Accessing const object during constructor without this pointer
- From: Pankaj Gupta <pankaj at tower-research dot com>
- To: gcc at gcc dot gnu dot org
- Date: Mon, 5 Dec 2005 15:14:52 -0500 (EST)
- Subject: Accessing const object during constructor without this pointer
- References: <10511181342.AA21738@vlsi1.ultra.nyu.edu> <20051118212128.GB24449@redhat.com> <Pine.LNX.4.61.0511181639250.20210@pankajlinux.tower-research.com>
Hi
I have a question. Consider this code:
#include <iostream>
void global_init();
class A {
public:
int i;
A() : i(10) {
global_init();
}
};
const A obj;
void global_init() {
std::cout << "obj.i = " << obj.i << std::endl;
}
int main() {
return EXIT_SUCCESS;
}
Here, global_init() is accessing a subobject of a const object, while its
being constructed. I think the standard says that, if the access in not
being made through the constructor's "this" (directly or indirectly), the
value of the const object or any subobject is unspecified.
But when I compile using g++, I don't get any warnings about it.
Any idea if this should be giving warnings or not.
Best Regards
Pankaj
--
Pankaj Gupta
Infrastructure Team
Tower Research Capital
pankaj.gupta@tower-research.com [Work]
pankaj.gupta@yahoo.com [Personal]