[stmt.dcl]

# 8 Statements [[stmt]](./#stmt)

## 8.10 Declaration statement [stmt.dcl]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/statements.tex#L1262)

A declaration statement introduces one or more new names into a
block; it has the form

[declaration-statement:](#nt:declaration-statement "8.10 Declaration statement [stmt.dcl]")  
[*block-declaration*](dcl.pre#nt:block-declaration "9.1 Preamble [dcl.pre]")

[*Note [1](#note-1)*:

If an identifier introduced by a declaration was previously declared in
an outer block,the outer declaration is hidden
for the remainder of the block ([[basic.lookup.unqual]](basic.lookup.unqual "6.5.3 Unqualified name lookup")),
after which it resumes its force[.](#1.sentence-1)

â *end note*]

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/statements.tex#L1280)

A block variable with automatic storage duration ([[basic.stc.auto]](basic.stc.auto "6.8.6.4 Automatic storage duration"))
is [*active*](#def:variable,active "8.10 Declaration statement [stmt.dcl]") everywhere in the scope to which it belongs
after its [*init-declarator*](dcl.decl.general#nt:init-declarator "9.3.1 General [dcl.decl.general]")[.](#2.sentence-1)

Upon each transfer of control (including sequential execution of statements)
within a function from point P to point Q,
all block variables with automatic storage duration
that are active at P and not at Q are destroyed in the reverse order of their construction[.](#2.sentence-2)

Then, all block variables with automatic storage duration
that are active at Q but not at P are initialized in declaration order;
unless all such variables have vacuous initialization ([[basic.life]](basic.life "6.8.4 Lifetime")),
the transfer of control shall not be a jump[.](#2.sentence-3)[73](#footnote-73 "The transfer from the condition of a switch statement to a case label is considered a jump in this respect.")

When a [*declaration-statement*](#nt:declaration-statement "8.10 Declaration statement [stmt.dcl]") is executed,P and Q are the points immediately before and after it;
when a function returns, Q is after its body[.](#2.sentence-4)

[*Example [1](#example-1)*: void f() {// ...goto lx; // error: jump into scope of a// ... ly: X a = 1; // ... lx:goto ly; // OK, jump implies destructor call for a followed by// construction again immediately following label ly} â *end example*]

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/statements.tex#L1320)

Dynamic initialization of a block variable with[static storage duration](basic.stc.static "6.8.6.2 Static storage duration [basic.stc.static]") or[thread storage duration](basic.stc.thread "6.8.6.3 Thread storage duration [basic.stc.thread]") is performed
the first time control passes through its declaration; such a variable is
considered initialized upon the completion of its initialization[.](#3.sentence-1)

If the
initialization exits by throwing an exception, the initialization is not
complete, so it will be tried again the next time control enters the
declaration[.](#3.sentence-2)

If control enters the declaration concurrently while the variable is
being initialized, the concurrent execution shall wait for completion
of the initialization[.](#3.sentence-3)

[*Note [2](#note-2)*:

A conforming implementation cannot introduce
any deadlock around execution of the initializer[.](#3.sentence-4)

Deadlocks might still be caused by the program logic;
the implementation need only avoid deadlocks
due to its own synchronization operations[.](#3.sentence-5)

â *end note*]

If control
re-enters the declaration recursively while
the variable is being initialized, the behavior is undefined[.](#3.sentence-6)

[*Example [2](#example-2)*: int foo(int i) {static int s = foo(2*i); // undefined behavior: recursive callreturn i+1;} â *end example*]

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/statements.tex#L1355)

An object associated with
a block variable with static or thread storage duration
will be destroyed if and only if it was constructed[.](#4.sentence-1)

[*Note [3](#note-3)*:

[[basic.start.term]](basic.start.term "6.10.3.4 Termination") describes the order in which such objects are destroyed[.](#4.sentence-2)

â *end note*]

[73)](#footnote-73)[73)](#footnoteref-73)

The transfer from the condition of a switch statement to acase label is considered a jump in this respect[.](#footnote-73.sentence-1)
