diff --git a/source/basic.tex b/source/basic.tex index 20d8970469..4ba58bb4e7 100644 --- a/source/basic.tex +++ b/source/basic.tex @@ -987,14 +987,32 @@ \end{codeblock} \end{example} +\pnum +A declaration is \defnx{name-independent}{declaration!name-independent} +if its name is \tcode{_} (\unicode{005f}{low line}) and it declares +a variable with automatic storage duration, +a structured binding not inhabiting a namespace scope, +the variable introduced by an \grammarterm{init-capture}, or +a non-static data member. + +\recommended +Implementations should not emit a warning +that a name-independent declaration is used or unused. + \pnum \indextext{declaration!potentially conflict}% Two declarations \defn{potentially conflict} if they correspond and cause their shared name to denote different entities\iref{basic.link}. The program is ill-formed -if, in any scope, a name is bound to two declarations -that potentially conflict and one precedes the other\iref{basic.lookup}. +if, in any scope, a name is bound to two declarations $A$ and $B$ +that potentially conflict and $A$ precedes $B$\iref{basic.lookup}, +unless $B$ is name-independent. +\begin{note} +An \grammarterm{id-expression} that names a unique name-independent declaration +is usable until an additional declaration of the same name +is introduced in the same scope\iref{basic.lookup.general}. +\end{note} \begin{note} Overload resolution can consider potentially conflicting declarations found in multiple scopes @@ -1015,6 +1033,18 @@ namespace B = B; // OK, no effect namespace A = B; // OK, no effect namespace B {} // error: different entity for \tcode{B} + +void g() { + int _; + _ = 0; // OK + int _; // OK, name-independent declaration + _ = 0; // error: two non-function declarations in the lookup set +} +void h () { + int _; // \#1 + _ ++; // OK + static int _; // error: conflicts with \#1 because static variables are not name-independent +} \end{codeblock} \end{example} @@ -1236,7 +1266,9 @@ \end{example} \pnum -If a declaration whose target scope is the block scope $S$ of a +If a declaration +that is not a name-independent declaration and +whose target scope is the block scope $S$ of a \begin{itemize} \item \grammarterm{compound-statement} of a \grammarterm{lambda-expression}, @@ -2728,6 +2760,7 @@ for linkage purposes, if any\iref{dcl.typedef,dcl.enum}, they correspond\iref{basic.scope.scope}, have the same target scope that is not a function or template parameter scope, +neither is a name-independent declaration, and either \begin{itemize} \item diff --git a/source/declarations.tex b/source/declarations.tex index 58962c889a..15c6dc71e5 100644 --- a/source/declarations.tex +++ b/source/declarations.tex @@ -8055,9 +8055,21 @@ \pnum If a declaration named by a \grammarterm{using-declaration} -that inhabits the target scope of another declaration +that inhabits the target scope of another declaration $B$ potentially conflicts with it\iref{basic.scope.scope}, and -either is reachable from the other, the program is ill-formed. +either is reachable from the other, the program is ill-formed +unless $B$ is name-independent and +the \grammarterm{using-declaration} precedes $B$. +\begin{example} +\begin{codeblock} +int _; +void f() { + int _; // B + _ = 0; + using ::_; // error: \grammarterm{using-declaration} does not precede B +} +\end{codeblock} +\end{example} If two declarations named by \grammarterm{using-declaration}s that inhabit the same scope potentially conflict, either is reachable from the other, and diff --git a/source/preprocessor.tex b/source/preprocessor.tex index 23f2fe9bbf..c0e21559f9 100644 --- a/source/preprocessor.tex +++ b/source/preprocessor.tex @@ -1849,6 +1849,7 @@ \defnxname{cpp_nontype_template_args} & \tcode{201911L} \\ \rowsep \defnxname{cpp_nontype_template_parameter_auto} & \tcode{201606L} \\ \rowsep \defnxname{cpp_nsdmi} & \tcode{200809L} \\ \rowsep +\defnxname{cpp_placeholder_variables} & \tcode{202306L} \\ \rowsep \defnxname{cpp_range_based_for} & \tcode{202211L} \\ \rowsep \defnxname{cpp_raw_strings} & \tcode{200710L} \\ \rowsep \defnxname{cpp_ref_qualifiers} & \tcode{200710L} \\ \rowsep