Skip to content

[basic.def.odr] Greatly expand example 6 #6483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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