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

[EMAIL PROTECTED]  [Work]
[EMAIL PROTECTED]           [Personal]



Reply via email to