220 40128 <fa8b3288-c9f8-4f40-b219-1d1e0bb21b2f@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: julien@nanolive.ch
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: override on free-standing functions (compiler error
 instead of linker error)
Date: Wed, 12 Sep 2018 01:50:49 -0700 (PDT)
Lines: 229
Approved: news@gmane.org
Message-ID: <fa8b3288-c9f8-4f40-b219-1d1e0bb21b2f@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_1957_2078064836.1536742249522"
X-Trace: blaine.gmane.org 1536742127 14335 195.159.176.226 (12 Sep 2018 08:48:47 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 12 Sep 2018 08:48:47 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCXOT6NURMLRB2VG4POAKGQESLXN3BQ@isocpp.org Wed Sep 12 10:48:43 2018
Return-path: <std-proposals+bncBCXOT6NURMLRB2VG4POAKGQESLXN3BQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yb1-f197.google.com ([209.85.219.197])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCXOT6NURMLRB2VG4POAKGQESLXN3BQ@isocpp.org>)
	id 1g00pE-0003XR-ND
	for gclcip-std-proposals@m.gmane.org; Wed, 12 Sep 2018 10:48:40 +0200
Original-Received: by mail-yb1-f197.google.com with SMTP id 189-v6sf1047531ybz.11
        for <gclcip-std-proposals@m.gmane.org>; Wed, 12 Sep 2018 01:50:51 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:message-id:subject:mime-version:x-original-sender
         :reply-to:precedence:mailing-list:list-id:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=QCVPNPJnXD12WX5HEnb0sQMVDqnY7d7BNGJeT/VMfxs=;
        b=HC1/CSwn3v/ZeJ/mzRiNT+5pYfeZUJ2m51hETg58kz9B2yTcxRI5VeWy1cLSw4pJzf
         +9h3KbLwgKGwgAG7/9vpPit1qAkb5m3PIv0XLvmivD7cQNwsG9sENxiyJKSOmpEbUgqp
         GNiDZMtyjK7Qxy0FTCAaQgn/mUklKscCGIXzP4jo1Q12qk7kyV1a12mgRIIaC/fyyAUf
         bCzTfOaLgIn5dhrgSis16CmSkrdUzPBM/tmeOCH+64VhezDHTW3q9ao8pLgv6pcHFakd
         EjCG6+/pjqG2/hvZhhw6v9quAjyC1YVX2/72u+w5Nzii1Y1ANL6UXJPGyletDr1jwhcp
         XU5g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:message-id:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=QCVPNPJnXD12WX5HEnb0sQMVDqnY7d7BNGJeT/VMfxs=;
        b=LOpAJDuDV85u8kVWZUAHJHX0+dPrWwTxYAD4RWPHFSeGA9jbNa1a6o+uj7Kx0WeOOx
         nmNgP1owVCxLFNGN5SQpEDyhxaksIdvZK1WGP1T9asvNIeTKK9zqM9Qww5sKSgP8F/Lj
         l4tSPT2D17RdorwpB1+CKdgtjnEV3Kbj4Jxo/xhh8QW/IaiYVRZFVra/FH+SZZ+zbE/G
         hDFk+IgwiAWV08ApJSIL78tilM09WoJggZY2tr3evKrMh68rp8HxpJuTRuJknS8cFDyi
         sbeYFLSnSNN9ElYx0wn+G/ZwRXiGiee2C9+X298gaZ61Phs2jzAjdNbHIJ8Gxe3dBOW0
         43eA==
X-Gm-Message-State: APzg51Cs+XTh1ONP5eGAvpu82XmEt2BrF9VbjSX2efCJ8HfBGog5tDr4
	W9brjJtUwO2sDLDWbJbOZ+e0bw==
X-Google-Smtp-Source: ANB0VdbNVhMhO+2D7ycx22AIDGq7GI6JyhyGCNAzufvHkKKRSEGRW0Byke1C8W/O0cv77FWLjfAMgw==
X-Received: by 2002:a0d:da41:: with SMTP id c62-v6mr72183ywe.98.1536742251062;
        Wed, 12 Sep 2018 01:50:51 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 2002:a0d:e8d1:: with SMTP id r200-v6ls95488ywe.36.gmail; Wed, 12
 Sep 2018 01:50:50 -0700 (PDT)
X-Received: by 2002:a81:308e:: with SMTP id w136-v6mr10956yww.0.1536742250177;
        Wed, 12 Sep 2018 01:50:50 -0700 (PDT)
X-Original-Sender: julien@nanolive.ch
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:40128
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/40128>

------=_Part_1957_2078064836.1536742249522
Content-Type: multipart/alternative; 
	boundary="----=_Part_1958_584045642.1536742249522"

------=_Part_1958_584045642.1536742249522
Content-Type: text/plain; charset="UTF-8"

Hi,

From time to time in I have to declare a free-standing function in a header 
file and implement it in the corresponding cpp file. Very basic stuff. What 
always bothers me though is that when I have a discrepancy in the 
signatures (ex. I update the header and forget to update the 
implementation) I'm only aware of the problem at linker time. Then it 
becomes a hunt to find out why things are not working though it compiles 
fine.

In such cases I'm always tempted to create a static member function to get 
a compilation error instead. But that feels like more overhead than 
necessary.

My idea would be to allow the keyword "override" in the implementation to 
make the compiler aware the function must have been pre-declared. Otherwise 
a compilation error is generated which makes it much easier to find the 
problem than a linker error. *Note: I chose "override" as it's an existing 
keyword that seems semantically closest to what I propose, but maybe there 
is a better one.*

What do you think of it?

Example code:

// foo.h

void bar(int&);

struct Foo {
    static void bar(int&);
};

// foo.cpp
#include "foo.h"

// Current - Compiler error: overloaded member function not found
void Foo::bar(int a) { /*...*/ }

// Current - Linker error: unresolved external symbol bar(int&)
void bar(int a) { /*...*/ }

// Proposal - Compiler error: cannot find function pre-declaration.
// Including foo.h may be necessary for this to work (?); but most of the 
time it would be done anyway.
void bar(int a) override { /*...*/ }

// main.cpp
#include "foo.h"

int main(int argc, char* argv[])
{
    bar(3);
    Foo::bar(3);
}

-- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/fa8b3288-c9f8-4f40-b219-1d1e0bb21b2f%40isocpp.org.

------=_Part_1958_584045642.1536742249522
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hi,<br></div><div><br></div><div>From time to time in=
 I have to declare a free-standing function in a header file and implement =
it in the corresponding cpp file. Very basic stuff. What always bothers me =
though is that when I have a discrepancy in the signatures (ex. I update th=
e header and forget to update the implementation) I&#39;m only aware of the=
 problem at linker time. Then it becomes a hunt to find out why things are =
not working though it compiles fine.</div><div><br></div><div>In such cases=
 I&#39;m always tempted to create a static member function to get a compila=
tion error instead. But that feels like more overhead than necessary.</div>=
<div><br></div><div>My idea would be to allow the keyword &quot;override&qu=
ot; in the implementation to make the compiler aware the function must have=
 been pre-declared. Otherwise a compilation error is generated which makes =
it much easier to find the problem than a linker error. <i>Note: I chose &q=
uot;override&quot; as it&#39;s an existing keyword that seems semantically =
closest to what I propose, but maybe there is a better one.</i></div><div><=
br></div><div>What do you think of it?</div><div><br></div><div>Example cod=
e:<br></div><div><br></div><div class=3D"prettyprint" style=3D"background-c=
olor: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: s=
olid; border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint=
"><div class=3D"subprettyprint"><span style=3D"color: #800;" class=3D"style=
d-by-prettify">// foo.h</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">void</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> bar</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(=
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;);</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #606;" class=3D"styled-by-prettify">Foo</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">static</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">void</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> bar</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(=
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;);</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">};</span></div></code></di=
v><div><br></div><div class=3D"prettyprint" style=3D"background-color: rgb(=
250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; bord=
er-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div cla=
ss=3D"subprettyprint"><span style=3D"color: #800;" class=3D"styled-by-prett=
ify">// foo.cpp</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br></span><span style=3D"color: #800;" class=3D"styled-by-prettify">#=
include</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #080;" class=3D"styled-by-prettify">&quot;foo.h&=
quot;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><=
br></span><span style=3D"color: #800;" class=3D"styled-by-prettify">// Curr=
ent - Compiler error: overloaded member function not found</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">void</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" cl=
ass=3D"styled-by-prettify">Foo</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">bar</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">int<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> a</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #800;" class=3D"=
styled-by-prettify">/*...*/</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br><br></span><span style=3D"color: #800;" class=3D"styled-by-prettify">// =
Current - Linker error: unresolved external symbol bar(int&amp;)</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">void</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> bar</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">int</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> a</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #800;" class=3D"styled-by-prettify">/*...*/</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #800;" c=
lass=3D"styled-by-prettify">// Proposal - Compiler error: cannot find funct=
ion pre-declaration.</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br></span><span style=3D"color: #800;" class=3D"styled-by-pretti=
fy">// Including foo.h may be necessary for this to work (?); but most of t=
he time it would be done anyway.</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">void</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> bar</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">int=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> a</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">override</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #800;" class=3D"styled-by-=
prettify">/*...*/</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}<=
/span></div></code></div><div><br></div><div class=3D"prettyprint" style=3D=
"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); bo=
rder-style: solid; border-width: 1px; word-wrap: break-word;"><code class=
=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #800;"=
 class=3D"styled-by-prettify">// main.cpp</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br></span><span style=3D"color: #800;" clas=
s=3D"styled-by-prettify">#include</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #080;" class=3D"style=
d-by-prettify">&quot;foo.h&quot;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">int</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> main</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">(</span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">int</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> arg=
c</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">char</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">*</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> argv</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">[])</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br>=C2=A0 =C2=A0 bar</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">(</span><span style=3D"color: #066;" class=3D"styled-by-pr=
ettify">3</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=
=A0 =C2=A0 </span><span style=3D"color: #606;" class=3D"styled-by-prettify"=
>Foo</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">bar</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #066;" class=3D"styled-by-prettify">3</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br></span></div></code></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/fa8b3288-c9f8-4f40-b219-1d1e0bb21b2f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/fa8b3288-c9f8-4f40-b219-1d1e0bb21b2f=
%40isocpp.org</a>.<br />

------=_Part_1958_584045642.1536742249522--

------=_Part_1957_2078064836.1536742249522--

.
