|
413 | 413 | \begin{example}
|
414 | 414 | \begin{codeblock}
|
415 | 415 | using X = int;
|
416 |
| -struct A { friend bool operator==(const A&, const A&) = default; }; |
| 416 | +struct A {}; |
417 | 417 | template<const X& x, int i, A a> void f() {
|
418 |
| - i++; // error: change of template-parameter value |
| 418 | + i++; // error: change of \grammarterm{template-parameter} value |
419 | 419 |
|
420 | 420 | &x; // OK
|
421 | 421 | &i; // error: address of non-reference template-parameter
|
|
428 | 428 | \end{example}
|
429 | 429 |
|
430 | 430 | \pnum
|
| 431 | +\begin{note} |
431 | 432 | A non-type
|
432 | 433 | \grammarterm{template-parameter}
|
433 |
| -shall not be declared to have floating-point or void type. |
| 434 | +cannot be declared to have type \cv{} \tcode{void}. |
434 | 435 | \begin{example}
|
435 | 436 | \begin{codeblock}
|
436 |
| -template<double d> class X; // error |
437 |
| -template<double* pd> class Y; // OK |
438 |
| -template<double& rd> class Z; // OK |
| 437 | +template<void v> class X; // error |
| 438 | +template<void* pv> class Y; // OK |
439 | 439 | \end{codeblock}
|
440 | 440 | \end{example}
|
| 441 | +\end{note} |
441 | 442 |
|
442 | 443 | \pnum
|
443 | 444 | A non-type
|
|
1233 | 1234 | A<&f> a; // selects \tcode{f(int)}
|
1234 | 1235 |
|
1235 | 1236 | template<auto n> struct B { @\commentellip@ };
|
1236 |
| -B<5> b1; // OK: template parameter type is \tcode{int} |
1237 |
| -B<'a'> b2; // OK: template parameter type is \tcode{char} |
1238 |
| -B<2.5> b3; // error: template parameter type cannot be \tcode{double} |
| 1237 | +B<5> b1; // OK, template parameter type is \tcode{int} |
| 1238 | +B<'a'> b2; // OK, template parameter type is \tcode{char} |
| 1239 | +B<2.5> b3; // OK, template parameter type is \tcode{double} |
| 1240 | +B<void(0)> b4; // error: template parameter type cannot be \tcode{void} |
1239 | 1241 | \end{codeblock}
|
1240 | 1242 | \end{example}
|
1241 | 1243 |
|
|
1250 | 1252 | @\commentellip@
|
1251 | 1253 | };
|
1252 | 1254 |
|
1253 |
| -X<const char*, "Studebaker"> x; // error: string literal as template-argument |
| 1255 | +X<const char*, "Studebaker"> x; // error: string literal as \grammarterm{template-argument} |
| 1256 | +X<const char*, "Knope" + 1> x2; // error: subobject of string literal as \grammarterm{template-argument} |
1254 | 1257 |
|
1255 | 1258 | const char p[] = "Vivisectionist";
|
1256 | 1259 | X<const char*, p> y; // OK
|
1257 | 1260 |
|
1258 | 1261 | struct A {
|
1259 | 1262 | constexpr A(const char*) {}
|
1260 |
| - friend bool operator==(const A&, const A&) = default; |
1261 | 1263 | };
|
1262 | 1264 |
|
1263 | 1265 | X<A, "Pyrophoricity"> z; // OK, string literal is a constructor argument to \tcode{A}
|
1264 | 1266 | \end{codeblock}
|
1265 | 1267 | \end{example}
|
1266 | 1268 | \end{note}
|
1267 | 1269 |
|
1268 |
| -\pnum |
1269 |
| -\begin{note} |
1270 |
| -The address of an array element or non-static data member is not an acceptable |
1271 |
| -\grammarterm{template-argument}. |
1272 |
| -\begin{example} |
1273 |
| -\begin{codeblock} |
1274 |
| -template<int* p> class X { }; |
1275 |
| - |
1276 |
| -int a[10]; |
1277 |
| -struct S { int m; static int s; } s; |
1278 |
| - |
1279 |
| -X<&a[2]> x3; // error: address of array element |
1280 |
| -X<&s.m> x4; // error: address of non-static member |
1281 |
| -X<&s.s> x5; // OK: address of static member |
1282 |
| -X<&S::s> x6; // OK: address of static member |
1283 |
| -\end{codeblock} |
1284 |
| -\end{example} |
1285 |
| -\end{note} |
1286 |
| - |
1287 | 1270 | \pnum
|
1288 | 1271 | \begin{note}
|
1289 | 1272 | A temporary object
|
|
1296 | 1279 | \begin{codeblock}
|
1297 | 1280 | template<const int& CRI> struct B { @\commentellip@ };
|
1298 | 1281 |
|
1299 |
| -B<1> b2; // error: temporary would be required for template argument |
| 1282 | +B<1> b1; // error: temporary would be required for template argument |
1300 | 1283 |
|
1301 | 1284 | int c = 1;
|
1302 |
| -B<c> b1; // OK |
| 1285 | +B<c> b2; // OK |
| 1286 | + |
| 1287 | +struct X { int n; }; |
| 1288 | +struct Y { const int &r; }; |
| 1289 | +template<Y y> struct C { @\commentellip@ }; |
| 1290 | +C<Y{X{1}.n}> c; // error: subobject of temporary object used to initialize |
| 1291 | + // reference member of template parameter |
1303 | 1292 | \end{codeblock}
|
1304 | 1293 | \end{example}
|
1305 | 1294 | \end{note}
|
|
0 commit comments