<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 642</TITLE>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
  INS { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  .INS { text-decoration:none; background-color:#D0FFD0 }
  DEL { text-decoration:line-through; background-color:#FFA0A0 }
  .DEL { text-decoration:line-through; background-color: #FFD0D0 }
  @media (prefers-color-scheme: dark) {
    HTML { background-color:#202020; color:#f0f0f0; }
    A { color:#5bc0ff; }
    A:visited { color:#c6a8ff; }
    A:hover, a:focus { color:#afd7ff; }
    INS { background-color:#033a16; color:#aff5b4; }
    .INS { background-color: #033a16; }
    DEL { background-color:#67060c; color:#ffdcd7; }
    .DEL { background-color:#67060c; }
  }
  SPAN.cmnt { font-family:Times; font-style:italic }
</STYLE>
</HEAD>
<BODY>
<P><EM>This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21
  Core Issues List revision 118b.
  See http://www.open-std.org/jtc1/sc22/wg21/ for the official
  list.</EM></P>
<P>2025-09-28</P>
<HR>
<A NAME="642"></A><H4>642.
  
Definition and use of &#8220;block scope&#8221; and &#8220;local scope&#8221;
</H4>
<B>Section: </B>6.4.3&#160; [<A href="https://wg21.link/basic.scope.block">basic.scope.block</A>]
 &#160;&#160;&#160;

 <B>Status: </B>CD2
 &#160;&#160;&#160;

 <B>Submitter: </B>Alisdair Meredith
 &#160;&#160;&#160;

 <B>Date: </B>6 Aug 2007<BR>


<P>[Voted into WP at March, 2010 meeting.]</P>

<P>The Standard uses the terms &#8220;block scope&#8221; and &#8220;local
scope&#8221; interchangeably, but the former is never formally
defined.  Would it be better to use only one term consistently?
&#8220;Block scope&#8221; seems to be more frequently used.</P>

<P><B>Notes from the October, 2007 meeting:</B></P>

<P>The CWG expressed a preference for the term &#8220;local
scope.&#8221;</P>

<P><B>Notes from the September, 2008 meeting:</B></P>

<P>Reevaluating the relative prevalence of the two terms
(including the fact that new uses of &#8220;block scope&#8221;
are being introduced, e.g., in both the lambda and thread-local
wording) led to CWG reversing its previous preference for
&#8220;local scope.&#8221;  The resolution will need to add a
definition of &#8220;block scope&#8221; and should change the
title of 6.4.3 [<A href="https://wg21.link/basic.scope.block">basic.scope.block</A>].</P>

<P><B>Proposed resolution (October, 2009):</B></P>

<OL>
<LI><P>Change 6.4.2 [<A href="https://wg21.link/basic.scope.pdecl#2">basic.scope.pdecl</A>] paragraph 2 as follows:</P></LI>

<BLOCKQUOTE>

<P>[<I>Note:</I> a <DEL>nonlocal</DEL> name <INS>from an outer
scope</INS> remains visible up to the point of declaration of the
<DEL>local</DEL> name that hides it. [<I>Example:</I>
</P>

<PRE>
  const int i = 2;
  { int i[i]; }
</PRE>

<P>declares a <DEL>local</DEL> <INS>block-scope</INS> array of two
integers. &#8212;<I>end example</I>] &#8212;<I>end note</I>]</P>

</BLOCKQUOTE>

<LI><P>Change the section heading of 6.4.3 [<A href="https://wg21.link/basic.scope.block">basic.scope.block</A>] from
&#8220;Local scope&#8221; to &#8220;Block scope.&#8221;</P></LI>

<LI><P>Change 6.4.3 [<A href="https://wg21.link/basic.scope.block#1">basic.scope.block</A>] paragraph 1 as follows:</P></LI>

<BLOCKQUOTE>

A name declared in a block (8.4 [<A href="https://wg21.link/stmt.block">stmt.block</A>]) is local to that
block<INS>; it has <I>block scope</I></INS>.  Its potential scope
begins at its point of declaration (6.4.2 [<A href="https://wg21.link/basic.scope.pdecl">basic.scope.pdecl</A>]) and
ends at the end of its <DEL>declarative region</DEL> <INS>block. A
variable declared at block scope is a <I>local variable</I></INS>.

</BLOCKQUOTE>

<LI><P>Change 6.4.3 [<A href="https://wg21.link/basic.scope.block#3">basic.scope.block</A>] paragraph 3 as follows:</P></LI>

<BLOCKQUOTE>

The name <DEL>in a <TT>catch</TT> exception-declaration</DEL>
<INS>declared in an <I>exception-declaration</I></INS> is local to the
<DEL>handler</DEL> <INS><I>handler</I></INS> and shall not be
redeclared in the outermost block of the <DEL>handler</DEL>
<INS><I>handler</I></INS>.

</BLOCKQUOTE>

<LI><P>Change _N4868_.6.4.10 [<A href="https://wg21.link/basic.scope.hiding#3">basic.scope.hiding</A>] paragraph 3 as follows:</P></LI>

<BLOCKQUOTE>

In a member function definition, the declaration of a <DEL>local</DEL>
name <INS>at block scope</INS> hides the declaration of a member of
the class with the same name...

</BLOCKQUOTE>

<LI><P>Change 6.7 [<A href="https://wg21.link/basic.link#8">basic.link</A>] paragraph 8 as follows:</P></LI>

<BLOCKQUOTE>

...Moreover, except as noted, a name declared <DEL>in a local</DEL>
<INS>at block</INS> scope (6.4.3 [<A href="https://wg21.link/basic.scope.block">basic.scope.block</A>]) has no
linkage...

</BLOCKQUOTE>

<LI><P>Change 6.10.3.3 [<A href="https://wg21.link/basic.start.dynamic#1">basic.start.dynamic</A>] paragraph 1 as follows:</P></LI>

<BLOCKQUOTE>

...For an object of array or class type, all subobjects of that object
are destroyed before any <DEL>local</DEL> <INS>block-scope</INS>
object with static storage duration initialized during the
construction of the subobjects is destroyed.

</BLOCKQUOTE>

<LI><P>Change 6.10.3.3 [<A href="https://wg21.link/basic.start.dynamic#2">basic.start.dynamic</A>] paragraph 2 as follows:</P></LI>

<BLOCKQUOTE>

If a function contains a <DEL>local</DEL> <INS>block-scope</INS>
object of static or thread storage duration that has been destroyed
and the function is called during the destruction of an object with
static or thread storage duration, the program has undefined behavior
if the flow of control passes through the definition of the previously
destroyed <DEL>local</DEL> <INS>block-scope</INS> object.  Likewise,
the behavior is undefined if the <DEL>function-local</DEL>
<INS>block-scope</INS> object is used indirectly (i.e., through a
pointer) after its destruction.

</BLOCKQUOTE>

<LI><P>Change 6.10.3.3 [<A href="https://wg21.link/basic.start.dynamic#3">basic.start.dynamic</A>] paragraph 3 as follows:</P></LI>

<BLOCKQUOTE>

If the completion of the initialization of a <DEL>non-local</DEL>
<INS>non-block-scope</INS> object with static storage duration is
sequenced before a call to <TT>std::atexit</TT> (see
<TT>&lt;cstdlib&gt;</TT>, 17.5 [<A href="https://wg21.link/support.start.term">support.start.term</A>]), the call to the
function passed to <TT>std::atexit</TT> is sequenced before the call
to the destructor for the object. If a call to <TT>std::atexit</TT> is
sequenced before the completion of the initialization of a
<DEL>non-local</DEL> <INS>non-block-scope</INS> object with static
storage duration, the call to the destructor...

</BLOCKQUOTE>

<P><I>[Editorial note: the occurrences of &#8220;non-local&#8221;
in this change are removed by the proposed resolution for
<A HREF="946.html">issue 946</A>.]</I></P>

<LI><P>Change 8.4 [<A href="https://wg21.link/stmt.block#1">stmt.block</A>] paragraph 1 as follows:</P></LI>

<BLOCKQUOTE>

...A compound statement defines a <DEL>local</DEL> <INS>block</INS>
scope (6.4 [<A href="https://wg21.link/basic.scope">basic.scope</A>])...

</BLOCKQUOTE>

<LI><P>Change 8.5 [<A href="https://wg21.link/stmt.select#1">stmt.select</A>] paragraph 1 as follows:</P></LI>

<BLOCKQUOTE>

...The substatement in a <I>selection-statement</I> (each
substatement, in the <TT>else</TT> form of the <TT>if</TT> statement)
implicitly defines a <DEL>local</DEL> <INS>block</INS> scope
(6.4 [<A href="https://wg21.link/basic.scope">basic.scope</A>])...

</BLOCKQUOTE>

<LI><P>Change 8.5 [<A href="https://wg21.link/stmt.select#5">stmt.select</A>] paragraph 5 as follows:</P></LI>

<BLOCKQUOTE>

If a condition can be syntactically resolved as either an expression
or the declaration of a <DEL>local</DEL> <INS>block-scope</INS> name,
it is interpreted as a declaration.

</BLOCKQUOTE>

<LI><P>Change 8.6 [<A href="https://wg21.link/stmt.iter#2">stmt.iter</A>] paragraph 2 as follows:</P></LI>

<BLOCKQUOTE>

The substatement in an <I>iteration-statement</I> implicitly defines a
<DEL>local</DEL> <INS>block</INS> scope (6.4 [<A href="https://wg21.link/basic.scope">basic.scope</A>])
which is entered and exited each time through the loop.

</BLOCKQUOTE>

<LI><P>Change 8.10 [<A href="https://wg21.link/stmt.dcl#3">stmt.dcl</A>] paragraph 3 as follows:</P></LI>

<BLOCKQUOTE>

...A program that jumps<SUP>84</SUP> from a point where a
<DEL>local</DEL> variable with automatic storage duration...

</BLOCKQUOTE>

<LI><P>Change 8.10 [<A href="https://wg21.link/stmt.dcl#4">stmt.dcl</A>] paragraph 4 as follows:</P></LI>

<BLOCKQUOTE>

The zero-initialization (9.5 [<A href="https://wg21.link/dcl.init">dcl.init</A>]) of all
<DEL>local</DEL> <INS>block-scope</INS> objects with static storage
duration (6.8.6.2 [<A href="https://wg21.link/basic.stc.static">basic.stc.static</A>]) or thread storage duration
(6.8.6.3 [<A href="https://wg21.link/basic.stc.thread">basic.stc.thread</A>]) is performed before any other
initialization takes place. Constant initialization (6.10.3.2 [<A href="https://wg21.link/basic.start.static">basic.start.static</A>]) of a <DEL>local</DEL> <INS>block-scope</INS> entity
with static storage duration, if applicable, is performed before its
block is first entered. An implementation is permitted to perform
early initialization of other <DEL>local</DEL> <INS>block-scope</INS>
objects...

</BLOCKQUOTE>

<LI><P>Change 8.10 [<A href="https://wg21.link/stmt.dcl#5">stmt.dcl</A>] paragraph 5 as follows:</P></LI>

<BLOCKQUOTE>

The destructor for a <DEL>local</DEL> <INS>block-scope</INS> object
with static or thread storage duration will be executed if and only if
the variable was constructed.  [<I>Note:</I> 6.10.3.3 [<A href="https://wg21.link/basic.start.dynamic">basic.start.dynamic</A>] describes the order in which <DEL>local</DEL>
<INS>block-scope</INS> objects with static and thread storage duration
are destroyed.  &#8212;<I>end note</I>]

</BLOCKQUOTE>

<LI><P>Change 9.6 [<A href="https://wg21.link/dcl.fct.def#7">dcl.fct.def</A>] paragraph 7 as follows:</P></LI>

<BLOCKQUOTE>

In the <I>function-body</I>, a <I>function-local predefined
variable</I> denotes a <DEL>local</DEL> <INS>block-scope</INS> object
of static storage duration that is implicitly defined (see
6.4.3 [<A href="https://wg21.link/basic.scope.block">basic.scope.block</A>]).

</BLOCKQUOTE>

<LI><P>Change the example in 11.3 [<A href="https://wg21.link/class.name#2">class.name</A>] paragraph 2 as
follows:</P></LI>

<PRE>
  ...
  void g() {
    struct s;      //<SPAN CLASS="cmnt"> hide global </SPAN>struct s
                   //<SPAN CLASS="cmnt"> with a <DEL>local</DEL> <INS>block-scope</INS> declaration</SPAN>
  ...
</PRE>

<LI><P>Change the example in 11.3 [<A href="https://wg21.link/class.name#3">class.name</A>] paragraph 3 as
follows:</P></LI>

<PRE>
  ...
  void g(int s) {
    struct s* p = new struct s;   //<SPAN CLASS="cmnt"> global </SPAN>s
    p-&gt;a = s;                     //<SPAN CLASS="cmnt"> <DEL>local</DEL> <INS>parameter</INS> </SPAN>s
  }
</PRE>

</OL>

<BR><BR>
</BODY>
</HTML>
