Reputation: 1093
In C++0x -n3290 Draft : they added in section :Destructors : 12.4/2nd point last line
**A destructor shall not be declared with a ref-qualifier.**
In c++03 Draft .... they didn't mention this point in destructors ?
my question is whether
*~S() ; //this declaration is allowed or not according to the Standard's
//**~S(); ***~S() ; etc...........
this type of declaration is allowed ? No where in the Draft he described about this ...Declaration?
In GCC 4.6.0,Sun/Oracle C++12.0 , --->this declaration is allowed int Comeau C/C++ -->not allowed
Upvotes: 8
Views: 254
Reputation: 506925
The rule you are looking for is stated in the same paragraph, 12.4p2
A destructor takes no parameters, and no return type can be specified for it (not even void).
The phrase "no return type can be specified for it" also forbids "*", which is not immediately clear but can be seen by comparison with 12.3.2p1 (compare with this issue report):
... Such functions are called conversion functions. No return type can be specified.
That rule is what makes implementations forbid * operator int() { }
. You can also argue with 12.4p1, although as that's phrased very general and is the first statement in the destructors section, I think the other statement above should be the primary argument
A special declarator syntax using an optional function-specifier (7.1.2) followed by ˜ followed by the destructor's class name followed by an empty parameter list is used to declare the destructor in a class definition.
As can be seen/read there is no mention of declarators such as *
in that description, which shows the intent of the authors.
Upvotes: 1
Reputation: 208333
You have misunderstood what ref-qualifier means in the new standard. In the same way that you can provide a const
qualifier to any member function in C++03, you can also add a ref-qualifier to a member function in C++0x. That modifier will affect the type of the implicit this
argument to the function:
struct test {
void f() const &&; // implicit "this" in "f" is of type "test const &&"
};
In the same way that a destructor cannot be static
, or const
, or const volatile
in C++03, it cannot take a ref-qualifier (&
or &&
) in C++0x. Of course this bit was not present in the former standard.
Upvotes: 7
Reputation: 56048
That doesn't look like it would ever be a legal function declaration of any kind, much less for a destructor. I'm not positive what that part of the standard is talking about, but I have a guess.
I suspect there is a qualifier saying that your function is being called on an rvalue reference. Something like this:
class A {
public:
void IAmAnRValue() &&;
};
I think the language in the standard is saying that this qualifier is not allowed on a destructor, much like having a trailing const
would also be illegal.
And, on further investigation, my certainty of the correctness of my surmise goes up considerably. Here is the justification:
There it clearly states that functions may now have a 'ref-qualifier' after the 'cv-qualifer'. This means that a function declaration may now be followed by const &
or const volatile &&
instead of just const
. And the term used (ref-qualifier) is the same as the term used in the little bit of the standard you're quoting. And it makes sense for destructors to not be able to have one.
Upvotes: 10