Topic: declaration/expression-statement ambiguity involving destructor
Author: James Kuyper <kuyper@wizard.net>
Date: 1999/12/22 Raw View
Sandra Loosemore wrote:
>
> I can't find any explicit mention of this ambiguity in the spec.
>
> class C {
> ~C();
> void f ()
> {
> C::~C(); // redeclaration or expression-statement?
> }
> };
Section 9.3 p2: "Except for member function definitions, that appear
outside of a class definition, and except for explicit specializations
of template member functions (14.7) appearing outside of the class
defintion, a member function shall not be redeclared."
Therefore, it must be an expression-statement; no ambiguity, and
therefore no ambiguity resolution is needed.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Sandra Loosemore <sandra@shore.net>
Date: 1999/12/23 Raw View
James Kuyper <kuyper@wizard.net> writes:
> Sandra Loosemore wrote:
> >
> > I can't find any explicit mention of this ambiguity in the spec.
> >
> > class C {
> > ~C();
> > void f ()
> > {
> > C::~C(); // redeclaration or expression-statement?
> > }
> > };
>
> Section 9.3 p2: "Except for member function definitions, that appear
> outside of a class definition, and except for explicit specializations
> of template member functions (14.7) appearing outside of the class
> defintion, a member function shall not be redeclared."
>
> Therefore, it must be an expression-statement; no ambiguity, and
> therefore no ambiguity resolution is needed.
Ah, but is this a semantic restriction, or a syntactic one? I think
"C::~C();" is still a syntactically correct simple-declaration
according to the grammar. The ambiguity only happens with special
member functions that don't have a return type, so if you wanted to
disallow this at a syntactic level, the grammar ought to say
simple-declaration::
decl-specifier-seq init-declarator-list(opt)
instead of what it actually says,
simple-declaration::
decl-specifier-seq(opt) init-declarator-list(opt)
-Sandra
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Sandra Loosemore <sandra@shore.net>
Date: 1999/12/20 Raw View
I can't find any explicit mention of this ambiguity in the spec.
class C {
~C();
void f ()
{
C::~C(); // redeclaration or expression-statement?
}
};
The spec says that the ambiguity between a functional cast expression and
a declaration is resolved in favor of a declaration. Is this one also
resolved as a declaration?
I am not sure how useful the interpretation as a declaration would be, but
of course you can say
this->C::~C();
to unambiguously invoke the destructor instead.
-Sandra
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]