Skip to content

Commit e40ae3f

Browse files
committed
dcl.dcl first part
1 parent 09cc371 commit e40ae3f

File tree

1 file changed

+36
-108
lines changed

1 file changed

+36
-108
lines changed

source/declarations.tex

Lines changed: 36 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,8 @@
126126
\pnum
127127
\indextext{declaration}%
128128
\indextext{scope}%
129-
A declaration occurs in a scope\iref{basic.scope}; the scope rules are
130-
summarized in~\ref{basic.lookup}. A declaration that declares a function
131-
or defines a class, namespace, template, or function also has one or
132-
more scopes nested within it. These nested scopes, in turn, can have
133-
declarations nested within them. Unless otherwise stated, utterances in
129+
Certain declarations contain one or more scopes\iref{basic.scope.scope}.
130+
Unless otherwise stated, utterances in
134131
\ref{dcl.dcl} about components in, of, or contained by a
135132
declaration or subcomponent thereof refer only to those components of
136133
the declaration that are \emph{not} nested within scopes nested within
@@ -141,19 +138,18 @@
141138
\indextext{declarator}%
142139
In a \grammarterm{simple-declaration}, the optional
143140
\grammarterm{init-declarator-list} can be omitted only when declaring a
144-
class\iref{class} or enumeration\iref{dcl.enum}, that is,
141+
class\iref{class.pre} or enumeration\iref{dcl.enum}, that is,
145142
when the \grammarterm{decl-specifier-seq} contains either a
146143
\grammarterm{class-specifier}, an \grammarterm{elaborated-type-specifier} with
147144
a \grammarterm{class-key}\iref{class.name}, or an
148145
\grammarterm{enum-specifier}. In these cases and whenever a
149146
\grammarterm{class-specifier} or \grammarterm{enum-specifier} is present in
150147
the \grammarterm{decl-specifier-seq}, the identifiers in these specifiers
151-
are among the names being declared by the declaration (as
148+
are also declared (as
152149
\grammarterm{class-name}{s}, \grammarterm{enum-name}{s}, or
153150
\grammarterm{enumerator}{s}, depending on the syntax). In such cases,
154-
the \grammarterm{decl-specifier-seq} shall introduce one or more names into
155-
the program, or shall redeclare a name introduced by a previous
156-
declaration.
151+
the \grammarterm{decl-specifier-seq} shall (re)introduce one or more names into
152+
the program.
157153
\begin{example}
158154
\begin{codeblock}
159155
enum { }; // error
@@ -201,25 +197,30 @@
201197
\grammarterm{assignment-expression} is of array or non-union class type.
202198

203199
\pnum
204-
Each \grammarterm{init-declarator} in the \grammarterm{init-declarator-list}
205-
contains exactly one \grammarterm{declarator-id}, which is the name
206-
declared by that \grammarterm{init-declarator} and hence one of the names
207-
declared by the declaration. The
208-
\grammarterm{defining-type-specifier}{s}\iref{dcl.type} in the
209-
\grammarterm{decl-specifier-seq} and the recursive \grammarterm{declarator}
210-
structure of the \grammarterm{init-declarator} describe a
211-
type\iref{dcl.meaning}, which is then associated with the name being
212-
declared by the \grammarterm{init-declarator}.
200+
If a \grammarterm{declarator-id} is a name, the
201+
\grammarterm{init-declarator} and (hence) the declaration introduce that name.
202+
\begin{note}
203+
Otherwise, the \grammarterm{declarator-id} is
204+
a \grammarterm{qualified-id} or
205+
names a destructor or
206+
its \grammarterm{unqualified-id} is a \grammarterm{template-id} and
207+
no name is introduced.
208+
\end{note}
209+
The \grammarterm{defining-type-specifier}{s}\iref{dcl.type} in
210+
the \grammarterm{decl-specifier-seq} and
211+
the recursive \grammarterm{declarator} structure
212+
describe a type\iref{dcl.meaning},
213+
which is then associated with the \grammarterm{declarator-id}.
213214

214215
\pnum
215216
If the \grammarterm{decl-specifier-seq} contains the \tcode{typedef}
216-
specifier, the declaration is called a \defnx{typedef declaration}{declaration!typedef} and the name
217-
of each \grammarterm{init-declarator}
218-
is declared to be a \grammarterm{typedef-name}, synonymous with its
217+
specifier, the declaration is called a \defnx{typedef declaration}{declaration!typedef},
218+
each \grammarterm{declarator-id} shall be an \grammarterm{identifier}
219+
and is declared to be a \grammarterm{typedef-name}, synonymous with its
219220
associated type\iref{dcl.typedef}. If the
220221
\grammarterm{decl-specifier-seq} contains no \tcode{typedef} specifier, the
221222
declaration is called a \defnx{function declaration}{declaration!function} if
222-
the type associated with the name is a function type\iref{dcl.fct} and
223+
the type associated with a \grammarterm{declarator-id} is a function type\iref{dcl.fct} and
223224
an \defnx{object declaration}{declaration!object} otherwise.
224225

225226
\pnum
@@ -354,10 +355,7 @@
354355
\tcode{typedef} specifier in the same \grammarterm{decl-specifier-seq} and
355356
the \grammarterm{init-declarator-list} or \grammarterm{member-declarator-list}
356357
of the declaration shall not be
357-
empty (except for an anonymous union declared in a named namespace or in the
358-
global namespace, which shall be declared
359-
\indextext{specifier!\idxcode{static}}%
360-
\tcode{static}\iref{class.union.anon}). The
358+
empty (except for an anonymous union declared in a namespace scope\iref{class.union.anon}). The
361359
\grammarterm{storage-class-specifier} applies to the name declared by each
362360
\grammarterm{init-declarator} in the list and not to any names declared by
363361
other specifiers.
@@ -421,10 +419,11 @@
421419
\end{note}
422420

423421
\pnum
424-
The linkages implied by successive declarations for a given entity shall
425-
agree. That is, within a given scope, each declaration declaring the
426-
same variable name or the same overloading of a function name shall imply
427-
the same linkage.
422+
All declarations for a given entity shall give its name the same linkage.
423+
\begin{note}
424+
The linkage given by some declarations is affected by previous declarations.
425+
Overloads are distinct entities.
426+
\end{note}
428427
\begin{example}
429428
\begin{codeblock}
430429
static char* f(); // \tcode{f()} has internal linkage
@@ -599,7 +598,7 @@
599598
\pnum
600599
A \grammarterm{typedef-name} can also be introduced by an
601600
\grammarterm{alias-declaration}. The \grammarterm{identifier} following the
602-
\tcode{using} keyword becomes a \grammarterm{typedef-name}
601+
\tcode{using} keyword is not looked up; it becomes a \grammarterm{typedef-name}
603602
and the optional \grammarterm{attribute-specifier-seq} following the
604603
\grammarterm{identifier} appertains to that \grammarterm{typedef-name}.
605604
Such a \grammarterm{typedef-name} has the same
@@ -618,75 +617,6 @@
618617
a class or enumeration if the \grammarterm{alias-declaration}
619618
is the \grammarterm{declaration} of a \grammarterm{template-declaration}.
620619

621-
\pnum
622-
\indextext{redefinition!\idxcode{typedef}}%
623-
In a given non-class scope, a \tcode{typedef} specifier can be used to
624-
redeclare the name of any type declared in that scope to refer to the
625-
type to which it already refers.
626-
\begin{example}
627-
\begin{codeblock}
628-
typedef struct s { @\commentellip@ } s;
629-
typedef int I;
630-
typedef int I;
631-
typedef I I;
632-
\end{codeblock}
633-
\end{example}
634-
635-
\pnum
636-
In a given class scope, a \tcode{typedef} specifier can be used to
637-
redeclare any \grammarterm{class-name} declared in that scope that is not
638-
also a \grammarterm{typedef-name} to refer to the type to which it already
639-
refers.
640-
\begin{example}
641-
\begin{codeblock}
642-
struct S {
643-
typedef struct A { } A; // OK
644-
typedef struct B B; // OK
645-
typedef A A; // error
646-
};
647-
\end{codeblock}
648-
\end{example}
649-
650-
\pnum
651-
If a \tcode{typedef} specifier is used to redeclare in a given scope an
652-
entity that can be referenced using an \grammarterm{elaborated-type-specifier},
653-
the entity can continue to be referenced by an
654-
\grammarterm{elaborated-type-specifier} or as an enumeration or class name
655-
in an enumeration or class definition respectively.
656-
\begin{example}
657-
\begin{codeblock}
658-
struct S;
659-
typedef struct S S;
660-
int main() {
661-
struct S* p; // OK
662-
}
663-
struct S { }; // OK
664-
\end{codeblock}
665-
\end{example}
666-
667-
\pnum
668-
In a given scope, a \tcode{typedef} specifier shall not be used to
669-
redeclare the name of any type declared in that scope to refer to a
670-
different type.
671-
\begin{example}
672-
\begin{codeblock}
673-
class complex { @\commentellip@ };
674-
typedef int complex; // error: redefinition
675-
\end{codeblock}
676-
\end{example}
677-
678-
\pnum
679-
Similarly, in a given scope, a class or enumeration shall not be
680-
declared with the same name as a \grammarterm{typedef-name} that is
681-
declared in that scope and refers to a type other than the class or
682-
enumeration itself.
683-
\begin{example}
684-
\begin{codeblock}
685-
typedef int complex;
686-
class complex { @\commentellip@ }; // error: redefinition
687-
\end{codeblock}
688-
\end{example}
689-
690620
\pnum
691621
\indextext{class name!\idxcode{typedef}}%
692622
A \grammarterm{simple-template-id} is only a \grammarterm{typedef-name}
@@ -1097,13 +1027,11 @@
10971027
\begin{note}
10981028
An inline function or variable
10991029
with external or module linkage
1100-
has the same address in all translation units.
1101-
A \tcode{static} local variable in an inline
1102-
function with external or module linkage
1103-
always refers to the same object.
1104-
A type defined within the body of an inline
1105-
function with external or module linkage is the
1106-
same type in every translation unit.
1030+
can be defined in multiple translation units\iref{basic.def.odr},
1031+
but is one entity with one address.
1032+
A type or \tcode{static} variable
1033+
defined in the body of such a function
1034+
is therefore a single entity.
11071035
\end{note}
11081036

11091037
\pnum

0 commit comments

Comments
 (0)