<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang xml:lang>

<head>
    <meta charset="utf-8" />
    <meta name="generator" content="mpark/wg21" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />      <meta name="dcterms.date" content="2020-01-12" />      <title>Prohibit zero and NULL from being used as null pointer literals</title>
    <style>
        code {
            white-space: pre-wrap;
        }
        
        span.smallcaps {
            font-variant: small-caps;
        }
        
        span.underline {
            text-decoration: underline;
        }
        
        div.column {
            display: inline-block;
            vertical-align: top;
            width: 50%;
        }
        
        
    </style>
        <style>
        pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
  { counter-reset: source-line 0; }
pre.numberSource code > span
  { position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
  { content: counter(source-line);
    position: relative; left: -1em; text-align: right; vertical-align: baseline;
    border: none; display: inline-block;
    -webkit-touch-callout: none; -webkit-user-select: none;
    -khtml-user-select: none; -moz-user-select: none;
    -ms-user-select: none; user-select: none;
    padding: 0 4px; width: 4em;
    color: #aaaaaa;
  }
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa;  padding-left: 4px; }
div.sourceCode
  {  background-color: #f6f8fa; }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span. { } /* Normal */
code span.al { color: #ff0000; } /* Alert */
code span.an { } /* Annotation */
code span.at { } /* Attribute */
code span.bn { color: #9f6807; } /* BaseN */
code span.bu { color: #9f6807; } /* BuiltIn */
code span.cf { color: #00607c; } /* ControlFlow */
code span.ch { color: #9f6807; } /* Char */
code span.cn { } /* Constant */
code span.co { color: #008000; font-style: italic; } /* Comment */
code span.cv { color: #008000; font-style: italic; } /* CommentVar */
code span.do { color: #008000; } /* Documentation */
code span.dt { color: #00607c; } /* DataType */
code span.dv { color: #9f6807; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #9f6807; } /* Float */
code span.fu { } /* Function */
code span.im { } /* Import */
code span.in { color: #008000; } /* Information */
code span.kw { color: #00607c; } /* Keyword */
code span.op { color: #af1915; } /* Operator */
code span.ot { } /* Other */
code span.pp { color: #6f4e37; } /* Preprocessor */
code span.re { } /* RegionMarker */
code span.sc { color: #9f6807; } /* SpecialChar */
code span.ss { color: #9f6807; } /* SpecialString */
code span.st { color: #9f6807; } /* String */
code span.va { } /* Variable */
code span.vs { color: #9f6807; } /* VerbatimString */
code span.wa { color: #008000; font-weight: bold; } /* Warning */ code.diff {
            color: #898887
        }
        
        code.diff span.va {
            color: #006e28
        }
        
        code.diff span.st {
            color: #bf0303
        }
    </style>
         <style type="text/css">
body {
margin: 5em;
font-family: serif;

hyphens: auto;
line-height: 1.35;
}
div.wrapper {
max-width: 60em;
margin: auto;
}
ul {
list-style-type: none;
padding-left: 2em;
margin-top: -0.2em;
margin-bottom: -0.2em;
}
a {
text-decoration: none;
color: #4183C4;
}
a.hidden_link {
text-decoration: none;
color: inherit;
}
li {
margin-top: 0.6em;
margin-bottom: 0.6em;
}
h1,
h2,
h3,
h4 {
position: relative;
line-height: 1;
}
a.self-link {
position: absolute;
top: 0;
left: calc(-1 * (3.5rem - 26px));
width: calc(3.5rem - 26px);
height: 2em;
text-align: center;
border: none;
transition: opacity .2s;
opacity: .5;
font-family: sans-serif;
font-weight: normal;
font-size: 83%;
}
a.self-link:hover {
opacity: 1;
}
a.self-link::before {
content: "§";
}
ul>li:before {
content: "\2014";
position: absolute;
margin-left: -1.5em;
}
:target {
background-color: #C9FBC9;
}
:target .codeblock {
background-color: #C9FBC9;
}
:target ul {
background-color: #C9FBC9;
}
.abbr_ref {
float: right;
}
.folded_abbr_ref {
float: right;
}
:target .folded_abbr_ref {
display: none;
}
:target .unfolded_abbr_ref {
float: right;
display: inherit;
}
.unfolded_abbr_ref {
display: none;
}
.secnum {
display: inline-block;
min-width: 35pt;
}
.header-section-number {
display: inline-block;
min-width: 35pt;
}
.annexnum {
display: block;
}
div.sourceLinkParent {
float: right;
}
a.sourceLink {
position: absolute;
opacity: 0;
margin-left: 10pt;
}
a.sourceLink:hover {
opacity: 1;
}
a.itemDeclLink {
position: absolute;
font-size: 75%;
text-align: right;
width: 5em;
opacity: 0;
}
a.itemDeclLink:hover {
opacity: 1;
}
span.marginalizedparent {
position: relative;
left: -5em;
}
li span.marginalizedparent {
left: -7em;
}
li ul>li span.marginalizedparent {
left: -9em;
}
li ul>li ul>li span.marginalizedparent {
left: -11em;
}
li ul>li ul>li ul>li span.marginalizedparent {
left: -13em;
}
div.footnoteNumberParent {
position: relative;
left: -4.7em;
}
a.marginalized {
position: absolute;
font-size: 75%;
text-align: right;
width: 5em;
}
a.enumerated_item_num {
position: relative;
left: -3.5em;
display: inline-block;
margin-right: -3em;
text-align: right;
width: 3em;
}
div.para {
margin-bottom: 0.6em;
margin-top: 0.6em;
text-align: justify;
}
div.section {
text-align: justify;
}
div.sentence {
display: inline;
}
span.indexparent {
display: inline;
position: relative;
float: right;
right: -1em;
}
a.index {
position: absolute;
display: none;
}
a.index:before {
content: "⟵";
}

a.index:target {
display: inline;
}
.indexitems {
margin-left: 2em;
text-indent: -2em;
}
div.itemdescr {
margin-left: 3em;
}
.bnf {
font-family: serif;
margin-left: 40pt;
margin-top: 0.5em;
margin-bottom: 0.5em;
}
.ncbnf {
font-family: serif;
margin-top: 0.5em;
margin-bottom: 0.5em;
margin-left: 40pt;
}
.ncsimplebnf {
font-family: serif;
font-style: italic;
margin-top: 0.5em;
margin-bottom: 0.5em;
margin-left: 40pt;
background: inherit;

}
span.textnormal {
font-style: normal;
font-family: serif;
white-space: normal;
display: inline-block;
}
span.rlap {
display: inline-block;
width: 0px;
}
span.descr {
font-style: normal;
font-family: serif;
}
span.grammarterm {
font-style: italic;
}
span.term {
font-style: italic;
}
span.terminal {
font-family: monospace;
font-style: normal;
}
span.nonterminal {
font-style: italic;
}
span.tcode {
font-family: monospace;
font-style: normal;
}
span.textbf {
font-weight: bold;
}
span.textsc {
font-variant: small-caps;
}
a.nontermdef {
font-style: italic;
font-family: serif;
}
span.emph {
font-style: italic;
}
span.techterm {
font-style: italic;
}
span.mathit {
font-style: italic;
}
span.mathsf {
font-family: sans-serif;
}
span.mathrm {
font-family: serif;
font-style: normal;
}
span.textrm {
font-family: serif;
}
span.textsl {
font-style: italic;
}
span.mathtt {
font-family: monospace;
font-style: normal;
}
span.mbox {
font-family: serif;
font-style: normal;
}
span.ungap {
display: inline-block;
width: 2pt;
}
span.textit {
font-style: italic;
}
span.texttt {
font-family: monospace;
}
span.tcode_in_codeblock {
font-family: monospace;
font-style: normal;
}
span.phantom {
color: white;
}

span.math {
font-style: normal;
}
span.mathblock {
display: block;
margin-left: auto;
margin-right: auto;
margin-top: 1.2em;
margin-bottom: 1.2em;
text-align: center;
}
span.mathalpha {
font-style: italic;
}
span.synopsis {
font-weight: bold;
margin-top: 0.5em;
display: block;
}
span.definition {
font-weight: bold;
display: block;
}
.codeblock {
margin-left: 1.2em;
line-height: 127%;
}
.outputblock {
margin-left: 1.2em;
line-height: 127%;
}
div.itemdecl {
margin-top: 2ex;
}
code.itemdeclcode {
white-space: pre;
display: block;
}
span.textsuperscript {
vertical-align: super;
font-size: smaller;
line-height: 0;
}
.footnotenum {
vertical-align: super;
font-size: smaller;
line-height: 0;
}
.footnote {
font-size: small;
margin-left: 2em;
margin-right: 2em;
margin-top: 0.6em;
margin-bottom: 0.6em;
}
div.minipage {
display: inline-block;
margin-right: 3em;
}
div.numberedTable {
text-align: center;
margin: 2em;
}
div.figure {
text-align: center;
margin: 2em;
}
table {
border: 1px solid black;
border-collapse: collapse;
margin-left: auto;
margin-right: auto;
margin-top: 0.8em;
text-align: left;
hyphens: none;

}
td,
th {
padding-left: 1em;
padding-right: 1em;
vertical-align: top;
}
td.empty {
padding: 0px;
padding-left: 1px;
}
td.left {
text-align: left;
}
td.right {
text-align: right;
}
td.center {
text-align: center;
}
td.justify {
text-align: justify;
}
td.border {
border-left: 1px solid black;
}
tr.rowsep,
td.cline {
border-top: 1px solid black;
}
tr.even,
tr.odd {
border-bottom: 1px solid black;
}
tr.capsep {
border-top: 3px solid black;
border-top-style: double;
}
tr.header {
border-bottom: 3px solid black;
border-bottom-style: double;
}
th {
border-bottom: 1px solid black;
}
span.centry {
font-weight: bold;
}
div.table {
display: block;
margin-left: auto;
margin-right: auto;
text-align: center;
width: 90%;
}
span.indented {
display: block;
margin-left: 2em;
margin-bottom: 1em;
margin-top: 1em;
}
ol.enumeratea {
list-style-type: none;
background: inherit;
}
ol.enumerate {
list-style-type: none;
background: inherit;
}

code.sourceCode>span {
display: inline;
}

div#refs p {
padding-left: 32px;
text-indent: -32px;
}
pre.sourceCode {
border: 1px solid #444;
padding: 12px;
border-radius: 6px
}
html {
font-size: 100%;
overflow-y: scroll;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%
}
body {
color: #444;
font-family: georgia, palatino, palatino linotype, times, times new roman, serif;
font-size: 12px;
line-height: 1.7;
padding: 1em;
margin: auto;
max-width: 54em;
background: #fefefe
}
a {
color: #0645ad;
text-decoration: none
}
a:visited {
color: #0b0080
}
a:hover {
color: #06e
}
a:active {
color: #faa700
}
a:focus {
outline: thin dotted
}
*::-moz-selection {
background: rgba(255, 255, 0, .3);
color: #000
}
*::selection {
background: rgba(255, 255, 0, .3);
color: #000
}
a::-moz-selection {
background: rgba(255, 255, 0, .3);
color: #0645ad
}
a::selection {
background: rgba(255, 255, 0, .3);
color: #0645ad
}
p {
margin: 1em 0
}
img {
max-width: 100%
}
h1,
h2,
h3,
h4,
h5,
h6 {
color: #111;
line-height: 125%;
margin-top: 2em;
font-weight: 400
}
h4,
h5,
h6 {
font-weight: 700
}
h1 {
font-size: 2.5em
}
h2 {
font-size: 2em
}
h3 {
font-size: 1.5em
}
h4 {
font-size: 1.2em
}
h5 {
font-size: 1em
}
h6 {
font-size: .9em
}
blockquote {
color: #666;
margin: 0;
padding-left: 3em;
border-left: .5em #eee solid
}
hr {
display: block;
height: 2px;
border: 0;
border-top: 1px solid #aaa;
border-bottom: 1px solid #eee;
margin: 1em 0;
padding: 0
}
pre,
code,
kbd,
samp {
color: #000;
font-family: monospace, monospace;
_font-family: 'courier new', monospace;
font-size: .98em
}
pre {
white-space: pre;
white-space: pre-wrap;
word-wrap: break-word
}
b,
strong {
font-weight: 700
}
dfn {
font-style: italic
}
ins {
background: #ff9;
color: #000;
text-decoration: none
}
mark {
background: #ff0;
color: #000;
font-style: italic;
font-weight: 700
}
sub,
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline
}
sup {
top: -.5em
}
sub {
bottom: -.25em
}
ul,
ol {
margin: 1em 0;
padding: 0 0 0 2em
}
li p:last-child {
margin-bottom: 0
}
ul ul,
ol ol {
margin: .3em 0
}
dl {
margin-bottom: 1em
}
dt {
font-weight: 700;
margin-bottom: .8em
}
dd {
margin: 0 0 .8em 2em
}
dd:last-child {
margin-bottom: 0
}
img {
border: 0;
-ms-interpolation-mode: bicubic;
vertical-align: middle
}
figure {
display: block;
text-align: center;
margin: 1em 0
}
figure img {
border: 0;
margin: 0 auto
}
figcaption {
font-size: .8em;
font-style: italic;
margin: 0 0 .8em
}
table {
margin-bottom: 2em;
border-bottom: 1px solid #ddd;
border-right: 1px solid #ddd;
border-spacing: 0;
border-collapse: collapse
}
table th {
padding: .2em 1em;
background-color: #eee;
border-top: 1px solid #ddd;
border-left: 1px solid #ddd
}
table td {
padding: .2em 1em;
border-top: 1px solid #ddd;
border-left: 1px solid #ddd;
vertical-align: top
}
.author {
font-size: 1.2em;
text-align: center
}
@media only screen and (min-width:480px) {
body {
font-size: 14px
}
}
@media only screen and (min-width:768px) {
body {
font-size: 16px
}
}
@media print {
* {
background: transparent!important;
color: #000!important;
filter: none!important;
-ms-filter: none!important
}
body {
font-size: 12pt;
max-width: 100%
}
a,
a:visited {
text-decoration: underline
}
hr {
height: 1px;
border: 0;
border-bottom: 1px solid #000
}
a[href]:after {
content: " (" attr(href) ")"
}
abbr[title]:after {
content: " (" attr(title) ")"
}
.ir a:after,
a[href^="javascript:"]:after,
a[href^="#"]:after {
content: ""
}
pre,
blockquote {
border: 1px solid #999;
padding-right: 1em;
page-break-inside: avoid
}
tr,
img {
page-break-inside: avoid
}
img {
max-width: 100%!important
}
@page: left {
margin: 15mm 20mm 15mm 10mm
}
@page: right {
margin: 15mm 10mm 15mm 20mm
}
p,
h2,
h3 {
orphans: 3;
widows: 3
}
h2,
h3 {
page-break-after: avoid
}
}
@media only screen and (min-width: 1200px) and (max-width: 1680px) {
.sidebar ul {
columns: 2;
font-size: smaller;
}
}
@media only screen and (min-width: 1680px) {
.sidebar {
float: left;
position: fixed;
top: -20px;
left: 0px;
background-color: aliceblue;
line-height: 1.3;
padding-right: 20px;
zoom: 90%;
max-width: 360px;
height: 100%;
overflow-y: scroll;
}
.sidebartitle {
margin-top: 30px;
padding-left: 20px;
margin-bottom: 10px;
color: darkslateblue;
}
.sidebar ul {
columns: 1;
}
}
@media only screen and (min-width: 2000px) {
body {
max-width: 70em;
}
body .wrapper {
max-width: 70em;
}
}</style>     <!-- <link rel="icon" href="https://isocpp.org/favicon.ico" /> -->
    
    <!--[if lt IE 9]>
    <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
  <![endif]-->
      
</head>

<body>
    <div class="wrapper">
                 <header id="title-block-header">
            <h1 class="title" style="text-align:center">Prohibit zero and NULL from being used as null pointer literals</h1>
            
            <table style="float:right">
                <tr>
                    <td>Document #: </td>
                    <td>P2048R0</td>
                </tr>
                <tr>
                    <td>Date: </td>
                    <td>2020-01-12</td>
                </tr>
                <tr>
                    <td style="vertical-align:top">Project: </td>
                    <td>Programming Language C++<br>  Evolution Working Group Incubator (EWGI)
                        <br> 
                    </td>
                </tr>
                                <tr>
                    <td style="vertical-align:top">Reply-to: </td>
                    <td>
                         Vittorio Romeo
                        <br>
                        &lt;<a href="mailto:vittorio.romeo@outlook.com" class="email">vittorio.romeo@outlook.com</a>&gt;<br> 
                    </td>
                </tr>
            </table>

        </header>
                <div style="clear:both">
                        <div id="TOC" role="doc-toc" class="sidebar">
                <h1 id="toctitle" class="sidebartitle">Contents</h1>
                <ul>
                <li><a href="#abstract"><span class="toc-section-number">1</span> Abstract<span></span></a></li>
                <li><a href="#revision-history"><span class="toc-section-number">2</span> Revision History<span></span></a></li>
                <li><a href="#motivation"><span class="toc-section-number">3</span> Motivation<span></span></a>
                <ul>
                <li><a href="#zero-integer-literal"><span class="toc-section-number">3.1</span> Zero integer literal<span></span></a></li>
                <li><a href="#null-macro"><span class="toc-section-number">3.2</span> <code>NULL</code> macro<span></span></a></li>
                </ul></li>
                <li><a href="#example"><span class="toc-section-number">4</span> Example<span></span></a></li>
                <li><a href="#mechanism"><span class="toc-section-number">5</span> Mechanism<span></span></a></li>
                <li><a href="#wording"><span class="toc-section-number">6</span> Wording<span></span></a></li>
                <li><a href="#acknowledgments"><span class="toc-section-number">7</span> Acknowledgments<span></span></a></li>
                <li><a href="#references"><span class="toc-section-number">8</span> References<span></span></a></li>
                </ul>
            </div>
             <style>
.inline-link
{
    font-size: small;
    margin-top: -2.8em;
    margin-right: 4px;
    text-align: right;
    font-weight: bold;
}

code
{
    font-family: "Fira Code", monospace !important;
    font-size: 0.87em;
}

.sourceCode
{
    font-size: 0.95em;
}

a code
{
    color: #0645ad;
}
</style>
<h1 data-number="1" id="abstract"><span class="header-section-number">1</span> Abstract<a href="#abstract" class="self-link"></a></h1>
<p>This paper proposes removing the <code>NULL</code> macro and prohibiting the use of the integer literal <code>0</code> as a null pointer literal from C++23, limiting the change to epoch 2023.</p>
<h1 data-number="2" id="revision-history"><span class="header-section-number">2</span> Revision History<a href="#revision-history" class="self-link"></a></h1>
<p>None.</p>
<h1 data-number="3" id="motivation"><span class="header-section-number">3</span> Motivation<a href="#motivation" class="self-link"></a></h1>
<p><em>(This paper assumes that the reader is familiar with the concept of epochs and its goals, which are explained in P1881<a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a>. Sections 3, 7, and 8.3 of the epochs paper provide context required to understand this paper.)</em></p>
<p>There currently are multiple ways to represent a <em>null pointer constant</em> in C++: the integer literal <code>0</code>, the standard macro <code>NULL</code>, and the keyword <code>nullptr</code>. While the latter is preferable in every scenario, due to backward compatibility, both <code>0</code> and <code>NULL</code> still exist. They are both suboptimal in terms of functionality, and also needlessly increase the complexity and breadth of the language, often resulting in confusion especially to newcomers.</p>
<p>This paper proposes to make <code>nullptr</code> the only valid way to represent a <em>null pointer constant</em> in C++, leveraging the epochs mechanism discussed in P1881<a href="#fn2" class="footnote-ref" id="fnref2" role="doc-noteref"><sup>2</sup></a> to avoid breaking backward compatibility.</p>
<h2 data-number="3.1" id="zero-integer-literal"><span class="header-section-number">3.1</span> Zero integer literal<a href="#zero-integer-literal" class="self-link"></a></h2>
<p><code>0</code> is a suboptimal way to represent a <em>null pointer constant</em> for multiple reasons. Firstly, it is an integer literal, which is most commonly used to represent the numerical value zero rather than an address. Its duality introduces cognitive overhead to source code readers.</p>
<table>
<thead>
<tr class="header">
<th><div style="text-align:center">
<strong>Before</strong>
</div></th>
<th><div style="text-align:center">
<strong>After</strong>
</div></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><div class="sourceCode" id="cb1"><pre class="sourceCode cpp"><code class="sourceCode cpp"><span id="cb1-1"><a href="#cb1-1"></a></span>
<span id="cb1-2"><a href="#cb1-2"></a><span class="kw">module</span> Example;</span>
<span id="cb1-3"><a href="#cb1-3"></a><span class="kw">import</span> Something;</span>
<span id="cb1-4"><a href="#cb1-4"></a></span>
<span id="cb1-5"><a href="#cb1-5"></a><span class="dt">int</span> main<span class="op">()</span></span>
<span id="cb1-6"><a href="#cb1-6"></a><span class="op">{</span></span>
<span id="cb1-7"><a href="#cb1-7"></a>    something<span class="op">::</span>foo<span class="op">(</span><span class="dv">0</span><span class="op">)</span>;</span>
<span id="cb1-8"><a href="#cb1-8"></a>        <span class="co">// Unclear whether `foo` accepts</span></span>
<span id="cb1-9"><a href="#cb1-9"></a>        <span class="co">// an integer or address.</span></span>
<span id="cb1-10"><a href="#cb1-10"></a></span>
<span id="cb1-11"><a href="#cb1-11"></a>    something<span class="op">::</span>bar<span class="op">(</span><span class="dv">0</span><span class="op">)</span>;</span>
<span id="cb1-12"><a href="#cb1-12"></a>        <span class="co">// Unclear whether `bar` accepts</span></span>
<span id="cb1-13"><a href="#cb1-13"></a>        <span class="co">// an integer or address.</span></span>
<span id="cb1-14"><a href="#cb1-14"></a><span class="op">}</span></span></code></pre></div></td>
<td><div class="sourceCode" id="cb2"><pre class="sourceCode cpp"><code class="sourceCode cpp"><span id="cb2-1"><a href="#cb2-1"></a><span class="kw">epoch</span> <span class="dv">2023</span>;</span>
<span id="cb2-2"><a href="#cb2-2"></a><span class="kw">module</span> Example;</span>
<span id="cb2-3"><a href="#cb2-3"></a><span class="kw">import</span> Something;</span>
<span id="cb2-4"><a href="#cb2-4"></a></span>
<span id="cb2-5"><a href="#cb2-5"></a><span class="dt">int</span> main<span class="op">()</span></span>
<span id="cb2-6"><a href="#cb2-6"></a><span class="op">{</span></span>
<span id="cb2-7"><a href="#cb2-7"></a>    something<span class="op">::</span>foo<span class="op">(</span><span class="dv">0</span><span class="op">)</span>;</span>
<span id="cb2-8"><a href="#cb2-8"></a>        <span class="co">// `foo` clearly accepts an integer.</span></span>
<span id="cb2-9"><a href="#cb2-9"></a></span>
<span id="cb2-10"><a href="#cb2-10"></a>    something<span class="op">::</span>bar<span class="op">(</span><span class="kw">nullptr</span><span class="op">)</span>;</span>
<span id="cb2-11"><a href="#cb2-11"></a>        <span class="co">// `bar` clearly accepts an address.</span></span>
<span id="cb2-12"><a href="#cb2-12"></a><span class="op">}</span></span></code></pre></div></td>
</tr>
</tbody>
</table>
<p>Another problem lies in overload resolution. Overloading a function accepting <code>int*</code> with one accepting <code>int</code> might silently change the meaning of existing code:</p>
<table>
<thead>
<tr class="header">
<th><div style="text-align:center">
<strong>Before</strong>
</div></th>
<th><div style="text-align:center">
<strong>After</strong>
</div></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><div class="sourceCode" id="cb3"><pre class="sourceCode cpp"><code class="sourceCode cpp"><span id="cb3-1"><a href="#cb3-1"></a><span class="dt">void</span> foo<span class="op">(</span><span class="dt">int</span><span class="op">*)</span>;   <span class="co">// (0)</span></span>
<span id="cb3-2"><a href="#cb3-2"></a><span class="co">/* void foo(int); // (1) */</span></span>
<span id="cb3-3"><a href="#cb3-3"></a></span>
<span id="cb3-4"><a href="#cb3-4"></a><span class="dt">int</span> main<span class="op">()</span></span>
<span id="cb3-5"><a href="#cb3-5"></a><span class="op">{</span></span>
<span id="cb3-6"><a href="#cb3-6"></a>    foo<span class="op">(</span><span class="dv">0</span><span class="op">)</span>; <span class="co">// Calls (0).</span></span>
<span id="cb3-7"><a href="#cb3-7"></a><span class="op">}</span></span></code></pre></div></td>
<td><div class="sourceCode" id="cb4"><pre class="sourceCode cpp"><code class="sourceCode cpp"><span id="cb4-1"><a href="#cb4-1"></a><span class="dt">void</span> foo<span class="op">(</span><span class="dt">int</span><span class="op">*)</span>;   <span class="co">// (0)</span></span>
<span id="cb4-2"><a href="#cb4-2"></a><span class="dt">void</span> foo<span class="op">(</span><span class="dt">int</span><span class="op">)</span>;    <span class="co">// (1)</span></span>
<span id="cb4-3"><a href="#cb4-3"></a></span>
<span id="cb4-4"><a href="#cb4-4"></a><span class="dt">int</span> main<span class="op">()</span></span>
<span id="cb4-5"><a href="#cb4-5"></a><span class="op">{</span></span>
<span id="cb4-6"><a href="#cb4-6"></a>    foo<span class="op">(</span><span class="dv">0</span><span class="op">)</span>; <span class="co">// Calls (1).</span></span>
<span id="cb4-7"><a href="#cb4-7"></a><span class="op">}</span></span></code></pre></div></td>
</tr>
</tbody>
</table>
<p>Under <code>epoch 2023</code>, surprising behavior and bugs would be prevented:</p>
<table>
<thead>
<tr class="header">
<th><div style="text-align:center">
<strong>Before</strong>
</div></th>
<th><div style="text-align:center">
<strong>After</strong>
</div></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><div class="sourceCode" id="cb5"><pre class="sourceCode cpp"><code class="sourceCode cpp"><span id="cb5-1"><a href="#cb5-1"></a></span>
<span id="cb5-2"><a href="#cb5-2"></a><span class="kw">module</span> Example;</span>
<span id="cb5-3"><a href="#cb5-3"></a></span>
<span id="cb5-4"><a href="#cb5-4"></a><span class="dt">void</span> foo<span class="op">(</span><span class="dt">int</span><span class="op">*)</span>;</span>
<span id="cb5-5"><a href="#cb5-5"></a></span>
<span id="cb5-6"><a href="#cb5-6"></a><span class="dt">int</span> main<span class="op">()</span></span>
<span id="cb5-7"><a href="#cb5-7"></a><span class="op">{</span></span>
<span id="cb5-8"><a href="#cb5-8"></a>    foo<span class="op">(</span><span class="dv">0</span><span class="op">)</span>; <span class="co">// OK.</span></span>
<span id="cb5-9"><a href="#cb5-9"></a><span class="op">}</span></span></code></pre></div></td>
<td><div class="sourceCode" id="cb6"><pre class="sourceCode cpp"><code class="sourceCode cpp"><span id="cb6-1"><a href="#cb6-1"></a><span class="kw">epoch</span> <span class="dv">2023</span>;</span>
<span id="cb6-2"><a href="#cb6-2"></a><span class="kw">module</span> Example;</span>
<span id="cb6-3"><a href="#cb6-3"></a></span>
<span id="cb6-4"><a href="#cb6-4"></a><span class="dt">void</span> foo<span class="op">(</span><span class="dt">int</span><span class="op">*)</span>;</span>
<span id="cb6-5"><a href="#cb6-5"></a></span>
<span id="cb6-6"><a href="#cb6-6"></a><span class="dt">int</span> main<span class="op">()</span></span>
<span id="cb6-7"><a href="#cb6-7"></a><span class="op">{</span></span>
<span id="cb6-8"><a href="#cb6-8"></a>    foo<span class="op">(</span><span class="dv">0</span><span class="op">)</span>; <span class="co">// Compile-time error.</span></span>
<span id="cb6-9"><a href="#cb6-9"></a><span class="op">}</span></span></code></pre></div></td>
</tr>
</tbody>
</table>
<h2 data-number="3.2" id="null-macro"><span class="header-section-number">3.2</span> <code>NULL</code> macro<a href="#null-macro" class="self-link"></a></h2>
<p>The <code>NULL</code> macro is defined in the C++20 standard as <em>“an implementation-defined null pointer constant”</em><a href="#fn3" class="footnote-ref" id="fnref3" role="doc-noteref"><sup>3</sup></a>. This gives implementations the freedom to implement <code>NULL</code> as any zero integral literal (e.g. <code>0</code>, <code>0L</code>) or as <code>nullptr</code>. Similarly to the overload resolution situation described above, this definition can cause problem when new overloads are added to an existing overload set.</p>
<p>Imagine adding a function accepting either <code>std::nullptr_t</code>, <code>long</code>, <code>int</code>, or <code>int*</code> to an existing overload set that is being invoked with <code>NULL</code>: the behavior is now hard to predict and may vary depending on the standard library implementation being used.</p>
<h1 data-number="4" id="example"><span class="header-section-number">4</span> Example<a href="#example" class="self-link"></a></h1>
<p>Modern code should use <code>nullptr</code> instead of <code>0</code> or <code>NULL</code> to maximize readability and prevent suprising overload resolution outcomes between pointer and integral types. <code>epoch 2023</code> forbids the use of the integer literal <code>0</code> in a context where a pointer is required, and the use of <code>NULL</code> altogether:</p>
<table>
<thead>
<tr class="header">
<th><div style="text-align:center">
<strong>Before</strong>
</div></th>
<th><div style="text-align:center">
<strong>After</strong>
</div></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><div class="sourceCode" id="cb7"><pre class="sourceCode cpp"><code class="sourceCode cpp"><span id="cb7-1"><a href="#cb7-1"></a></span>
<span id="cb7-2"><a href="#cb7-2"></a><span class="kw">module</span> Example;</span>
<span id="cb7-3"><a href="#cb7-3"></a></span>
<span id="cb7-4"><a href="#cb7-4"></a><span class="dt">void</span> foo<span class="op">(</span><span class="dt">long</span><span class="op">)</span>; <span class="co">// (0)</span></span>
<span id="cb7-5"><a href="#cb7-5"></a><span class="dt">void</span> foo<span class="op">(</span><span class="dt">int</span><span class="op">*)</span>; <span class="co">// (1)</span></span>
<span id="cb7-6"><a href="#cb7-6"></a></span>
<span id="cb7-7"><a href="#cb7-7"></a><span class="dt">int</span> main<span class="op">()</span></span>
<span id="cb7-8"><a href="#cb7-8"></a><span class="op">{</span></span>
<span id="cb7-9"><a href="#cb7-9"></a>    <span class="dt">int</span><span class="op">*</span> p0 <span class="op">=</span> <span class="dv">0</span>;       <span class="co">// OK</span></span>
<span id="cb7-10"><a href="#cb7-10"></a>    <span class="dt">int</span><span class="op">*</span> p1 <span class="op">=</span> NULL;    <span class="co">// OK</span></span>
<span id="cb7-11"><a href="#cb7-11"></a>    <span class="dt">int</span><span class="op">*</span> p2 <span class="op">=</span> <span class="kw">nullptr</span>; <span class="co">// OK</span></span>
<span id="cb7-12"><a href="#cb7-12"></a></span>
<span id="cb7-13"><a href="#cb7-13"></a>    foo<span class="op">(</span><span class="dv">0</span><span class="op">)</span>;       <span class="co">// Ambiguous?</span></span>
<span id="cb7-14"><a href="#cb7-14"></a>    foo<span class="op">(</span>NULL<span class="op">)</span>;    <span class="co">// Ambiguous?</span></span>
<span id="cb7-15"><a href="#cb7-15"></a>    foo<span class="op">(</span><span class="kw">nullptr</span><span class="op">)</span>; <span class="co">// Calls (1)</span></span>
<span id="cb7-16"><a href="#cb7-16"></a><span class="op">}</span></span></code></pre></div></td>
<td><div class="sourceCode" id="cb8"><pre class="sourceCode cpp"><code class="sourceCode cpp"><span id="cb8-1"><a href="#cb8-1"></a><span class="kw">epoch</span> <span class="dv">2023</span>;</span>
<span id="cb8-2"><a href="#cb8-2"></a><span class="kw">module</span> Example;</span>
<span id="cb8-3"><a href="#cb8-3"></a></span>
<span id="cb8-4"><a href="#cb8-4"></a><span class="dt">void</span> foo<span class="op">(</span><span class="dt">long</span><span class="op">)</span>; <span class="co">// (0)</span></span>
<span id="cb8-5"><a href="#cb8-5"></a><span class="dt">void</span> foo<span class="op">(</span><span class="dt">int</span><span class="op">*)</span>; <span class="co">// (1)</span></span>
<span id="cb8-6"><a href="#cb8-6"></a></span>
<span id="cb8-7"><a href="#cb8-7"></a><span class="dt">int</span> main<span class="op">()</span></span>
<span id="cb8-8"><a href="#cb8-8"></a><span class="op">{</span></span>
<span id="cb8-9"><a href="#cb8-9"></a>    <del>int* p0 = 0;</del>       <span class="co">// Compilation error</span></span>
<span id="cb8-10"><a href="#cb8-10"></a>    <del>int* p1 = NULL;</del>    <span class="co">// Compilation error</span></span>
<span id="cb8-11"><a href="#cb8-11"></a>    <span class="dt">int</span><span class="op">*</span> p2 <span class="op">=</span> <span class="kw">nullptr</span>; <span class="co">// OK</span></span>
<span id="cb8-12"><a href="#cb8-12"></a></span>
<span id="cb8-13"><a href="#cb8-13"></a>    foo<span class="op">(</span><span class="dv">0</span><span class="op">)</span>;       <span class="co">// Calls (0)</span></span>
<span id="cb8-14"><a href="#cb8-14"></a>    <del>foo(NULL);</del>    <span class="co">// Compilation error</span></span>
<span id="cb8-15"><a href="#cb8-15"></a>    foo<span class="op">(</span><span class="kw">nullptr</span><span class="op">)</span>; <span class="co">// Calls (1)</span></span>
<span id="cb8-16"><a href="#cb8-16"></a><span class="op">}</span></span></code></pre></div></td>
</tr>
</tbody>
</table>
<h1 data-number="5" id="mechanism"><span class="header-section-number">5</span> Mechanism<a href="#mechanism" class="self-link"></a></h1>
<p>In layman’s terms, this is what the compiler would do in a module unit targeting <code>epoch 2023</code>:</p>
<ul>
<li><p>Any use of the standard <code>NULL</code> macro would be ill-formed. Ideally, the error would explain that <code>NULL</code> is a relic of the past and that <code>nullptr</code> should be used instead.</p></li>
<li><p>Any use of the integer literal <code>0</code> (or similar, such as <code>0L</code>) in a context where a pointer type is required would be ill-formed.</p>
<ul>
<li>During overload resolution, <code>0</code> will find overloads accepting integral types as suitable, but will never select any overload accepting a pointer type.</li>
</ul></li>
</ul>
<h1 data-number="6" id="wording"><span class="header-section-number">6</span> Wording<a href="#wording" class="self-link"></a></h1>
<p>Will be provided if the paper is positively received. Minor changes are required in <code>[support.types.nullptr]</code> and <code>[conv.ptr]</code>.</p>
<h1 data-number="7" id="acknowledgments"><span class="header-section-number">7</span> Acknowledgments<a href="#acknowledgments" class="self-link"></a></h1>
<p>None.</p>
<h1 data-number="8" id="references"><span class="header-section-number">8</span> References<a href="#references" class="self-link"></a></h1>
<p><small></p>
<p></small></p>
<section class="footnotes" role="doc-endnotes">
<hr />
<ol>
<li id="fn1" role="doc-endnote"><p><a href="https://wg21.link/P1881" class="uri">https://wg21.link/P1881</a><a href="#fnref1" class="footnote-back" role="doc-backlink">↩︎</a></p></li>
<li id="fn2" role="doc-endnote"><p><a href="https://wg21.link/P1881" class="uri">https://wg21.link/P1881</a><a href="#fnref2" class="footnote-back" role="doc-backlink">↩︎</a></p></li>
<li id="fn3" role="doc-endnote"><p><a href="http://eel.is/c++draft/support.types.nullptr" class="uri">http://eel.is/c++draft/support.types.nullptr</a><a href="#fnref3" class="footnote-back" role="doc-backlink">↩︎</a></p></li>
</ol>
</section> 
        </div>
    </div>
</body>

</html>