|
126 | 126 | \pnum
|
127 | 127 | \indextext{declaration}%
|
128 | 128 | \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 |
134 | 131 | \ref{dcl.dcl} about components in, of, or contained by a
|
135 | 132 | declaration or subcomponent thereof refer only to those components of
|
136 | 133 | the declaration that are \emph{not} nested within scopes nested within
|
|
141 | 138 | \indextext{declarator}%
|
142 | 139 | In a \grammarterm{simple-declaration}, the optional
|
143 | 140 | \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, |
145 | 142 | when the \grammarterm{decl-specifier-seq} contains either a
|
146 | 143 | \grammarterm{class-specifier}, an \grammarterm{elaborated-type-specifier} with
|
147 | 144 | a \grammarterm{class-key}\iref{class.name}, or an
|
148 | 145 | \grammarterm{enum-specifier}. In these cases and whenever a
|
149 | 146 | \grammarterm{class-specifier} or \grammarterm{enum-specifier} is present in
|
150 | 147 | 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 |
152 | 149 | \grammarterm{class-name}{s}, \grammarterm{enum-name}{s}, or
|
153 | 150 | \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. |
157 | 153 | \begin{example}
|
158 | 154 | \begin{codeblock}
|
159 | 155 | enum { }; // error
|
|
201 | 197 | \grammarterm{assignment-expression} is of array or non-union class type.
|
202 | 198 |
|
203 | 199 | \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}. |
213 | 214 |
|
214 | 215 | \pnum
|
215 | 216 | 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 |
219 | 220 | associated type\iref{dcl.typedef}. If the
|
220 | 221 | \grammarterm{decl-specifier-seq} contains no \tcode{typedef} specifier, the
|
221 | 222 | 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 |
223 | 224 | an \defnx{object declaration}{declaration!object} otherwise.
|
224 | 225 |
|
225 | 226 | \pnum
|
|
354 | 355 | \tcode{typedef} specifier in the same \grammarterm{decl-specifier-seq} and
|
355 | 356 | the \grammarterm{init-declarator-list} or \grammarterm{member-declarator-list}
|
356 | 357 | 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 |
361 | 359 | \grammarterm{storage-class-specifier} applies to the name declared by each
|
362 | 360 | \grammarterm{init-declarator} in the list and not to any names declared by
|
363 | 361 | other specifiers.
|
|
421 | 419 | \end{note}
|
422 | 420 |
|
423 | 421 | \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} |
428 | 427 | \begin{example}
|
429 | 428 | \begin{codeblock}
|
430 | 429 | static char* f(); // \tcode{f()} has internal linkage
|
|
599 | 598 | \pnum
|
600 | 599 | A \grammarterm{typedef-name} can also be introduced by an
|
601 | 600 | \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} |
603 | 602 | and the optional \grammarterm{attribute-specifier-seq} following the
|
604 | 603 | \grammarterm{identifier} appertains to that \grammarterm{typedef-name}.
|
605 | 604 | Such a \grammarterm{typedef-name} has the same
|
|
618 | 617 | a class or enumeration if the \grammarterm{alias-declaration}
|
619 | 618 | is the \grammarterm{declaration} of a \grammarterm{template-declaration}.
|
620 | 619 |
|
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 |
| - |
690 | 620 | \pnum
|
691 | 621 | \indextext{class name!\idxcode{typedef}}%
|
692 | 622 | A \grammarterm{simple-template-id} is only a \grammarterm{typedef-name}
|
|
1097 | 1027 | \begin{note}
|
1098 | 1028 | An inline function or variable
|
1099 | 1029 | 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. |
1107 | 1035 | \end{note}
|
1108 | 1036 |
|
1109 | 1037 | \pnum
|
|
0 commit comments