visibility, declarative region, scope, validity, introduction and accessibility

S

Steven T. Hatton

All of the following terms are used in some way to describe where and how a
name is relevant to a particular location in a program: visible,
declarative region, scope, potential scope, valid, introduced, used,
potentially evaluated and accessible. They all seem to have subtle
difference in meanings.

Any positive contribution to the following will be appreciated.

Here is my attempt to make sense of these:

*)declarative region
The declarative region of a name is largest "containment" construct (block,
namespace or class) in which the name is valid. A declarative region which
is not global[1] is delimited by '{' and '}'. There may be more than one
such delimited construct composing a declarative region.

*)valid
Valid seems to mean "in scope", but I'm not sure if that is sufficient or
correct.

*)potential scope
The part of a program beginning immediately after the first point of
declaration of a name, and extending to the end of the name's declarative
region.

*)scope
The portion of the potential scope excluding any potential scope determined
by declaring the same name in an enclosed declarative region. [2]

*)introduced
A name is introduced into a declarative region by a declaration which makes
it valid[3] within that declarative region.

*)accessible
It's got to do with public, protected, private and friend, but I don't know
how best to put it into words.

*)visible
A name is visible if it is in scope and not hidden. A name may be visible,
and not accessible. I'm not sure of the consequences of that, however.

*)potentially evaluated
"An expression is potentially evaluated unless
**)it appears where an integral constant expression is required (see 5.19),
**)is the operand of the sizeof operator (5.3.3),
**)or is the operand of the typeid operator and the expression does not
designate an lvalue of polymorphic class type (5.2.8)."


*)used
"An expression is potentially evaluated unless it appears where an integral
constant expression is required (see 5.19), is the operand of the sizeof
operator (5.3.3), or is the operand of the typeid operator and the
expression does not designate an lvalue of polymorphic class type (5.2.8)."

[1]Is a translation unit a declarative region?

[2]The Standard says: "The scope of a declaration is the same as its
potential scope unless the potential scope contains another declaration of
the same name." I believe there is a subtle error in that statement. To
wit, a name may be redeclared in the same declarative region in which it
was originally declared, and the scope would not be affected.

[3]The definition is circular.
 
S

Steven T. Hatton

Steven said:
All of the following terms are used in some way to describe where and how
a name is relevant to a particular location in a program: visible,
declarative region, scope, potential scope, valid, introduced, used,
potentially evaluated and accessible. They all seem to have subtle
difference in meanings.

Any positive contribution to the following will be appreciated.

Here is my attempt to make sense of these:

*)declarative region
The declarative region of a name is largest "containment" construct
(block,
namespace or class) in which the name is valid. A declarative region
which
is not global[1] is delimited by '{' and '}'. There may be more than one
such delimited construct composing a declarative region.

*)valid
Valid seems to mean "in scope", but I'm not sure if that is sufficient or
correct.

*)potential scope
The part of a program beginning immediately after the first point of
declaration of a name, and extending to the end of the name's declarative
region.

*)scope
The portion of the potential scope excluding any potential scope
determined by declaring the same name in an enclosed declarative region.
[2]

*)introduced
A name is introduced into a declarative region by a declaration which
makes it valid[3] within that declarative region.

*)accessible
It's got to do with public, protected, private and friend, but I don't
know how best to put it into words.

*)visible
A name is visible if it is in scope and not hidden. A name may be
visible,
and not accessible. I'm not sure of the consequences of that, however.

*)potentially evaluated
"An expression is potentially evaluated unless
**)it appears where an integral constant expression is required (see
5.19), **)is the operand of the sizeof operator (5.3.3),
**)or is the operand of the typeid operator and the expression does not
designate an lvalue of polymorphic class type (5.2.8)."


*)used
"An expression is potentially evaluated unless it appears where an
integral constant expression is required (see 5.19), is the operand of the
sizeof operator (5.3.3), or is the operand of the typeid operator and the
expression does not designate an lvalue of polymorphic class type
(5.2.8)."

[1]Is a translation unit a declarative region?

The following excerpt from the first example in §3.3.5 indicates to me that
the bounds of a translation unit do not delimit declarative regions. The
unnamed namespace is introduced in order to establish that delimitation.

namespace N {
int i;
int g(int a) { return a; }
int j();
void q();
}
namespace { int l=1; }
// the potential scope of l is from its point of declaration
// to the end of the translation unit

[2]The Standard says: "The scope of a declaration is the same as its
potential scope unless the potential scope contains another declaration of
the same name." I believe there is a subtle error in that statement. To
wit, a name may be redeclared in the same declarative region in which it
was originally declared, and the scope would not be affected.

[3]The definition is circular.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top