Jan Tušil
2018-11-27 20:08:35 UTC
Consider a program P1:
```
struct S {
~S(); // no implicit definition!
};
int main() {
S s;
}
```
Is `S::~S` odr-used in P1? Yes. Clang complains
```
undefined reference to `S::~S()'
```
because `S::~S` is potentially-invoked at the end of the function
`main` because it is invoked here,
because a block in which `s` is defined exits here. This is what N4778 says
in 10.3.6/12:
A destructor is invoked implicitly [...] for a constructed object with
A destructor is potentially invoked if it is invoked or as specified in
```
struct S {
~S(); // no implicit definition!
};
int main() {
S s;
while(true)
;
}
```
The block in the function `main` never exits, so S::~S is not odr-used. But
this is weird: odr-use depends on termination, which is undecidable. The
loop may as well be trying to find a counterexample to Fermat's last
theorem, and break when successful.
be similar to the definition of `potentially-evaluated expression`. And
decidable.
So I have three questions:
1. is `S::~S` odr-used in P2?
2. if (1) is false, why?
3. if (1) is true, do we want it that way?
```
struct S {
~S(); // no implicit definition!
};
int main() {
S s;
}
```
Is `S::~S` odr-used in P1? Yes. Clang complains
```
undefined reference to `S::~S()'
```
because `S::~S` is potentially-invoked at the end of the function
`main` because it is invoked here,
because a block in which `s` is defined exits here. This is what N4778 says
in 10.3.6/12:
A destructor is invoked implicitly [...] for a constructed object with
automatic storage duration (6.6.4.3)
when the block in which an object is created exits (8.7).A destructor is potentially invoked if it is invoked or as specified in
[...]
But consider a program P2:```
struct S {
~S(); // no implicit definition!
};
int main() {
S s;
while(true)
;
}
```
The block in the function `main` never exits, so S::~S is not odr-used. But
this is weird: odr-use depends on termination, which is undecidable. The
loop may as well be trying to find a counterexample to Fermat's last
theorem, and break when successful.
A destructor is potentially invoked if it is invoked or as specified in
[...]
since I would expect the definition of `potentially-invoked destructor` to[...]
be similar to the definition of `potentially-evaluated expression`. And
decidable.
So I have three questions:
1. is `S::~S` odr-used in P2?
2. if (1) is false, why?
3. if (1) is true, do we want it that way?
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.