Skip to content

Commit af5d427

Browse files
Dawn Perchikzygoloid
authored andcommitted
NB CA 378 (C++20 CD): Remove constrained non-template functions
1 parent 7825bd1 commit af5d427

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

source/declarations.tex

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,7 +2174,7 @@
21742174
The optional \grammarterm{requires-clause}\iref{temp} in an
21752175
\grammarterm{init-declarator} or \grammarterm{member-declarator}
21762176
shall not be present when the declarator does not declare a
2177-
function\iref{dcl.fct}.
2177+
templated function\iref{dcl.fct}.
21782178
%
21792179
\indextext{trailing requires-clause@trailing \textit{requires-clause}|see{\textit{requires-clause}, trailing}}%
21802180
When present after a declarator, the \grammarterm{requires-clause}
@@ -2187,9 +2187,11 @@
21872187
%
21882188
\begin{example}
21892189
\begin{codeblock}
2190-
void f1(int a) requires true; // OK
2191-
auto f2(int a) -> bool requires true; // OK
2192-
auto f3(int a) requires true -> bool; // error: \grammarterm{requires-clause} precedes \grammarterm{trailing-return-type}
2190+
void f1(int a) requires true; // error: non-templated function
2191+
template<typename T>
2192+
auto f2(T a) -> bool requires true; // OK
2193+
template<typename T>
2194+
auto f3(T a) requires true -> bool; // error: \grammarterm{requires-clause} precedes \grammarterm{trailing-return-type}
21932195
void (*pf)() requires true; // error: constraint on a variable
21942196
void g(int (*)() requires true); // error: constraint on a \grammarterm{parameter-declaration}
21952197

source/expressions.tex

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,12 +1324,14 @@
13241324
is ill-formed.
13251325
\begin{example}
13261326
\begin{codeblock}
1327-
void f(int) requires false;
1327+
template<typename T> struct A {
1328+
static void f(int) requires false;
1329+
}
13281330

13291331
void g() {
1330-
f(0); // error: cannot call \tcode{f}
1331-
void (*p1)(int) = f; // error: cannot take the address of \tcode{f}
1332-
decltype(f)* p2 = nullptr; // error: the type \tcode{decltype(f)} is invalid
1332+
A<int>::f(0); // error: cannot call \tcode{f}
1333+
void (*p1)(int) = A<int>::f; // error: cannot take the address of \tcode{f}
1334+
decltype(A<int>::f)* p2 = nullptr; // error: the type \tcode{decltype(A<int>::f)} is invalid
13331335
}
13341336
\end{codeblock}
13351337
In each case, the constraints of \tcode{f} are not satisfied.

source/templates.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,7 +1647,7 @@
16471647

16481648
\pnum
16491649
A template declaration\iref{temp}
1650-
or function declaration\iref{dcl.fct}
1650+
or templated function declaration\iref{dcl.fct}
16511651
can be constrained by the use of a \grammarterm{requires-clause}.
16521652
This allows the specification of constraints for that declaration as
16531653
an expression:
@@ -1666,7 +1666,7 @@
16661666

16671667
\pnum
16681668
\indextext{constraint!associated|see{associated constraints}}%
1669-
A template's \defn{associated constraints} are defined as follows:
1669+
A declaration's \defn{associated constraints} are defined as follows:
16701670

16711671
\begin{itemize}
16721672
\item If there are no introduced \grammarterm{constraint-expression}{s},

0 commit comments

Comments
 (0)