Topic: [Q] Exception specifiers on member functions in scope of class?
Author: rfg@netcom.com (Ronald F. Guilmette)
Date: Sun, 28 Nov 1993 23:54:19 GMT Raw View
In article <2ctamf$gk5@tornews.torolab.ibm.com> thomson@cppfs.torolab.ibm.com (Brian Thomson) writes:
>In article <rfgCGqGvv.49E@netcom.com> rfg@netcom.com (Ronald F. Guilmette) writes:
>>I assume that you are correct when you assert that parameter lists of member
>>functions are in the scope of the class (otherwise compilers would accept
>>the following short example... and most of the ones I have here don't)
>>but I'm just curious... where do it say that?? (I've looked in both 3.2
>>and 10.4 and haven't found this particular scope rule in either place.)
>
>I think you might combine 10.4 with 9.3, which says
>
> "The definition of a member function is considered to be within the
> scope of its class [... and ...] can use names of members of its class
> directly."
OK. But what exactly is "the definition of a member function". Does that
include the formal parameter list??
I have to believe that the answer is NO because given:
struct S
{
void foo (int i = value);
void bar (int i = value) { }
};
the member function `foo' has a definition, while the member function `bar'
doesn't. Note however that both of them have formal parameter lists.
The conclusion I draw is that "the definition" of a function (or member
function) is *only* the stuff between the curly braces.
--
-- Ronald F. Guilmette, Sunnyvale, California -------------------------------
------ domain address: rfg@netcom.com ---------------------------------------
------ uucp address: ...!uunet!netcom.com!rfg -------------------------------
Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Wed, 1 Dec 1993 03:43:49 GMT Raw View
rfg@netcom.com (Ronald F. Guilmette) writes:
>thomson@cppfs.torolab.ibm.com (Brian Thomson) writes:
>>I think you might combine 10.4 with 9.3, which says
>>
>> "The definition of a member function is considered to be within the
>> scope of its class [... and ...] can use names of members of its class
>> directly."
>
>OK. But what exactly is "the definition of a member function". Does that
>include the formal parameter list??
ARM 8.3:
"Function definitions have the form
function-defition:
decl_specifiers{opt} declarator ctor-initializer{opt} fct-body"
(where {opt} indicates an optional part of the grammar).
This clearly indicates that the formal parameter list is part of a
function definition. A member function definition is just a function
definition for a member function, so the same holds for member functions
definitions.
--
Fergus Henderson fjh@munta.cs.mu.OZ.AU
Author: rfg@netcom.com (Ronald F. Guilmette)
Date: Fri, 19 Nov 1993 09:55:07 GMT Raw View
In article <753447263snz@iplbath.demon.co.uk> Ipl@iplbath.demon.co.uk writes:
>A small question regarding scoping rules:
>
>Consider the following code:
>
> struct A
> {
> typedef int TypeName;
> typedef int Except1;
> typedef int Except2;
>
> void foo() throw (Except1);
> void goo(TypeName) throw (Except1, Except2);
> };
>
> void A::foo() throw (A::Except1)
> {
> /* some code */
> }
>
> void A::goo(TypeName t) throw (Except1, Except2)
> {
> /* some code */
> }
>
>My question is: which of the function declarations is legal?
I think that's a good question.
>I would assume that both are legal (ie that, like the parameter
>list, the exception-specifier is in the scope of the class).
I assume that you are correct when you assert that parameter lists of member
functions are in the scope of the class (otherwise compilers would accept
the following short example... and most of the ones I have here don't)
but I'm just curious... where do it say that?? (I've looked in both 3.2
and 10.4 and haven't found this particular scope rule in either place.)
struct S
{
int foo;
void bar (int);
};
int foo;
void S::bar (int arg = foo) { }
--
-- Ronald F. Guilmette, Sunnyvale, California -------------------------------
------ domain address: rfg@netcom.com ---------------------------------------
------ uucp address: ...!uunet!netcom.com!rfg -------------------------------
Author: thomson@cppfs.torolab.ibm.com (Brian Thomson)
Date: 23 Nov 1993 15:36:47 GMT Raw View
In article <rfgCGqGvv.49E@netcom.com> rfg@netcom.com (Ronald F. Guilmette) writes:
>I assume that you are correct when you assert that parameter lists of member
>functions are in the scope of the class (otherwise compilers would accept
>the following short example... and most of the ones I have here don't)
>but I'm just curious... where do it say that?? (I've looked in both 3.2
>and 10.4 and haven't found this particular scope rule in either place.)
I think you might combine 10.4 with 9.3, which says
"The definition of a member function is considered to be within the
scope of its class [... and ...] can use names of members of its class
directly."
plus
"If the definition of a member function is lexically outside the class
definition, the member function name must be qualified by the class
name using the :: operator."
which implies, but does not state, that this is the only change that must
be made. Unfortunately, this is just about impossible to achieve if the
return type specifier contains an unqualified name, eg. the "Y X::y"
in the following:
class X {
public:
class Y {};
Y y(Y&) throw(Y);
};
Y X::y(Y& yref) throw(Y) { return yref; }
IBM compilers require that class members appearing before the member function
name must also be class qualified, and will compile this example if the
last line is changed to:
X::Y X::y(Y& yref) throw(Y) { return yref; }
--
Brian Thomson THOMSON at TOROLAB
OS/2 C++ Development thomson@vnet.ibm.com
Author: ipl@iplbath.demon.co.uk (IPL)
Date: Tue, 16 Nov 1993 10:54:23 +0000 Raw View
A small question regarding scoping rules:
Consider the following code:
struct A
{
typedef int TypeName;
typedef int Except1;
typedef int Except2;
void foo() throw (Except1);
void goo(TypeName) throw (Except1, Except2);
};
void A::foo() throw (A::Except1)
{
/* some code */
}
void A::goo(TypeName t) throw (Except1, Except2)
{
/* some code */
}
My question is: which of the function declarations is legal?
I would assume that both are legal (ie that, like the parameter
list, the exception-specifier is in the scope of the class).
I have looked in the ARM, but can't find anything relevant. Paragraph
references to the ARM would be appreciated.
Misha Dorman
--
IPL Information Processing Ltd
Eveleigh House Tel: +44 225 444888
Grove Street Fax: +44 225 444400
Bath BA1 5LR
United Kingdom E-mail: ipl@iplbath.demon.co.uk