This is the mail archive of the gcc@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]

Accessing const object during constructor without this pointer


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]




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