Skip to content

[Motions 2024 03 cwg 1] P3196R0 (Core Language Working Group "ready" Issues) #6906

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

Merged
merged 47 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
47469c0
CWG453 References may only bind to “valid” objects
burblebee Mar 26, 2024
6bd8d0a
CWG1954 typeid null dereference check in subexpressions
burblebee Mar 26, 2024
939d5a5
CWG2476 placeholder-type-specifiers and function declarators
burblebee Mar 27, 2024
44a6d81
CWG2533 Storage duration of implicitly created objects
burblebee Mar 27, 2024
eef4c2b
CWG2546 Defaulted secondary comparison operators defined as deleted
burblebee Mar 27, 2024
5cd87e2
CWG2547 Defaulted comparison operator function for non-classes
burblebee Mar 27, 2024
bc3b802
CWG2560 Parameter type determination in a requirement-parameter-list
burblebee Mar 27, 2024
5227675
CWG2568 Access checking during synthesis of defaulted comparison oper…
burblebee Mar 27, 2024
90558db
CWG2634 Avoid circularity in specification of scope for friend class …
burblebee Mar 27, 2024
b391810
CWG2637 Injected-class-name as a simple-template-id
burblebee Mar 27, 2024
54e3829
CWG2638 Improve the example for initializing by initializer list
burblebee Mar 27, 2024
f0eb8e8
CWG2657 Cv-qualification adjustment when binding reference to temporary
burblebee Mar 27, 2024
2dc0d72
CWG2661 Missing disambiguation rule for pure-specifier vs. brace-or-e…
burblebee Mar 27, 2024
6a2476a
CWG2668 co_await in a lambda-expression
burblebee Mar 27, 2024
c720e60
CWG2689 Are cv-qualified std::nullptr_t fundamental types?
burblebee Mar 27, 2024
2e4a603
CWG2700 #error disallows existing implementation practice
burblebee Mar 27, 2024
5c86660
CWG2707 Deduction guides cannot have a trailing requires-clause
burblebee Mar 27, 2024
5d64fb7
CWG2714 Implicit deduction guides omit properties from the parameter-…
burblebee Mar 27, 2024
4655655
CWG2745 Dependent odr-use in generic lambdas
burblebee Mar 27, 2024
1a2c390
CWG2746 Checking of default template arguments
burblebee Mar 27, 2024
5bd604c
CWG2748 Accessing static data members via null pointer
burblebee Mar 27, 2024
14a05c9
CWG2771 Transformation for unqualified-ids in address operator
burblebee Mar 27, 2024
c37fc84
CWG2775 Unclear argument type for copy of exception object
burblebee Mar 27, 2024
03f6db1
CWG2777 Type of id-expression denoting a template parameter object
burblebee Mar 27, 2024
8fb9318
CWG2803 Overload resolution for reference binding of similar types
burblebee Mar 27, 2024
440cef3
CWG2809 An implicit definition does not redeclare a function
burblebee Mar 27, 2024
76fcfea
CWG2810 Requiring the absence of diagnostics for templates
burblebee Mar 27, 2024
36961e8
CWG2811 Clarify "use" of main
burblebee Mar 27, 2024
03408d1
CWG2813 Class member access with prvalues
burblebee Mar 27, 2024
c6000ad
CWG2820 Value-initialization and default constructors
burblebee Mar 27, 2024
f6228d3
CWG2822 Side-effect-free pointer zap
burblebee Mar 27, 2024
6a36364
CWG2824 Copy-initialization of arrays
burblebee Mar 27, 2024
3bf7dac
CWG2825 Range-based for statement using a braced-init-list
burblebee Mar 27, 2024
0e026f5
CWG2828 Ambiguous interpretation of C-style cast
burblebee Mar 27, 2024
b37a8ce
CWG2830 Top-level cv-qualification should be ignored for list-initial…
burblebee Mar 27, 2024
5b089c3
CWG2831 Non-templated function definitions and requires-clauses
burblebee Mar 27, 2024
0149909
CWG2845 Make the closure type of a captureless lambda a structural type
burblebee Mar 27, 2024
a41b34e
CWG2846 Out-of-class definitions of explicit object member functions
burblebee Mar 27, 2024
69c86fa
CWG2848 Omitting an empty template argument list for explicit instant…
burblebee Mar 27, 2024
aef74c9
CWG2849 Parameter objects are not temporary objects
burblebee Mar 27, 2024
f8b0b5f
CWG2850 Unclear storage duration for function parameter objects
burblebee Mar 27, 2024
8811f8a
CWG2851 Allow floating-point conversions in converted constant expres…
burblebee Mar 27, 2024
e611b75
CWG2853 Pointer arithmetic with pointer to hypothetical element
burblebee Mar 27, 2024
10bddc9
CWG2854 Storage duration of exception objects
burblebee Mar 27, 2024
c95348a
CWG2855 Undefined behavior in postfix increment
burblebee Mar 27, 2024
6b3f68b
CWG2856 Copy-list-initialization with explicit default constructors
burblebee Mar 27, 2024
d0bd27d
CWG2857 Argument-dependent lookup with incomplete class types
burblebee Mar 27, 2024
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
Next Next commit
CWG453 References may only bind to “valid” objects
  • Loading branch information
burblebee authored and tkoeppe committed Apr 15, 2024
commit 47469c02f92b09a1d54d2bd889ef20ee5482ece5
40 changes: 35 additions & 5 deletions source/declarations.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3069,16 +3069,46 @@
specifier\iref{dcl.stc},
is a class member\iref{class.mem} declaration within a class definition,
or is the declaration of a parameter or a return type\iref{dcl.fct}; see~\ref{basic.def}.
A reference shall be initialized to refer to a valid object or function.

\pnum
Attempting to bind a reference to a function where
the converted initializer is a glvalue whose
type is not call-compatible\iref{expr.call}
with the type of the function's definition
results in undefined behavior.
Attempting to bind a reference to an object where
the converted initializer is a glvalue through which
the object is not type-accessible\iref{basic.lval}
results in undefined behavior.
\begin{note}
\indextext{reference!null}%
In particular, a null reference cannot exist in a well-defined program,
because the only way to create such a reference would be to bind it to
the ``object'' obtained by indirection through a null pointer,
which causes undefined behavior.
The object designated by such a glvalue can be
outside its lifetime\iref{basic.life}.
Because a null pointer value or a pointer past the end of an object
does not point to an object,
a reference in a well-defined program cannot refer to such things;
see~\ref{expr.unary.op}.
As described in~\ref{class.bit}, a reference cannot be bound directly
to a bit-field.
\end{note}
The behavior of an evaluation of a reference\iref{expr.prim.id, expr.ref} that
does not happen after\iref{intro.races} the initialization of the reference
is undefined.
\begin{example}
\begin{codeblock}
int &f(int&);
int &g();
extern int &ir3;
int *ip = 0;
int &ir1 = *ip; // undefined behavior: null pointer
int &ir2 = f(ir3); // undefined behavior: \tcode{ir3} not yet initialized
int &ir3 = g();
int &ir4 = f(ir4); // undefined behavior: \tcode{ir4} used in its own initializer

char x alignas(int);
int &ir5 = *reinterpret_cast<int *>(&x); // undefined behavior: initializer refers to char object
\end{codeblock}
\end{example}

\pnum
\indextext{reference collapsing}%
Expand Down
41 changes: 24 additions & 17 deletions source/expressions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -300,23 +300,24 @@
\end{note}

\pnum
An object of dynamic type $\tcode{T}_\text{obj}$ is
\defn{type-accessible} through a glvalue of type $\tcode{T}_\text{ref}$
if $\tcode{T}_\text{ref}$ is similar\iref{conv.qual} to:
\begin{itemize}
\item $\tcode{T}_\text{obj}$,

\item a type that is the signed or unsigned type corresponding to $\tcode{T}_\text{obj}$, or

\item a \keyword{char}, \tcode{\keyword{unsigned} \keyword{char}}, or \tcode{std::byte} type.
\end{itemize}
If a program attempts to access\iref{defns.access}
the stored value of an object through a glvalue
whose type is not similar\iref{conv.qual} to
one of the following types the behavior is
undefined:
through which it is not type-accessible,
the behavior is undefined.
\begin{footnote}
The intent of this list is to specify those circumstances in which an
object can or cannot be aliased.
\end{footnote}
\begin{itemize}
\item the dynamic type of the object,

\item a type that is the signed or unsigned type corresponding to the
dynamic type of the object, or

\item a \keyword{char}, \tcode{\keyword{unsigned} \keyword{char}}, or \tcode{std::byte} type.
\end{itemize}
If a program invokes
a defaulted copy/move constructor or copy/move assignment operator
for a union of type \tcode{U} with a glvalue argument
Expand Down Expand Up @@ -3270,14 +3271,20 @@
of the class member access\iref{expr.ref,basic.life}.

\pnum
A type $\tcode{T}_\text{call}$ is
\defn{call-compatible} with a function type $\tcode{T}_\text{func}$
if $\tcode{T}_\text{call}$ is the same type as $\tcode{T}_\text{func}$ or
if the type ``pointer to $\tcode{T}_\text{func}$'' can be
converted to type ``pointer to $\tcode{T}_\text{call}$''
via a function pointer conversion\iref{conv.fctptr}.
Calling a function through an
expression whose function type \tcode{E} is different
from the function type \tcode{F} of the called function's
definition results in undefined behavior
unless the type ``pointer to \tcode{F}'' can be converted
to the type ``pointer to \tcode{E}'' via a function pointer conversion\iref{conv.fctptr}.
expression whose function type
is not call-compatible with the
type of the called function's
definition results in undefined behavior.
\begin{note}
The exception applies when the expression has the type of a
This requirement allows the case
when the expression has the type of a
potentially-throwing function, but the called function has
a non-throwing exception specification,
and the function types are otherwise the same.
Expand Down