|
120 | 120 | \nontermdef{noptr-declarator}\br |
121 | 121 | declarator-id attribute-specifier-seq\opt\br |
122 | 122 | noptr-declarator parameters-and-qualifiers\br |
123 | | - noptr-declarator \terminal{[} constant-expression\opt \terminal{]} attribute-specifier-seq\opt\br |
| 123 | + noptr-declarator \terminal{[} expression\opt \terminal{]} attribute-specifier-seq\opt\br |
124 | 124 | \terminal{(} ptr-declarator \terminal{)} |
125 | 125 | \end{bnf} |
126 | 126 |
|
|
599 | 599 | The |
600 | 600 | \grammarterm{cv-qualifier}{s} |
601 | 601 | apply to the pointer and not to the object pointed to. |
602 | | -Similarly, the optional \grammarterm{attribute-specifier-seq}~(\ref{dcl.attr.grammar}) appertains to the pointer and not to the object pointed to. |
| 602 | +Similarly, the optional |
| 603 | +\grammarterm{attribute-specifier-seq}~(\ref{dcl.attr.grammar}) appertains to |
| 604 | +the pointer and not to the object pointed to. There shall be no pointers to |
| 605 | +arrays of runtime bound. |
603 | 606 |
|
604 | 607 | \pnum |
605 | 608 | \enterexample |
|
821 | 824 |
|
822 | 825 | \pnum |
823 | 826 | \indextext{restriction!reference}% |
824 | | -There shall be no references to references, |
825 | | -no arrays of references, and no pointers to references. |
| 827 | +There shall be no references to references, no references to arrays of runtime |
| 828 | +bound, no arrays of references, and no pointers to references. |
826 | 829 | \indextext{initialization!reference}% |
827 | 830 | The declaration of a reference shall contain an |
828 | 831 | \grammarterm{initializer} |
|
993 | 996 | has the form |
994 | 997 |
|
995 | 998 | \begin{ncsimplebnf} |
996 | | -\terminal{D1 [} constant-expression\opt \terminal{]} attribute-specifier-seq\opt |
| 999 | +\terminal{D1 [} expression\opt \terminal{]} attribute-specifier-seq\opt |
997 | 1000 | \end{ncsimplebnf} |
998 | 1001 |
|
999 | 1002 | and the type of the identifier in the declaration |
|
1012 | 1015 | \term{element type}; |
1013 | 1016 | this type shall not be a reference type, the (possibly cv-qualified) type |
1014 | 1017 | \tcode{void}, |
1015 | | -a function type or an abstract class type. |
| 1018 | +a function type, an array of unknown or runtime bound, or an abstract class type. |
| 1019 | +Except as noted below, if the \grammarterm{expression} is omitted, the type of |
| 1020 | +the identifier of \tcode{D} is ``\grammarterm{derived-declarator-type-list} |
| 1021 | +array of unknown bound of \tcode{T}''. If the \grammarterm{expression} is |
| 1022 | +present, it is implicitly converted to \tcode{std::size_t}. The |
| 1023 | +\grammarterm{expression} is erroneous if: |
| 1024 | + |
| 1025 | +\begin{itemize} |
| 1026 | +\item |
| 1027 | +its value before converting to \tcode{std::size_t} or, in the case of an |
| 1028 | +expression of class type, before application of the second standard |
| 1029 | +conversion~(\ref{over.ics.user}) is less than or equal to zero; |
| 1030 | + |
| 1031 | +\item |
| 1032 | +its value is such that the size of the allocated object would exceed the |
| 1033 | +implementation-defined limit (Annex~\ref{implimits}); |
| 1034 | + |
| 1035 | +\item |
| 1036 | +the initializer of the object is a \grammarterm{braced-init-list} whose number |
| 1037 | +of (top-level) \grammarterm{initializer-clause}{s} exceeds the number of |
| 1038 | +elements to initialize; or |
| 1039 | + |
| 1040 | +\item |
| 1041 | +the object is initialized with a string literal and there are more initializers |
| 1042 | +than there are array elements. |
| 1043 | +\end{itemize} |
| 1044 | + |
| 1045 | +If the \grammarterm{expression}, after converting to \tcode{std::size_t}, is a |
| 1046 | +core constant expression and the \grammarterm{expression} is erroneous, the |
| 1047 | +program is ill-formed. |
| 1048 | + |
| 1049 | +If the \grammarterm{expression}, after converting to \tcode{std::size_t}, is a |
| 1050 | +core constant expression whose value is \tcode{N}, the type of the identifier |
| 1051 | +of \tcode{D} is ``\grammarterm{derived-declarator-type-list} array of |
| 1052 | +\tcode{N T}''. |
| 1053 | + |
| 1054 | +\indextext{array of runtime bound}% |
| 1055 | +\indextext{runtime bound!array of|see{array of runtime bound}}% |
| 1056 | +Otherwise, the type of the identifier of \tcode{D} is |
| 1057 | +``\grammarterm{derived-declarator-type-list} array of runtime bound of |
| 1058 | +\tcode{T}'' and the value of the \grammarterm{expression} designates the number |
| 1059 | +of elements \tcode{N} in the array. If the \grammarterm{expression} is |
| 1060 | +erroneous, an exception of a type that would match a |
| 1061 | +handler~(\ref{except.handle}) of type |
| 1062 | +\tcode{std::bad_array_length}~(\ref{bad.array.length}) is thrown. |
| 1063 | + |
1016 | 1064 | \indextext{declaration!array}% |
1017 | | -If the |
1018 | | -\grammarterm{constant-expression} |
1019 | | -(\ref{expr.const}) is present, it shall be a converted constant |
1020 | | -expression of type \tcode{std\colcol{}size_t} and |
1021 | | -its value shall be greater than zero. |
1022 | | -The constant expression specifies the |
1023 | | -\indextext{array!bound}% |
1024 | | -\indextext{bound,~of~array}% |
1025 | | -\term{bound} |
1026 | | -of (number of elements in) the array. |
1027 | | -If the value of the constant expression is |
1028 | | -\tcode{N}, |
1029 | | -the array has |
1030 | | -\tcode{N} |
1031 | | -elements numbered |
1032 | | -\tcode{0} |
1033 | | -to |
1034 | | -\tcode{N-1}, |
1035 | | -and the type of the identifier of |
1036 | | -\tcode{D} |
1037 | | -is ``\nonterminal{derived-declarator-type-list} array of |
1038 | | -\tcode{N} |
1039 | | -\tcode{T}''. |
1040 | 1065 | An object of array type contains a contiguously allocated non-empty set of |
1041 | 1066 | \tcode{N} |
1042 | 1067 | subobjects of type |
1043 | 1068 | \tcode{T}. |
1044 | | -Except as noted below, if |
1045 | | -the constant expression is omitted, the type of the identifier of |
1046 | | -\tcode{D} |
1047 | | -is ``\nonterminal{derived-declarator-type-list} array of unknown bound of |
1048 | | -\tcode{T}'', |
1049 | | -an incomplete object type. |
1050 | 1069 | The type ``\nonterminal{derived-declarator-type-list} array of |
1051 | 1070 | \tcode{N} |
1052 | 1071 | \tcode{T}'' |
|
1065 | 1084 | \tcode{T}'', |
1066 | 1085 | and similarly for |
1067 | 1086 | ``array of unknown bound of |
1068 | | -\tcode{T}''. |
| 1087 | +\tcode{T}'' and ``array of runtime bound of \tcode{T}''. |
1069 | 1088 | The optional \grammarterm{attribute-specifier-seq} appertains to the array. |
1070 | 1089 | \enterexample |
1071 | 1090 |
|
1072 | 1091 | \begin{codeblock} |
1073 | 1092 | typedef int A[5], AA[2][3]; |
1074 | | -typedef const A CA; // type is ``array of 5 const int'' |
1075 | | -typedef const AA CAA; // type is ``array of 2 array of 3 const int'' |
| 1093 | +typedef const A CA; // type is ``array of 5 \tcode{const int}'' |
| 1094 | +typedef const AA CAA; // type is ``array of 2 array of 3 \tcode{const int}'' |
| 1095 | + |
| 1096 | +void f(unsigned int n) { |
| 1097 | + int a[n]; // type of \tcode{a} is ``array of runtime bound of \tcode{int}'' |
| 1098 | +} |
| 1099 | + |
1076 | 1100 | \end{codeblock} |
1077 | 1101 | \exitexample |
1078 | 1102 | \enternote |
|
1095 | 1119 |
|
1096 | 1120 | \pnum |
1097 | 1121 | When several ``array of'' specifications are adjacent, a multidimensional |
1098 | | -array is created; |
1099 | | -only the first of |
1100 | | -the constant expressions that specify the bounds |
1101 | | -of the arrays may be omitted. |
| 1122 | +array is created. |
1102 | 1123 | In addition to declarations in which an incomplete object type is allowed, |
1103 | 1124 | an array bound may be omitted in some cases in the declaration of a function |
1104 | 1125 | parameter~(\ref{dcl.fct}). |
|
1122 | 1143 | be the same as in that earlier declaration, and similarly for the definition |
1123 | 1144 | of a static data member of a class. |
1124 | 1145 |
|
| 1146 | +\pnum |
| 1147 | +An array of runtime bound shall only be used as the type of a local object with |
| 1148 | +automatic storage duration. If the size of the array exceeds the size of the |
| 1149 | +memory available for objects with automatic storage duration, the behavior is |
| 1150 | +undefined.\footnote{Implementations that detect this case are encouraged to |
| 1151 | +throw an exception that would match a handler~(\ref{except.handle}) of type |
| 1152 | +\tcode{std::bad_array_length}~(\ref{bad.array.length}).} |
| 1153 | +It is unspecified whether a global allocation |
| 1154 | +function~(\ref{basic.stc.dynamic}) is invoked to obtain storage for the array. |
| 1155 | +If it is invoked, the corresponding global deallocation function is invoked to |
| 1156 | +release the storage after the lifetime of the array has |
| 1157 | +ended.\footnote{Alternatively, an implementation could allocate such an array |
| 1158 | +on the usual stack or obtain storage via \tcode{malloc}~(\ref{c.malloc}).} |
| 1159 | + |
1125 | 1160 | \pnum |
1126 | 1161 | \enterexample |
1127 | 1162 | \indextext{example!subscripting}% |
|
1536 | 1571 |
|
1537 | 1572 | \pnum |
1538 | 1573 | If the type of a parameter includes a type of the form |
1539 | | -``pointer to array of unknown bound of \tcode{T}'' or |
1540 | | -``reference to array of unknown bound of \tcode{T},'' |
| 1574 | +``array of runtime bound of \tcode{T}'', |
| 1575 | +``pointer to array of unknown bound of \tcode{T}'', or |
| 1576 | +``reference to array of unknown bound of \tcode{T}'', |
1541 | 1577 | the program is ill-formed.\footnote{This excludes parameters of type |
1542 | 1578 | ``\nonterminal{ptr-arr-seq} \tcode{T2}'' where \tcode{T2} is |
1543 | 1579 | ``pointer to array of unknown bound of \tcode{T}'' and where |
|
2871 | 2907 | \exitexample |
2872 | 2908 |
|
2873 | 2909 | \pnum |
2874 | | -An |
| 2910 | +For types other than arrays of runtime bound~(\ref{dcl.array}), an |
2875 | 2911 | \grammarterm{initializer-list} |
2876 | 2912 | is ill-formed if the number of |
2877 | 2913 | \grammarterm{initializer-clause}{s} |
|
3185 | 3221 | \exitexample |
3186 | 3222 |
|
3187 | 3223 | \pnum |
3188 | | -There shall not be more initializers than there are array elements. |
| 3224 | +\enternote There cannot be more initializers than there are array elements; |
| 3225 | +see~\ref{dcl.array}. |
3189 | 3226 | \enterexample |
3190 | 3227 |
|
3191 | 3228 | \begin{codeblock} |
|
3194 | 3231 |
|
3195 | 3232 | is ill-formed since there is no space for the implied trailing |
3196 | 3233 | \tcode{'\textbackslash 0'}. |
3197 | | -\exitexample |
| 3234 | +\exitexample \exitnote |
3198 | 3235 |
|
3199 | 3236 | \pnum |
3200 | 3237 | If there are fewer initializers than there are array elements, each element not |
|
0 commit comments