Skip to content

Commit 6ec7eb8

Browse files
committed
[temp.param] [temp.arg.nontype] Update examples and redundant duplicated
wording to match P1907R1.
1 parent cf25714 commit 6ec7eb8

File tree

1 file changed

+21
-32
lines changed

1 file changed

+21
-32
lines changed

source/templates.tex

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,9 @@
413413
\begin{example}
414414
\begin{codeblock}
415415
using X = int;
416-
struct A { friend bool operator==(const A&, const A&) = default; };
416+
struct A {};
417417
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
419419

420420
&x; // OK
421421
&i; // error: address of non-reference template-parameter
@@ -428,16 +428,17 @@
428428
\end{example}
429429

430430
\pnum
431+
\begin{note}
431432
A non-type
432433
\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}.
434435
\begin{example}
435436
\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
439439
\end{codeblock}
440440
\end{example}
441+
\end{note}
441442

442443
\pnum
443444
A non-type
@@ -1233,9 +1234,10 @@
12331234
A<&f> a; // selects \tcode{f(int)}
12341235

12351236
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}
12391241
\end{codeblock}
12401242
\end{example}
12411243

@@ -1250,40 +1252,21 @@
12501252
@\commentellip@
12511253
};
12521254

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}
12541257

12551258
const char p[] = "Vivisectionist";
12561259
X<const char*, p> y; // OK
12571260

12581261
struct A {
12591262
constexpr A(const char*) {}
1260-
friend bool operator==(const A&, const A&) = default;
12611263
};
12621264

12631265
X<A, "Pyrophoricity"> z; // OK, string literal is a constructor argument to \tcode{A}
12641266
\end{codeblock}
12651267
\end{example}
12661268
\end{note}
12671269

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-
12871270
\pnum
12881271
\begin{note}
12891272
A temporary object
@@ -1296,10 +1279,16 @@
12961279
\begin{codeblock}
12971280
template<const int& CRI> struct B { @\commentellip@ };
12981281

1299-
B<1> b2; // error: temporary would be required for template argument
1282+
B<1> b1; // error: temporary would be required for template argument
13001283

13011284
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
13031292
\end{codeblock}
13041293
\end{example}
13051294
\end{note}

0 commit comments

Comments
 (0)