Skip to content

Commit 788436e

Browse files
authored
Merge 2019-11 CWG Motion 3
P1971R0 Core Language Changes for NB Comments
2 parents 2978956 + af5d427 commit 788436e

File tree

9 files changed

+224
-86
lines changed

9 files changed

+224
-86
lines changed

source/basic.tex

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2606,11 +2606,6 @@
26062606
\opt{global-module-fragment} module-declaration \opt{top-level-declaration-seq} \opt{private-module-fragment}
26072607
\end{bnf}
26082608

2609-
\begin{bnf}
2610-
\nontermdef{private-module-fragment}\br
2611-
\keyword{module} \terminal{:} \keyword{private} \terminal{;} \opt{top-level-declaration-seq}
2612-
\end{bnf}
2613-
26142609
\begin{bnf}
26152610
\nontermdef{top-level-declaration-seq}\br
26162611
top-level-declaration\br
@@ -2623,13 +2618,6 @@
26232618
declaration
26242619
\end{bnf}
26252620

2626-
\pnum
2627-
A \grammarterm{private-module-fragment} shall appear only
2628-
in a primary module interface unit\iref{module.unit}.
2629-
A module unit with a \grammarterm{private-module-fragment}
2630-
shall be the only module unit of its module;
2631-
no diagnostic is required.
2632-
26332621
\pnum
26342622
A token sequence beginning with
26352623
\opt{\tcode{export}} \tcode{module}
@@ -2819,11 +2807,10 @@
28192807
\item both names refer to members of the same namespace or to members,
28202808
not by inheritance, of the same class; and
28212809

2822-
\item when both names denote functions, the parameter-type-lists of the
2823-
functions\iref{dcl.fct} are identical; and
2810+
\item when both names denote functions or function templates,
2811+
the signatures~(\ref{defns.signature}, \ref{defns.signature.templ})
2812+
are the same.
28242813

2825-
\item when both names denote function templates, the
2826-
signatures\iref{temp.over.link} are the same.
28272814
\end{itemize}
28282815
If multiple declarations of the same name with external linkage
28292816
would declare the same entity except that
@@ -3017,24 +3004,6 @@
30173004
\item
30183005
the new object is of the same type as \placeholder{e} (ignoring cv-qualification).
30193006
\end{itemize}
3020-
\begin{note}
3021-
If the subobject contains a reference member or a \tcode{const} subobject,
3022-
the name of the original subobject cannot be used to access the new object\iref{basic.life}.
3023-
\end{note}
3024-
\begin{example}
3025-
\begin{codeblock}
3026-
struct X { const int n; };
3027-
union U { X x; float f; };
3028-
void tong() {
3029-
U u = {{ 1 }};
3030-
u.f = 5.f; // OK, creates new subobject of \tcode{u}\iref{class.union}
3031-
X *p = new (&u.x) X {2}; // OK, creates new subobject of \tcode{u}
3032-
assert(p->n == 2); // OK
3033-
assert(*std::launder(&u.x.n) == 2); // OK
3034-
assert(u.x.n == 2); // undefined behavior, \tcode{u.x} does not name new subobject
3035-
}
3036-
\end{codeblock}
3037-
\end{example}
30383007

30393008
\pnum
30403009
\indextext{object!providing storage for}%
@@ -3359,9 +3328,9 @@
33593328
\item the new object is of the same type as the original object
33603329
(ignoring the top-level cv-qualifiers), and
33613330

3362-
\item the type of the original object is not const-qualified, and, if a
3363-
class type, does not contain any non-static data member whose type is
3364-
const-qualified or a reference type, and
3331+
\item the original object is neither
3332+
a complete object that is const-qualified nor
3333+
a subobject of such an object, and
33653334

33663335
\item neither the original object nor the new object
33673336
is a potentially-overlapping subobject\iref{intro.object}.
@@ -3696,13 +3665,13 @@
36963665
\tcode{std::align_val_t},
36973666
or any other names that the library uses to
36983667
declare these names. Thus, a \grammarterm{new-expression},
3699-
\grammarterm{delete-expression} or function call that refers to one of
3700-
these functions without including the header \libheaderref{new} is
3668+
\grammarterm{delete-expression}, or function call that refers to one of
3669+
these functions without importing or including the header \libheaderref{new} is
37013670
well-formed. However, referring to \tcode{std}
37023671
or \tcode{std::size_t}
37033672
or \tcode{std::align_val_t}
37043673
is ill-formed unless the name has been declared
3705-
by including the appropriate header.
3674+
by importing or including the appropriate header.
37063675
\end{note}
37073676
Allocation and/or
37083677
deallocation functions may also be declared and defined for any

source/declarations.tex

Lines changed: 30 additions & 10 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

@@ -5500,7 +5502,7 @@
55005502
\end{note}
55015503
The template
55025504
\tcode{std::initializer_list} is not predefined; if the header
5503-
\tcode{<initializer_list>} is not included prior to a use of
5505+
\tcode{<initializer_list>} is not imported or included prior to a use of
55045506
\tcode{std::initializer_list} --- even an implicit use in which the type is not
55055507
named\iref{dcl.spec.auto} --- the program is ill-formed.
55065508

@@ -6251,10 +6253,12 @@
62516253
\bnfindent promise-type \exposid{promise} promise-constructor-arguments \terminal{;}\br
62526254
% FIXME: \bnfindent \exposid{promise}\terminal{.get_return_object()} \terminal{;}
62536255
% ... except that it's not a discarded-value expression
6254-
\bnfindent \terminal{co_await} \terminal{\exposid{promise}.initial_suspend()} \terminal{;}\br
62556256
\bnfindent \terminal{try} \terminal{\{}\br
6257+
\bnfindent\bnfindent \terminal{co_await} \terminal{\exposid{promise}.initial_suspend()} \terminal{;}\br
62566258
\bnfindent\bnfindent function-body\br
62576259
\bnfindent \terminal{\} catch ( ... ) \{}\br
6260+
\bnfindent\bnfindent \terminal{if (!\exposid{initial-await-resume-called})}\br
6261+
\bnfindent\bnfindent\bnfindent \terminal{throw} \terminal{;}\br
62586262
\bnfindent\bnfindent \terminal{\exposid{promise}.unhandled_exception()} \terminal{;}\br
62596263
\bnfindent \terminal{\}}\br
62606264
\exposid{final-suspend} \terminal{:}\br
@@ -6272,6 +6276,12 @@
62726276
the call to \tcode{final_suspend}
62736277
is the \defn{final suspend point}, and
62746278
\item
6279+
\placeholder{initial-await-resume-called}
6280+
is initially \tcode{false} and is set to \tcode{true}
6281+
immediately before the evaluation
6282+
of the \placeholder{await-resume} expression\iref{expr.await}
6283+
of the initial suspend point, and
6284+
\item
62756285
\placeholder{promise-type} denotes the promise type, and
62766286
\item
62776287
the object denoted by the exposition-only name \exposid{promise}
@@ -7887,8 +7897,13 @@
78877897
a function introduced by a \grammarterm{using-declaration}, and the
78887898
declarations do not declare the same function, the program is
78897899
ill-formed. If a function template declaration in namespace scope has
7890-
the same name, parameter-type-list, return type, and template
7891-
parameter list as a function template introduced by a
7900+
the same
7901+
name,
7902+
parameter-type-list,
7903+
trailing \grammarterm{requires-clause} (if any),
7904+
return type, and
7905+
\grammarterm{template-head},
7906+
as a function template introduced by a
78927907
\grammarterm{using-declaration}, the program is ill-formed.
78937908
\begin{note}
78947909
Two \grammarterm{using-declaration}{s} may introduce functions with the same
@@ -7924,8 +7939,13 @@
79247939
When a \grammarterm{using-declarator} brings declarations from a base class into
79257940
a derived class, member functions and member function templates in
79267941
the derived class override and/or hide member functions and member
7927-
function templates with the same name,
7928-
parameter-type-list\iref{dcl.fct}, cv-qualification, and \grammarterm{ref-qualifier} (if any) in a base
7942+
function templates with the same
7943+
name,
7944+
parameter-type-list\iref{dcl.fct},
7945+
trailing \grammarterm{requires-clause} (if any),
7946+
cv-qualification, and
7947+
\grammarterm{ref-qualifier} (if any),
7948+
in a base
79297949
class (rather than conflicting).
79307950
Such hidden or overridden declarations are excluded from the set of
79317951
declarations introduced by the \grammarterm{using-declarator}.

source/expressions.tex

Lines changed: 21 additions & 13 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.
@@ -3597,7 +3599,8 @@
35973599
\end{example}
35983600

35993601
\pnum
3600-
If the header \libheaderrefx{typeinfo}{type.info} is not included prior
3602+
If the header \libheaderrefx{typeinfo}{type.info}
3603+
is not imported or included prior
36013604
to a use of \tcode{typeid}, the program is ill-formed.
36023605

36033606
\pnum
@@ -6007,7 +6010,7 @@
60076010
\tcode{std::partial_ordering})
60086011
are not predefined;
60096012
if the header \libheaderref{compare}
6010-
is not included prior to a use of such a class type --
6013+
is not imported or included prior to a use of such a class type --
60116014
even an implicit use in which the type is not named
60126015
(e.g., via the \tcode{auto} specifier\iref{dcl.spec.auto}
60136016
in a defaulted three-way comparison\iref{class.spaceship}
@@ -7132,31 +7135,36 @@
71327135

71337136
\pnum
71347137
For the purposes of determining
7135-
whether an expression is a core constant expression,
7138+
whether an expression \tcode{e} is a core constant expression,
71367139
the evaluation of a call to a member function of \tcode{std::allocator<T>}
71377140
as defined in \ref{allocator.members}, where \tcode{T} is a literal type,
7138-
does not disqualify the expression from being a core constant expression,
7141+
does not disqualify \tcode{e} from being a core constant expression,
71397142
even if the actual evaluation of such a call
71407143
would otherwise fail the requirements for a core constant expression.
71417144
Similarly, the evaluation of a call to
71427145
\tcode{std::destroy_at},
71437146
\tcode{std::ranges::destroy_at},
71447147
\tcode{std::construct_at}, or
71457148
\tcode{std::ranges::construct_at}
7146-
is a valid core constant expression unless:
7149+
does not disqualify \tcode{e}
7150+
from being a core constant expression unless:
71477151
\begin{itemize}
71487152
\item
71497153
for a call to \tcode{std::construct_at} or \tcode{std::ranges::construct_at},
71507154
the first argument, of type \tcode{T*},
7151-
does not point to storage allocated with \tcode{std::allocator<T>} or
7155+
does not point
7156+
to storage allocated with \tcode{std::allocator<T>} or
7157+
to an object whose lifetime began within the evaluation of \tcode{e}, or
71527158
the evaluation of the underlying constructor call
7153-
is not a core constant expression, or
7159+
disqualifies \tcode{e} from being a core constant expression, or
71547160
\item
71557161
for a call to \tcode{std::destroy_at} or \tcode{std::ranges::destroy_at},
71567162
the first argument, of type \tcode{T*},
7157-
does not point to storage allocated with \tcode{std::allocator<T>} or
7163+
does not point
7164+
to storage allocated with \tcode{std::allocator<T>} or
7165+
to an object whose lifetime began within the evaluation of \tcode{e}, or
71587166
the evaluation of the underlying destructor call
7159-
is not a core constant expression.
7167+
disqualifies \tcode{e} from being a core constant expression.
71607168
\end{itemize}
71617169

71627170
\pnum

source/intro.tex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
\pnum
1414
\Cpp{} is a general purpose programming language based on the C
15-
programming language as described in ISO/IEC 9899:2011
15+
programming language as described in ISO/IEC 9899:2018
1616
\doccite{Programming languages --- C} (hereinafter referred to as the
1717
\defnx{C standard}{C!standard}). \Cpp{} provides many facilities
1818
beyond those provided by C, including additional data types,
@@ -47,7 +47,7 @@
4747
Vocabulary}
4848
\item ISO 8601:2004, \doccite{Data elements and interchange formats ---
4949
Information interchange --- Representation of dates and times}
50-
\item ISO/IEC 9899:2011, \doccite{Programming languages --- C}
50+
\item ISO/IEC 9899:2018, \doccite{Programming languages --- C}
5151
\item ISO/IEC 9945:2003, \doccite{Information Technology --- Portable
5252
Operating System Interface (POSIX)}
5353
\item ISO/IEC 10646, \doccite{Information technology ---
@@ -63,7 +63,7 @@
6363
\end{itemize}
6464

6565
\pnum
66-
The library described in Clause 7 of ISO/IEC 9899:2011
66+
The library described in Clause 7 of ISO/IEC 9899:2018
6767
is hereinafter called the
6868
\defnx{C standard library}{C!standard library}.%
6969
\footnote{With the qualifications noted in \ref{\firstlibchapter}

source/modules.tex

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,10 +529,10 @@
529529
\end{example}
530530

531531
\pnum
532-
A translation unit has an \defn{interface dependency} on a module unit \tcode{U}
532+
A translation unit has an \defn{interface dependency} on a translation unit \tcode{U}
533533
if it contains a \grammarterm{module-declaration} or
534534
\grammarterm{module-import-declaration} that imports \tcode{U} or if it has
535-
an interface dependency on a module unit that has an interface dependency on \tcode{U}.
535+
an interface dependency on a translation unit that has an interface dependency on \tcode{U}.
536536
A translation unit shall not have an interface dependency on itself.
537537
\begin{example}
538538
\begin{codeblocktu}{Interface unit of \tcode{M1}}
@@ -758,6 +758,75 @@
758758
\end{codeblocktu}
759759
\end{example}
760760

761+
\rSec1[module.private.frag]{Private module fragment}
762+
763+
\begin{bnf}
764+
\nontermdef{private-module-fragment}\br
765+
\keyword{module} \terminal{:} \keyword{private} \terminal{;} \opt{top-level-declaration-seq}
766+
\end{bnf}
767+
768+
\pnum
769+
A \grammarterm{private-module-fragment} shall appear only
770+
in a primary module interface unit\iref{module.unit}.
771+
A module unit with a \grammarterm{private-module-fragment}
772+
shall be the only module unit of its module;
773+
no diagnostic is required.
774+
775+
\pnum
776+
\begin{note}
777+
A \grammarterm{private-module-fragment} ends
778+
the portion of the module interface unit
779+
that can affect the behavior of other translation units.
780+
A \grammarterm{private-module-fragment} allows a module
781+
to be represented as a single translation unit
782+
without making all of the contents of the module reachable to importers.
783+
The presence of a \grammarterm{private-module-fragment} affects:
784+
\begin{itemize}
785+
\item
786+
the point by which the definition of
787+
an exported inline function
788+
is required\iref{dcl.inline},
789+
790+
\item
791+
the point by which the definition of
792+
an exported function with a placeholder return type
793+
is required\iref{dcl.spec.auto},
794+
795+
\item
796+
the instantiation contexts of templates
797+
instantiated before it\iref{module.context}, and
798+
799+
\item
800+
the reachability of declarations within it\iref{module.reach}.
801+
\end{itemize}
802+
\end{note}
803+
804+
\pnum
805+
\begin{example}
806+
\begin{codeblock}
807+
export module A;
808+
export inline void fn_e(); // error: exported inline function \tcode{fn_e} not defined
809+
// before private module fragment
810+
inline void fn_m(); // OK, module-linkage inline function
811+
static void fn_s();
812+
export struct X;
813+
export void g(X *x) {
814+
fn_s(); // OK, call to static function in same translation unit
815+
fn_m(); // OK, call to module-linkage inline function
816+
}
817+
export X *factory(); // OK
818+
819+
module :private;
820+
struct X {}; // definition not reachable from importers of \tcode{A}
821+
X *factory() {
822+
return new X ();
823+
}
824+
void fn_e() {}
825+
void fn_m() {}
826+
void fn_s() {}
827+
\end{codeblock}
828+
\end{example}
829+
761830
\rSec1[module.context]{Instantiation context}
762831

763832
\pnum

0 commit comments

Comments
 (0)