S
shurjyaprabha ray
I have the following code:
(Yes, I understand there is a circular
dependency and that this is a Bad
Thing to do, but bear with me.)
struct a;
struct b {
a* a_;
b() : a_(0) {}
void set(a* t) { a_ = t; }
void change();
};
struct a {
int data_;
b& b_;
a(b& s) : b_(s), data_(42) {}
void strange() const {
b_.change();
}
};
void b::change() {
if (!a_)
a_->data_ = -42;
}
int main()
{
b m;
a n(m);
m.set(&n);
n.strange();
}
I consulted the draft n3090 and have problems
interpreting 7.1.6.1 §3 and §4. I read them as:
Since there is a const access path in a::strange
the call results in undefined behavior. Is this
correct? Or, is it that it invokes UB only in the
case that the object n was originally declared
const? (Yes, I consulted 9.3.2 §1 and §2 in
conjunction to the sections mentioned above.)
Any help would be greatly appreciated.
(Yes, I understand there is a circular
dependency and that this is a Bad
Thing to do, but bear with me.)
struct a;
struct b {
a* a_;
b() : a_(0) {}
void set(a* t) { a_ = t; }
void change();
};
struct a {
int data_;
b& b_;
a(b& s) : b_(s), data_(42) {}
void strange() const {
b_.change();
}
};
void b::change() {
if (!a_)
a_->data_ = -42;
}
int main()
{
b m;
a n(m);
m.set(&n);
n.strange();
}
I consulted the draft n3090 and have problems
interpreting 7.1.6.1 §3 and §4. I read them as:
Since there is a const access path in a::strange
the call results in undefined behavior. Is this
correct? Or, is it that it invokes UB only in the
case that the object n was originally declared
const? (Yes, I consulted 9.3.2 §1 and §2 in
conjunction to the sections mentioned above.)
Any help would be greatly appreciated.