|
4372 | 4372 | variable template, or concept, |
4373 | 4373 | respectively, and substitute it for each occurrence of that parameter |
4374 | 4374 | in the function type of the template. |
4375 | | -\begin{note} |
4376 | | -The type replacing the placeholder |
| 4375 | +The type replacing a placeholder |
4377 | 4376 | in the type of the value synthesized for a constant template parameter |
4378 | | -is also a unique synthesized type. |
4379 | | -\end{note} |
| 4377 | +is a unique synthesized type. |
4380 | 4378 |
|
4381 | 4379 | \pnum |
4382 | 4380 | %FIXME: What's a "synthesized template"? Do we mean the synthesized |
|
9390 | 9388 | \end{note} |
9391 | 9389 |
|
9392 | 9390 | \pnum |
9393 | | -If \tcode{P} has a form that contains \tcode{<i>}, and |
9394 | | -if the type of \tcode{i} differs from the type |
| 9391 | +If \tcode{P} has a form that contains \tcode{<i>}, |
| 9392 | +deduction fails unless the type of \tcode{i} is the same as that |
9395 | 9393 | of the corresponding template parameter |
| 9394 | +\tcode{p} in the specialization (from \tcode{A}) |
9396 | 9395 | of the template named by the enclosing \grammarterm{simple-template-id} or |
9397 | | -\grammarterm{splice-specialization-specifier}, deduction fails. |
| 9396 | +\grammarterm{splice-specialization-specifier}; |
| 9397 | +if the declared type of \tcode{i} contains a placeholder type, |
| 9398 | +the corresponding template argument for the purposes of |
| 9399 | +placeholder type deduction\iref{dcl.type.auto.deduct} |
| 9400 | +is an \grammarterm{id-expression} for \tcode{p}. |
9398 | 9401 | If \tcode{P} has a form that contains \tcode{[i]}, and if the type of |
9399 | 9402 | \tcode{i} is not an integral type, deduction fails. |
9400 | 9403 | \begin{footnote} |
|
9414 | 9417 | template<short s> void f(A<s>); |
9415 | 9418 | void k1() { |
9416 | 9419 | A<1> a; |
9417 | | - f(a); // error: deduction fails for conversion from \tcode{int} to \tcode{short} |
9418 | | - f<1>(a); // OK |
| 9420 | + f(a); // error: deduction fails for conversion from \tcode{int} to \tcode{short} |
| 9421 | + f<1>(a); // OK |
9419 | 9422 | } |
9420 | 9423 |
|
9421 | 9424 | template<const short cs> class B { }; |
9422 | 9425 | template<short s> void g(B<s>); |
9423 | 9426 | void k2() { |
9424 | 9427 | B<1> b; |
9425 | | - g(b); // OK, cv-qualifiers are ignored on template parameter types |
| 9428 | + g(b); // OK, cv-qualifiers are ignored on template parameter types |
| 9429 | +} |
| 9430 | + |
| 9431 | +template<auto> struct C; |
| 9432 | +template<long long x> void f(C<x> *); |
| 9433 | +void g(C<0LL> *ap) { |
| 9434 | + f(ap); // OK, deduces long long value from 0LL |
| 9435 | +} |
| 9436 | + |
| 9437 | +template<int> struct D; |
| 9438 | +template<auto x> void f(D<x> *); |
| 9439 | +void g(D<0LL> *ap) { |
| 9440 | + f(ap); // OK, deduces x as an int value |
| 9441 | +} |
| 9442 | + |
| 9443 | +template<int &> struct E; |
| 9444 | +template<auto x> void f(E<x> *); |
| 9445 | +int v; |
| 9446 | +void g(E<v> *bp) { |
| 9447 | + f(bp); // error: type \tcode{int} of \tcode{x} does not match the \tcode{int &} type |
| 9448 | +} // of the template parameter in the \tcode{E<v>} specialization of \tcode{E} |
| 9449 | + |
| 9450 | +template<const int &> struct F; |
| 9451 | +template<decltype(auto) x> void f(F<x> *); |
| 9452 | +int i; |
| 9453 | +void g(F<i> *ap) { |
| 9454 | + f(ap); // OK, deduces \tcode{x} as a constant template parameter of type \tcode{const int &} |
| 9455 | +} |
| 9456 | + |
| 9457 | +template <decltype(auto) q> struct G; |
| 9458 | +template <auto x> long *f(G<x> *); // \#1 |
| 9459 | +template <decltype(auto) x> short *f(G<x> *); // \#2 |
| 9460 | + |
| 9461 | +const int j = 0; |
| 9462 | +short *g(G<(j)> *ap) { // OK, \tcode{q} has type \tcode{const int &} |
| 9463 | + return f(ap); // OK, only \tcode{#2} matches |
| 9464 | +} |
| 9465 | + |
| 9466 | +long *g(G<j> *ap) { // OK, \tcode{q} has type \tcode{int} |
| 9467 | + return f(ap); // OK, \#1 is more specialized |
9426 | 9468 | } |
9427 | 9469 | \end{codeblock} |
9428 | 9470 | \end{example} |
|
0 commit comments