Topic: override on free-standing functions (compiler
Author: Nicolas Lesser <blitzrakete@gmail.com>
Date: Wed, 12 Sep 2018 11:16:58 +0200
Raw View
--00000000000012cc9d0575a90e0b
Content-Type: text/plain; charset="UTF-8"
I like the feature, but I don't think 'override' is th right keyword; what
does it override?
Anyways, I don't think we will need such a feature with modules (everything
(decl/def) will go together). But that's only AFAIK, I don't know much
about modules.
On Wed, Sep 12, 2018, 10:50 AM <julien@nanolive.ch> wrote:
> 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
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/fa8b3288-c9f8-4f40-b219-1d1e0bb21b2f%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>
--
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/CALmDwq05_7YSyqN_EAo6dNQSUcyMK9eiM%3DbV8awUT7Okg2aCFg%40mail.gmail.com.
--00000000000012cc9d0575a90e0b
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"auto"><div>I like the feature, but I don't think 'overr=
ide' is th right keyword; what does it override?<div dir=3D"auto"><br><=
/div><div dir=3D"auto">Anyways, I don't think we will need such a featu=
re with modules (everything (decl/def) will go together). But that's on=
ly AFAIK, I don't know much about modules.</div><br><br><div class=3D"g=
mail_quote"><div dir=3D"ltr">On Wed, Sep 12, 2018, 10:50 AM <<a href=3D=
"mailto:julien@nanolive.ch">julien@nanolive.ch</a>> wrote:<br></div><blo=
ckquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #c=
cc solid;padding-left:1ex"><div dir=3D"ltr"><div>Hi,<br></div><div><br></di=
v><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 stu=
ff. 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.</div><div><=
br></div><div>In such cases I'm always tempted to create a static membe=
r function to get a compilation error instead. But that feels like more ove=
rhead than necessary.</div><div><br></div><div>My idea would be to allow th=
e keyword "override" in the implementation to make the compiler a=
ware the function must have been pre-declared. Otherwise a compilation erro=
r is generated which makes it much easier to find the problem than a linker=
error. <i>Note: I chose "override" as it's an existing keywo=
rd 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 code:<br></div><div><br></div><div class=3D"m_-6668=
670067784636660prettyprint" style=3D"background-color:rgb(250,250,250);bord=
er-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:bre=
ak-word"><code class=3D"m_-6668670067784636660prettyprint"><div class=3D"m_=
-6668670067784636660subprettyprint"><span style=3D"color:#800" class=3D"m_-=
6668670067784636660styled-by-prettify">// foo.h</span><span style=3D"color:=
#000" class=3D"m_-6668670067784636660styled-by-prettify"><br><br></span><sp=
an style=3D"color:#008" class=3D"m_-6668670067784636660styled-by-prettify">=
void</span><span style=3D"color:#000" class=3D"m_-6668670067784636660styled=
-by-prettify"> bar</span><span style=3D"color:#660" class=3D"m_-66686700677=
84636660styled-by-prettify">(</span><span style=3D"color:#008" class=3D"m_-=
6668670067784636660styled-by-prettify">int</span><span style=3D"color:#660"=
class=3D"m_-6668670067784636660styled-by-prettify">&);</span><span sty=
le=3D"color:#000" class=3D"m_-6668670067784636660styled-by-prettify"><br><b=
r></span><span style=3D"color:#008" class=3D"m_-6668670067784636660styled-b=
y-prettify">struct</span><span style=3D"color:#000" class=3D"m_-66686700677=
84636660styled-by-prettify"> </span><span style=3D"color:#606" class=3D"m_-=
6668670067784636660styled-by-prettify">Foo</span><span style=3D"color:#000"=
class=3D"m_-6668670067784636660styled-by-prettify"> </span><span style=3D"=
color:#660" class=3D"m_-6668670067784636660styled-by-prettify">{</span><spa=
n style=3D"color:#000" class=3D"m_-6668670067784636660styled-by-prettify"><=
br>=C2=A0 =C2=A0 </span><span style=3D"color:#008" class=3D"m_-666867006778=
4636660styled-by-prettify">static</span><span style=3D"color:#000" class=3D=
"m_-6668670067784636660styled-by-prettify"> </span><span style=3D"color:#00=
8" class=3D"m_-6668670067784636660styled-by-prettify">void</span><span styl=
e=3D"color:#000" class=3D"m_-6668670067784636660styled-by-prettify"> bar</s=
pan><span style=3D"color:#660" class=3D"m_-6668670067784636660styled-by-pre=
ttify">(</span><span style=3D"color:#008" class=3D"m_-6668670067784636660st=
yled-by-prettify">int</span><span style=3D"color:#660" class=3D"m_-66686700=
67784636660styled-by-prettify">&);</span><span style=3D"color:#000" cla=
ss=3D"m_-6668670067784636660styled-by-prettify"><br></span><span style=3D"c=
olor:#660" class=3D"m_-6668670067784636660styled-by-prettify">};</span></di=
v></code></div><div><br></div><div class=3D"m_-6668670067784636660prettypri=
nt" style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187=
);border-style:solid;border-width:1px;word-wrap:break-word"><code class=3D"=
m_-6668670067784636660prettyprint"><div class=3D"m_-6668670067784636660subp=
rettyprint"><span style=3D"color:#800" class=3D"m_-6668670067784636660style=
d-by-prettify">// foo.cpp</span><span style=3D"color:#000" class=3D"m_-6668=
670067784636660styled-by-prettify"><br></span><span style=3D"color:#800" cl=
ass=3D"m_-6668670067784636660styled-by-prettify">#include</span><span style=
=3D"color:#000" class=3D"m_-6668670067784636660styled-by-prettify"> </span>=
<span style=3D"color:#080" class=3D"m_-6668670067784636660styled-by-prettif=
y">"foo.h"</span><span style=3D"color:#000" class=3D"m_-666867006=
7784636660styled-by-prettify"><br><br></span><span style=3D"color:#800" cla=
ss=3D"m_-6668670067784636660styled-by-prettify">// Current - Compiler error=
: overloaded member function not found</span><span style=3D"color:#000" cla=
ss=3D"m_-6668670067784636660styled-by-prettify"><br></span><span style=3D"c=
olor:#008" class=3D"m_-6668670067784636660styled-by-prettify">void</span><s=
pan style=3D"color:#000" class=3D"m_-6668670067784636660styled-by-prettify"=
> </span><span style=3D"color:#606" class=3D"m_-6668670067784636660styled-b=
y-prettify">Foo</span><span style=3D"color:#660" class=3D"m_-66686700677846=
36660styled-by-prettify">::</span><span style=3D"color:#000" class=3D"m_-66=
68670067784636660styled-by-prettify">bar</span><span style=3D"color:#660" c=
lass=3D"m_-6668670067784636660styled-by-prettify">(</span><span style=3D"co=
lor:#008" class=3D"m_-6668670067784636660styled-by-prettify">int</span><spa=
n style=3D"color:#000" class=3D"m_-6668670067784636660styled-by-prettify"> =
a</span><span style=3D"color:#660" class=3D"m_-6668670067784636660styled-by=
-prettify">)</span><span style=3D"color:#000" class=3D"m_-66686700677846366=
60styled-by-prettify"> </span><span style=3D"color:#660" class=3D"m_-666867=
0067784636660styled-by-prettify">{</span><span style=3D"color:#000" class=
=3D"m_-6668670067784636660styled-by-prettify"> </span><span style=3D"color:=
#800" class=3D"m_-6668670067784636660styled-by-prettify">/*...*/</span><spa=
n style=3D"color:#000" class=3D"m_-6668670067784636660styled-by-prettify"> =
</span><span style=3D"color:#660" class=3D"m_-6668670067784636660styled-by-=
prettify">}</span><span style=3D"color:#000" class=3D"m_-666867006778463666=
0styled-by-prettify"><br><br></span><span style=3D"color:#800" class=3D"m_-=
6668670067784636660styled-by-prettify">// Current - Linker error: unresolve=
d external symbol bar(int&)</span><span style=3D"color:#000" class=3D"m=
_-6668670067784636660styled-by-prettify"><br></span><span style=3D"color:#0=
08" class=3D"m_-6668670067784636660styled-by-prettify">void</span><span sty=
le=3D"color:#000" class=3D"m_-6668670067784636660styled-by-prettify"> bar</=
span><span style=3D"color:#660" class=3D"m_-6668670067784636660styled-by-pr=
ettify">(</span><span style=3D"color:#008" class=3D"m_-6668670067784636660s=
tyled-by-prettify">int</span><span style=3D"color:#000" class=3D"m_-6668670=
067784636660styled-by-prettify"> a</span><span style=3D"color:#660" class=
=3D"m_-6668670067784636660styled-by-prettify">)</span><span style=3D"color:=
#000" class=3D"m_-6668670067784636660styled-by-prettify"> </span><span styl=
e=3D"color:#660" class=3D"m_-6668670067784636660styled-by-prettify">{</span=
><span style=3D"color:#000" class=3D"m_-6668670067784636660styled-by-pretti=
fy"> </span><span style=3D"color:#800" class=3D"m_-6668670067784636660style=
d-by-prettify">/*...*/</span><span style=3D"color:#000" class=3D"m_-6668670=
067784636660styled-by-prettify"> </span><span style=3D"color:#660" class=3D=
"m_-6668670067784636660styled-by-prettify">}</span><span style=3D"color:#00=
0" class=3D"m_-6668670067784636660styled-by-prettify"><br><br></span><span =
style=3D"color:#800" class=3D"m_-6668670067784636660styled-by-prettify">// =
Proposal - Compiler error: cannot find function pre-declaration.</span><spa=
n style=3D"color:#000" class=3D"m_-6668670067784636660styled-by-prettify"><=
br></span><span style=3D"color:#800" class=3D"m_-6668670067784636660styled-=
by-prettify">// Including foo.h may be necessary for this to work (?); but =
most of the time it would be done anyway.</span><span style=3D"color:#000" =
class=3D"m_-6668670067784636660styled-by-prettify"><br></span><span style=
=3D"color:#008" class=3D"m_-6668670067784636660styled-by-prettify">void</sp=
an><span style=3D"color:#000" class=3D"m_-6668670067784636660styled-by-pret=
tify"> bar</span><span style=3D"color:#660" class=3D"m_-6668670067784636660=
styled-by-prettify">(</span><span style=3D"color:#008" class=3D"m_-66686700=
67784636660styled-by-prettify">int</span><span style=3D"color:#000" class=
=3D"m_-6668670067784636660styled-by-prettify"> a</span><span style=3D"color=
:#660" class=3D"m_-6668670067784636660styled-by-prettify">)</span><span sty=
le=3D"color:#000" class=3D"m_-6668670067784636660styled-by-prettify"> </spa=
n><span style=3D"color:#008" class=3D"m_-6668670067784636660styled-by-prett=
ify">override</span><span style=3D"color:#000" class=3D"m_-6668670067784636=
660styled-by-prettify"> </span><span style=3D"color:#660" class=3D"m_-66686=
70067784636660styled-by-prettify">{</span><span style=3D"color:#000" class=
=3D"m_-6668670067784636660styled-by-prettify"> </span><span style=3D"color:=
#800" class=3D"m_-6668670067784636660styled-by-prettify">/*...*/</span><spa=
n style=3D"color:#000" class=3D"m_-6668670067784636660styled-by-prettify"> =
</span><span style=3D"color:#660" class=3D"m_-6668670067784636660styled-by-=
prettify">}</span></div></code></div><div><br></div><div class=3D"m_-666867=
0067784636660prettyprint" style=3D"background-color:rgb(250,250,250);border=
-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:break=
-word"><code class=3D"m_-6668670067784636660prettyprint"><div class=3D"m_-6=
668670067784636660subprettyprint"><span style=3D"color:#800" class=3D"m_-66=
68670067784636660styled-by-prettify">// main.cpp</span><span style=3D"color=
:#000" class=3D"m_-6668670067784636660styled-by-prettify"><br></span><span =
style=3D"color:#800" class=3D"m_-6668670067784636660styled-by-prettify">#in=
clude</span><span style=3D"color:#000" class=3D"m_-6668670067784636660style=
d-by-prettify"> </span><span style=3D"color:#080" class=3D"m_-6668670067784=
636660styled-by-prettify">"foo.h"</span><span style=3D"color:#000=
" class=3D"m_-6668670067784636660styled-by-prettify"><br><br></span><span s=
tyle=3D"color:#008" class=3D"m_-6668670067784636660styled-by-prettify">int<=
/span><span style=3D"color:#000" class=3D"m_-6668670067784636660styled-by-p=
rettify"> main</span><span style=3D"color:#660" class=3D"m_-666867006778463=
6660styled-by-prettify">(</span><span style=3D"color:#008" class=3D"m_-6668=
670067784636660styled-by-prettify">int</span><span style=3D"color:#000" cla=
ss=3D"m_-6668670067784636660styled-by-prettify"> argc</span><span style=3D"=
color:#660" class=3D"m_-6668670067784636660styled-by-prettify">,</span><spa=
n style=3D"color:#000" class=3D"m_-6668670067784636660styled-by-prettify"> =
</span><span style=3D"color:#008" class=3D"m_-6668670067784636660styled-by-=
prettify">char</span><span style=3D"color:#660" class=3D"m_-666867006778463=
6660styled-by-prettify">*</span><span style=3D"color:#000" class=3D"m_-6668=
670067784636660styled-by-prettify"> argv</span><span style=3D"color:#660" c=
lass=3D"m_-6668670067784636660styled-by-prettify">[])</span><span style=3D"=
color:#000" class=3D"m_-6668670067784636660styled-by-prettify"><br></span><=
span style=3D"color:#660" class=3D"m_-6668670067784636660styled-by-prettify=
">{</span><span style=3D"color:#000" class=3D"m_-6668670067784636660styled-=
by-prettify"><br>=C2=A0 =C2=A0 bar</span><span style=3D"color:#660" class=
=3D"m_-6668670067784636660styled-by-prettify">(</span><span style=3D"color:=
#066" class=3D"m_-6668670067784636660styled-by-prettify">3</span><span styl=
e=3D"color:#660" class=3D"m_-6668670067784636660styled-by-prettify">);</spa=
n><span style=3D"color:#000" class=3D"m_-6668670067784636660styled-by-prett=
ify"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#606" class=3D"m_-666867=
0067784636660styled-by-prettify">Foo</span><span style=3D"color:#660" class=
=3D"m_-6668670067784636660styled-by-prettify">::</span><span style=3D"color=
:#000" class=3D"m_-6668670067784636660styled-by-prettify">bar</span><span s=
tyle=3D"color:#660" class=3D"m_-6668670067784636660styled-by-prettify">(</s=
pan><span style=3D"color:#066" class=3D"m_-6668670067784636660styled-by-pre=
ttify">3</span><span style=3D"color:#660" class=3D"m_-6668670067784636660st=
yled-by-prettify">);</span><span style=3D"color:#000" class=3D"m_-666867006=
7784636660styled-by-prettify"><br></span><span style=3D"color:#660" class=
=3D"m_-6668670067784636660styled-by-prettify">}</span><span style=3D"color:=
#000" class=3D"m_-6668670067784636660styled-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" 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" target=3D"_=
blank" rel=3D"noreferrer">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank" rel=3D"noreferrer">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" target=3D"_blank" =
rel=3D"noreferrer">https://groups.google.com/a/isocpp.org/d/msgid/std-propo=
sals/fa8b3288-c9f8-4f40-b219-1d1e0bb21b2f%40isocpp.org</a>.<br>
</blockquote></div></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/CALmDwq05_7YSyqN_EAo6dNQSUcyMK9eiM%3D=
bV8awUT7Okg2aCFg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CALmDwq05_7YSyq=
N_EAo6dNQSUcyMK9eiM%3DbV8awUT7Okg2aCFg%40mail.gmail.com</a>.<br />
--00000000000012cc9d0575a90e0b--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 12 Sep 2018 12:54:50 +0300
Raw View
On 12 September 2018 at 12:16, Nicolas Lesser <blitzrakete@gmail.com> wrote:
> I like the feature, but I don't think 'override' is th right keyword; what
> does it override?
>
> Anyways, I don't think we will need such a feature with modules (everything
> (decl/def) will go together). But that's only AFAIK, I don't know much about
> modules.
Modules don't guarantee that you don't run into this problem. Your
point about re-abusing override is valid;
what we need here is a new context-sensitive keyword:
void f() redeclaration // ill-formed if it's the first declaration
{
}
We could do this with an attribute, too, but the idea here is that
there are no false positives and it's a strong semantic
statement, so it makes sense for it to be a keyword. I can live with
an attribute as well, if that makes it more acceptable,
then it's just
void f() [[redeclaration]]
{
}
--
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/CAFk2RUZn5iVpwYW4OCruMr5EFfWqRasudWY9hx7kswBoV%2BASXQ%40mail.gmail.com.
.
Author: =?UTF-8?Q?=27Thomas_K=C3=B6ppe=27_via_ISO_C=2B=2B_Standard_=2D_Future_Proposals?= <std-proposals@isocpp.org>
Date: Wed, 12 Sep 2018 03:21:10 -0700 (PDT)
Raw View
------=_Part_2028_1476902139.1536747670968
Content-Type: multipart/alternative;
boundary="----=_Part_2029_478068000.1536747670969"
------=_Part_2029_478068000.1536747670969
Content-Type: text/plain; charset="UTF-8"
I'm very sympathetic to the problem and the desire for a solution. However,
I'd like to offer a word of caution: core language addition is always
costly -- there's opportunity cost, the fact that we already have *tons* of
keywords that go before and after function declarations, and the fact that
any additional feature here complicates the overall language.
I think this particular problem could be solved much more appropriately by
static analysers. The problem is ultimately about source code layout, which
is fundamentally outside the scope of the language. "Header files" aren't
really a thing in the language, they're just a pragmatic convention. And
even though "first declaration" is a thing, the proposed solution doesn't
cover all aspects of the problem, since e.g. nothing forces you to include
a header! By contrast, a static analyzer is in a much better position to
analyze your source code layout and comment on whether the .cc/.cpp file
includes a "related" .h file, and whether all names that are declared in
the former and have external linkage are also declared again in a header
file. Such an anaylsis would even have a broader benefit of providing a
systematic rule for the use of external-linkage names and let you optimize
your link. (For example, it would catch functions that should be internal
but accidentally have external linkage and never appear in any header.)
--
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/e722eb01-9a1e-4625-ac23-4c945394fceb%40isocpp.org.
------=_Part_2029_478068000.1536747670969
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><font color=3D"#000000">I'm very sympathetic to the pr=
oblem and the desire for a solution. However, I'd like to offer a word =
of caution: core language addition is always costly -- there's opportun=
ity cost, the fact that we already have *tons* of keywords that go before a=
nd after function declarations, and the fact that any additional feature he=
re complicates the overall language.</font><div><font color=3D"#000000"><br=
></font></div><div><font color=3D"#000000">I think this particular problem =
could be solved much more appropriately by static analysers. The problem is=
ultimately about source code layout, which is fundamentally outside the sc=
ope of the language. "Header files" aren't really a thing in =
the language, they're just a pragmatic convention. And even though &quo=
t;first declaration" is a thing, the proposed solution doesn't cov=
er all aspects of the problem, since e.g. nothing forces you to include a h=
eader! By contrast, a static analyzer is in a much better position to analy=
ze your source code layout and comment on whether the .cc/.cpp file include=
s a "related" .h file, and whether all names that are declared in=
the former and have external linkage are also declared again in a header f=
ile. Such an anaylsis would even have a broader benefit of providing a syst=
ematic rule for the use of external-linkage names and let you optimize your=
link. (For example, it would catch functions that should be internal but a=
ccidentally have external linkage and never appear in any header.)</font></=
div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/e722eb01-9a1e-4625-ac23-4c945394fceb%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/e722eb01-9a1e-4625-ac23-4c945394fceb=
%40isocpp.org</a>.<br />
------=_Part_2029_478068000.1536747670969--
------=_Part_2028_1476902139.1536747670968--
.
Author: =?UTF-8?Q?Jonathan_M=c3=bcller?= <jonathanmueller.dev@gmail.com>
Date: Wed, 12 Sep 2018 13:43:55 +0200
Raw View
On 9/12/18 10:50 AM, julien@nanolive.ch wrote:
> 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.
>
Another solution would be to simply put every function into a namespace
(as you should anyway). Then a mismatch will be detected at compile-time.
--
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/d3695ea2-56d0-f622-edd5-06bfd1d736df%40gmail.com.
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 12 Sep 2018 14:54:24 +0300
Raw View
On 12 September 2018 at 14:43, Jonathan M=C3=BCller
<jonathanmueller.dev@gmail.com> wrote:
> On 9/12/18 10:50 AM, julien@nanolive.ch wrote:
>>
>> 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 i=
n
>> 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.
>>
>
> Another solution would be to simply put every function into a namespace (=
as
> you should anyway). Then a mismatch will be detected at compile-time.
That does solve the problem partially, but my non-defining declaration
in a header will be in that namespace, and the
definition in a source file might be in that namespace as well, as
opposed to doing
namespace X {void f();} void X::f(int) {}
In other words, I might quite plausibly write
namespace X {void f();}
namespace X {void f(int) {} }
and I can't qualify the definition inside the namespace. So granted,
this suggestion solves a chunk of the problem, when a specific
code organization style is used.
--=20
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 e=
mail 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/CAFk2RUa5pjy5fN_5RxyRhbmX74hMYBo34Z9Ng5pSXTy8QWq=
WRg%40mail.gmail.com.
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Wed, 12 Sep 2018 08:31:05 -0700
Raw View
On Wednesday, 12 September 2018 01:50:49 PDT julien@nanolive.ch wrote:
> 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.*
Not emitting a comment on your proposal. This is just to tell you that you
have an solution for your particular problem, without having to wait for the
language update:
GCC and Clang already have -Werror=missing-declarations. C library developers
use this often.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
--
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/3636959.tBUVQo0lon%40tjmaciei-mobl1.
.