Skip to content

Commit d0acd26

Browse files
jensmaurerzygoloid
authored andcommitted
P1766R1 Mitigating minor modules maladies
1 parent f81ed8b commit d0acd26

File tree

3 files changed

+59
-9
lines changed

3 files changed

+59
-9
lines changed

source/basic.tex

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,9 @@
276276
\rSec1[basic.def.odr]{One-definition rule}
277277

278278
\pnum
279-
A variable, function, class type, enumeration type, or template
279+
A variable, function, class type, enumeration type, template,
280+
default argument for a parameter (for a function in a given scope), or
281+
default template argument
280282
shall not be defined where a prior definition is necessarily reachable\iref{module.reach};
281283
no diagnostic is required if the prior declaration is in another translation unit.
282284

@@ -548,10 +550,12 @@
548550
non-static function template\iref{temp.fct},
549551
concept\iref{temp.concept},
550552
static data member of a class template\iref{temp.static}, member
551-
function of a class template\iref{temp.mem.func}, or template
553+
function of a class template\iref{temp.mem.func}, template
552554
specialization for which some template parameters are not
553-
specified~(\ref{temp.spec}, \ref{temp.class.spec}) in a program
554-
provided that
555+
specified~(\ref{temp.spec}, \ref{temp.class.spec}),
556+
default argument for a parameter (for a function in a given scope), or
557+
default template argument
558+
in a program provided that
555559
no prior definition is necessarily reachable\iref{module.reach}
556560
at the point where a definition appears, and
557561
provided the definitions satisfy the following requirements.

source/compatibility.tex

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,6 +1922,34 @@
19221922

19231923
\rSec2[diff.cpp17.dcl.dcl]{\ref{dcl.dcl}: declarations}
19241924

1925+
\diffref{dcl.typedef}
1926+
\change Unnamed classes with a typedef name for linkage purposes
1927+
can only contain C-compatible constructs.
1928+
\rationale Necessary for implementability.
1929+
\effect Valid C++ 2017 code may be ill-formed in this International Standard.
1930+
\begin{codeblock}
1931+
typedef struct {
1932+
void f() {} // ill-formed; previously well-formed
1933+
} S;
1934+
\end{codeblock}
1935+
1936+
\diffref{dcl.fct.default}
1937+
\change A function cannot have different default arguments
1938+
in different translation units.
1939+
\rationale Required for modules support.
1940+
\effect Valid C++ 2017 code may be ill-formed in this International Standard,
1941+
with no diagnostic required.
1942+
\begin{codeblock}
1943+
// Translation unit 1
1944+
int f(int a = 42);
1945+
int g() { return f(); }
1946+
1947+
// Translation unit 2
1948+
int f(int a = 76) { return a; } // ill-formed (no diagnostic required); previously well-formed
1949+
int g();
1950+
int main() { return g(); } // used to return 42
1951+
\end{codeblock}
1952+
19251953
\diffref{dcl.init.aggr}
19261954
\change A class that has user-declared constructors is never an aggregate.
19271955
\rationale Remove potentially error-prone aggregate initialization

source/declarations.tex

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,24 @@
736736
typedef decltype([]{}) C; // the closure type has no name for linkage purposes
737737
\end{codeblock}
738738
\end{example}
739+
An unnamed class with a typedef name for linkage purposes shall not
740+
\begin{itemize}
741+
\item
742+
declare any members
743+
other than non-static data members, member enumerations, or member classes,
744+
\item
745+
have any base classes or default member initializers, or
746+
\item
747+
contain a \grammarterm{lambda-expression},
748+
\end{itemize}
749+
and all member classes shall also satisfy these requirements (recursively).
750+
\begin{example}
751+
\begin{codeblock}
752+
typedef struct {
753+
int f() {}
754+
} X; // error: struct with typedef name for linkage has member functions
755+
\end{codeblock}
756+
\end{example}
739757

740758
\rSec2[dcl.friend]{The \tcode{friend} specifier}%
741759
\indextext{specifier!\idxcode{friend}}
@@ -3777,11 +3795,12 @@
37773795
supplied in this or a previous declaration,
37783796
unless the parameter was expanded from a parameter pack,
37793797
or shall be a function parameter pack.
3798+
\begin{note}
37803799
A default argument
3781-
shall not be redefined by a later declaration (not even to the
3782-
same value).
3800+
cannot be redefined by a later declaration
3801+
(not even to the same value)\iref{basic.def.odr}.
3802+
\end{note}
37833803
\begin{example}
3784-
37853804
\begin{codeblock}
37863805
void g(int = 0, ...); // OK, ellipsis is not a parameter so it can follow
37873806
// a parameter with a default argument
@@ -3809,8 +3828,7 @@
38093828
\end{example}
38103829
For a given inline function defined in different translation units,
38113830
the accumulated sets of default arguments at the end of the
3812-
translation units shall be the same;
3813-
see~\ref{basic.def.odr}.
3831+
translation units shall be the same; no diagnostic is required.
38143832
If a friend declaration specifies a default argument expression,
38153833
that declaration shall be a definition and shall be the only
38163834
declaration of the function or function template in the translation unit.

0 commit comments

Comments
 (0)