Consider the following snippet:
struct Foo {};
int main()
{
Foo f;
f.~decltype(f)(); // fine with clang, error with gcc
f.~decltype(auto)(); // error with both clang and gcc
}
The rules for an explicit destructor call are handled by the standard grammar with pseudo-destructor-name
which is defined as follows:
pseudo-destructor-name:
nested-name-specifier opt type-name :: ~ type-name
nested-name-specifier template simple-template-id :: ~type-name
~ type-name
~ decltype-specifier
And:
decltype-specifier:
decltype ( expression )
decltype ( auto )
Then shouldn't the above snippet be well-formed as per standard? (Not considering the fact that the destructor is called twice and then a third time on the same object.)
GCC Live
Clang Live
Your program is ill-formed.
§7.1.6.4/[dcl.spec.auto] states:
A program that uses
auto
ordecltype(auto)
in a context not explicitly allowed in this section is ill-formed.
There, I cannot find anything that should allow you to write this. Generally, decltype(auto)
is used in variable and function declarations only. The fact the grammar allows is doesn't mean it's well-formed, though.
Therefore, writing something like f.~decltype(f)()
hasn't been explicitely forbidden and is allowed as stated in the grammar. The fact that the GCC won't compile it is most likely a bug.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With