Skip to content

Commit

Permalink
[basic.def.odr] greatly expand example
Browse files Browse the repository at this point in the history
  • Loading branch information
Eisenwave committed Aug 20, 2023
1 parent a272b7c commit a57a873
Showing 1 changed file with 48 additions and 8 deletions.
56 changes: 48 additions & 8 deletions source/basic.tex
Original file line number Diff line number Diff line change
Expand Up @@ -774,34 +774,74 @@

\pnum
\begin{example}
\begin{codeblock}
static int local = 0;
inline int a(int = local) {
return 0;
}
inline int b = a(0);
\end{codeblock}
If the definition of \tcode{a} or \tcode{b} appears in multiple translation units,
the behavior of the program is as if
there is only one definition of \tcode{a} or \tcode{b}, respectively.

\begin{codeblock}
inline int c = a();
\end{codeblock}
If the definition of \tcode{c} appears in multiple translation units,
the program is ill-formed (no diagnostic required) because
each such definition calls \tcode{a} with a different function argument.

\begin{codeblock}
inline void f(bool cond, void (*p)()) {
if (cond) f(false, []{});
}
\end{codeblock}
If the definition of \tcode{f} appears in multiple translation units,
the behavior of the program is as if
there is only one definition of \tcode{f}.

\begin{codeblock}
inline void g(bool cond, void (*p)() = []{}) {
if (cond) g(false);
}
\end{codeblock}
If the definition of \tcode{g} appears in multiple translation units,
the program is ill-formed (no diagnostic required) because
each such definition uses a default argument that
refers to a distinct \grammarterm{lambda-expression} closure type.

\begin{codeblock}
struct X {
void h(bool cond, void (*p)() = []{}) {
if (cond) h(false);
}
};
\end{codeblock}

If the definition of \tcode{f} appears in multiple translation units,
the behavior of the program is as if
there is only one definition of \tcode{f}.
If the definition of \tcode{g} appears in multiple translation units,
the program is ill-formed (no diagnostic required) because
each such definition uses a default argument that
refers to a distinct \grammarterm{lambda-expression} closure type.
The definition of \tcode{X} can appear
in multiple translation units of a valid program;
the \grammarterm{lambda-expression}{s} defined within
the default argument of \tcode{X::h} within the definition of \tcode{X}
denote the same closure type in each translation unit.

\begin{codeblock}
inline decltype([]{}) u = {};
\end{codeblock}
If the declaration of \tcode{u} appears in multiple translation units,
the program is ill-formed (no diagnostic required) because each such declaration
declares an object of distinct type.

\begin{codeblock}
inline auto v = []{};
inline auto w = decltype([]{}){};
\end{codeblock}
If the definition of \tcode{v} or \tcode{w} appears in multiple translation units,
the behavior is as if there is only one definition of \tcode{v} or \tcode{w}
because the definition of its closure type is considered to be part of the
token sequence of the definition of \tcode{v} or \tcode{w} respectively.
\end{example}


\pnum
If, at any point in the program,
there is more than one
Expand Down

0 comments on commit a57a873

Please sign in to comment.