Topic: Always defer evaluation of static_assert to template


Author: Bengt Gustafsson <bengt.gustafsson@beamways.com>
Date: Thu, 18 Oct 2018 18:16:57 -0700 (PDT)
Raw View
------=_Part_3398_293515587.1539911817113
Content-Type: multipart/alternative;
 boundary="----=_Part_3399_1004359765.1539911817113"

------=_Part_3399_1004359765.1539911817113
Content-Type: text/plain; charset="UTF-8"

It seems a recurring pattern that you try to use static_assert(false); in
template code to indicate that a template should not be instantiated, but
this currently does not work as the assert fires before the template is
ever instantiated. A work around I have seen is:

        // Delay evaluation of the assert by making it dependent on a template parameter

This line has a comment.Add a comment on this line.

33
+

        static_assert(sizeof(ExprT) == -1, "Conversion between these types is not supported");


It seems to me that it would be a reasonable change to not let a static_assert(false) fire in template code unless the template is actually instantiated.


Are there any show-stoppers preventing such a change?

--
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/1bc49018-90f2-47e4-ad3b-ed657c39d8cc%40isocpp.org.

------=_Part_3399_1004359765.1539911817113
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">It seems a recurring pattern that you try to use static_as=
sert(false); in template code to indicate that a template should not be ins=
tantiated, but this currently does not work as the assert fires before the =
template is ever instantiated. A work around I have seen is:<div><br></div>=
<div><div class=3D"added modified line" style=3D"background-color: rgb(235,=
 242, 249); font-size: 12px; border-top-color: rgb(221, 255, 221);"><pre cl=
ass=3D" CodeMirror-line " role=3D"presentation" style=3D"padding-right: 4px=
; padding-left: 4px; border-radius: 0px; background: transparent; font-size=
: inherit; overflow-wrap: normal; line-height: inherit; color: inherit; z-i=
ndex: 2; position: relative; overflow: visible; -webkit-tap-highlight-color=
: transparent; font-variant-ligatures: contextual;"><span role=3D"presentat=
ion" style=3D"padding-right: 0.1px;">        <span class=3D" ediff-add" sty=
le=3D"background-color: rgb(151, 242, 149);">// Delay evaluation of the </s=
pan>assert<span class=3D" ediff-add" style=3D"background-color: rgb(151, 24=
2, 149);"> by making it dependent on a template parameter</span></span></pr=
e></div><div class=3D"added modified line commented" style=3D"font-size: 12=
px; border-top-color: rgb(221, 255, 221);"><div class=3D"CodeMirror-gutter-=
wrapper" style=3D"background: none !important; position: absolute; z-index:=
 4; top: 0px; color: rgb(0, 0, 0); font-family: Arial, sans-serif; white-sp=
ace: nowrap; left: -121px; border-width: initial !important; border-style: =
none !important;"><div class=3D"CodeMirror-gutter-elt" style=3D"position: a=
bsolute; cursor: default; z-index: 4; left: 0px; width: 26px;"><button clas=
s=3D"add-comment-trigger bitbucket-gutter-marker" title=3D"Add a comment on=
 this line." style=3D"box-sizing: content-box; user-select: none; width: 16=
px; height: 17px; padding: 0px 5px; border-width: 0px; border-style: initia=
l; border-top-color: rgb(221, 255, 221); border-right-color: initial; borde=
r-bottom-color: initial; border-left-color: initial; border-radius: 0px; ma=
rgin: 0px; cursor: pointer; line-height: 17px; position: relative; vertical=
-align: top; background-color: rgb(221, 255, 221);"><span class=3D"aui-icon=
 aui-icon-small aui-iconfont-comment" style=3D"background-repeat: no-repeat=
; background-position: 0px 0px; border-width: initial; border-style: none; =
display: inline-block; height: 16px; text-align: left; text-indent: -999em;=
 vertical-align: text-top; width: 16px; line-height: 0; position: absolute;=
 transition: opacity 0.1s ease-in-out 0s; opacity: 0; color: rgb(112, 112, =
112); top: 2px; left: 5px;">This line has a comment.</span><span class=3D"a=
ui-icon aui-icon-small aui-iconfont-add-comment" style=3D"background-repeat=
: no-repeat; background-position: 0px 0px; border-width: initial; border-st=
yle: none; display: inline-block; height: 16px; text-align: left; text-inde=
nt: -999em; vertical-align: text-top; width: 16px; line-height: 0; position=
: absolute; transition: opacity 0.1s ease-in-out 0s; opacity: 0; color: rgb=
(112, 112, 112); top: 2px; left: 5px;">Add a comment on this line.</span></=
button></div><div class=3D"CodeMirror-gutter-elt" style=3D"position: absolu=
te; cursor: default; z-index: 4; left: 26px; width: 37px;"><div class=3D"li=
ne-number line-number-from bitbucket-gutter-marker" style=3D"user-select: n=
one; height: 17px; font-family: monospace; z-index: 2; color: rgb(51, 51, 5=
1); width: 37px; display: inline-block; text-align: right; vertical-align: =
top; border-top-color: rgb(221, 255, 221);">=C2=A0</div></div><div class=3D=
"CodeMirror-gutter-elt" style=3D"position: absolute; cursor: default; z-ind=
ex: 4; left: 63px; width: 37px;"><div class=3D"line-number line-number-to b=
itbucket-gutter-marker" style=3D"user-select: none; height: 17px; font-fami=
ly: monospace; z-index: 1; color: rgb(51, 51, 51); width: 37px; display: in=
line-block; text-align: right; vertical-align: top; border-top-color: rgb(2=
21, 255, 221);">33</div></div><div class=3D"CodeMirror-gutter-elt" style=3D=
"position: absolute; cursor: default; z-index: 4; left: 100px; width: 20px;=
"><div class=3D"line-number-marker line-locator bitbucket-gutter-marker" da=
ta-file-type=3D"" data-line-type=3D"ADDED" data-line-number=3D"33" style=3D=
"user-select: none; height: 17px; font-family: monospace; z-index: 1; color=
: rgb(51, 51, 51); width: 20px; text-align: center; display: inline-block; =
vertical-align: top; border-top-color: rgb(221, 255, 221);">+</div></div></=
div><pre class=3D" CodeMirror-line " role=3D"presentation" style=3D"backgro=
und: transparent; padding-right: 4px; padding-left: 4px; border-radius: 0px=
; overflow-wrap: normal; line-height: inherit; color: rgb(0, 0, 0); z-index=
: 2; position: relative; overflow: visible; -webkit-tap-highlight-color: tr=
ansparent; font-variant-ligatures: contextual;"><span role=3D"presentation"=
 style=3D"padding-right: 0.1px;"><span class=3D" ediff-add" style=3D"backgr=
ound-color: rgb(151, 242, 149);">        static_assert</span>(<span class=
=3D" ediff-change" style=3D"background-color: rgb(151, 242, 149);">sizeof(E=
xprT)</span> <span class=3D" ediff-change" style=3D"background-color: rgb(1=
51, 242, 149);">=3D=3D</span> <span class=3D" ediff-add" style=3D"backgroun=
d-color: rgb(151, 242, 149);">-1, </span>&quot;Conversion between these typ=
es is not supported&quot;);</span></pre><pre class=3D" CodeMirror-line " ro=
le=3D"presentation" style=3D"background: transparent; padding-right: 4px; p=
adding-left: 4px; border-radius: 0px; overflow-wrap: normal; line-height: i=
nherit; color: rgb(0, 0, 0); z-index: 2; position: relative; overflow: visi=
ble; -webkit-tap-highlight-color: transparent; font-variant-ligatures: cont=
extual;"><span role=3D"presentation" style=3D"padding-right: 0.1px;"><br></=
span></pre><pre class=3D" CodeMirror-line " role=3D"presentation" style=3D"=
background: transparent; padding-right: 4px; padding-left: 4px; border-radi=
us: 0px; overflow-wrap: normal; line-height: inherit; color: rgb(0, 0, 0); =
z-index: 2; position: relative; overflow: visible; -webkit-tap-highlight-co=
lor: transparent; font-variant-ligatures: contextual;"><span role=3D"presen=
tation" style=3D"padding-right: 0.1px;">It seems to me that it would be a r=
easonable change to not let a static_assert(false) fire in template code un=
less the template is actually instantiated.</span></pre><pre class=3D" Code=
Mirror-line " role=3D"presentation" style=3D"background: transparent; paddi=
ng-right: 4px; padding-left: 4px; border-radius: 0px; overflow-wrap: normal=
; line-height: inherit; color: rgb(0, 0, 0); z-index: 2; position: relative=
; overflow: visible; -webkit-tap-highlight-color: transparent; font-variant=
-ligatures: contextual;"><span role=3D"presentation" style=3D"padding-right=
: 0.1px;"><br></span></pre><pre class=3D" CodeMirror-line " role=3D"present=
ation" style=3D"background: transparent; padding-right: 4px; padding-left: =
4px; border-radius: 0px; overflow-wrap: normal; line-height: inherit; color=
: rgb(0, 0, 0); z-index: 2; position: relative; overflow: visible; -webkit-=
tap-highlight-color: transparent; font-variant-ligatures: contextual;"><spa=
n role=3D"presentation" style=3D"padding-right: 0.1px;">Are there any show-=
stoppers preventing such a change?</span></pre></div></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/1bc49018-90f2-47e4-ad3b-ed657c39d8cc%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/1bc49018-90f2-47e4-ad3b-ed657c39d8cc=
%40isocpp.org</a>.<br />

------=_Part_3399_1004359765.1539911817113--

------=_Part_3398_293515587.1539911817113--

.