From 28c4ef0522ff70d04856e9963881b8973294bc2a Mon Sep 17 00:00:00 2001 From: Jens Maurer Date: Mon, 19 Jun 2023 23:53:33 +0200 Subject: [PATCH 1/2] P2169R4 A nice placeholder with no name --- source/basic.tex | 39 ++++++++++++++++++++++++++++++++++++--- source/declarations.tex | 16 ++++++++++++++-- source/preprocessor.tex | 1 + 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/source/basic.tex b/source/basic.tex index 20d8970469..a87a7bdb73 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{_} 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 From d9c8933328cfb4a057fb45f0b615b85b6a0756b1 Mon Sep 17 00:00:00 2001 From: Jens Maurer Date: Tue, 20 Jun 2023 08:37:56 +0200 Subject: [PATCH 2/2] [basic.scope.scope] Add Unicode name for underscore --- source/basic.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/basic.tex b/source/basic.tex index a87a7bdb73..4ba58bb4e7 100644 --- a/source/basic.tex +++ b/source/basic.tex @@ -989,7 +989,7 @@ \pnum A declaration is \defnx{name-independent}{declaration!name-independent} -if its name is \tcode{_} and it declares +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