<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Aug 23, 2020 at 9:40 AM Manu agarwal <<a href="mailto:manu.agarwal@live.in">manu.agarwal@live.in</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">




<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Hi David,</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Thanks for the reply. I missed to mention the environment and what i am trying to do.</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<ol>
<li>Environment is ClangCL (version 10.0), Microsoft Visual Studio.</li></ol>
<div>       2. I assumed that since the 'constexpr if' evaluates to false, the external function's presence would not be checked. So, if my application is not of type 'client' ClientMain would not be called.  My actual code inside the constexpr if is the commented
 line of code that does not compile. To experiment i simply invoked ClientMain directly which compiled fine.</div>
<div><br>
</div>
<div>Here is the assembly generated from the successful compilation (with the first line inside 'constexpr if' enabled).</div>
<div><br>
</div>
<div>"??$<b>MyAppInit</b>@$02@MyAppTemplate@@SQ_NXZ": # @"??$MyAppInit@$02@MyAppTemplate@@SQ_NXZ"
<div>.Lfunc_begin2:</div>
<div>.cv_func_id 2</div>
<div>.cv_loc 2 1 32 0                # Main.cpp:32:0</div>
<div># %bb.0:</div>
<div>.cv_loc 2 1 39 0                # Main.cpp:39:0</div>
<div><b>xor eax, eax</b></div>
<div>                                        # kill: def $al killed $al killed $eax</div>
<div>.Ltmp6:</div>
<div><b>ret</b></div>
<div>.Ltmp7:</div>
.Lfunc_end2:<br>
</div>
<div><br>
</div>
<div>Here is how the compiler is invoked:</div>
<div><br>
</div>
<div><b>E:\LLVM\bin\clang-cl.exe  /c /Z7 /nologo /W3 /WX- /diagnostics:column /Od /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /EHsc /MTd /GS /fp:precise /permissive- /std:c++17 /FA /Fa"x64\Debug\\" /Fo"x64\Debug\\" /Gv /TP -m64  Main.cpp</b></div>
<div><b>1>  Done executing task "CL".</b><br>
</div>
<div><br>
</div>
<div>Is my understanding of 'constexpr if' wrong ? won't the body get discarded in case it gets evaluated to false?</div></div></div></blockquote><div><br>Yeah, that's not quite how constexpr works - I think you may've gained that model partly by the combination of MSVC-compatible lazy-parsed templates and constexpr.<br><br>The spec basically says something /very roughly/ like "dependent things in a non-taken constexpr if branch remain dependent even after template instantiation". But that means code that's invalid no matter what (like "static_assert(false)") still trigger errors. See the latter parts of the constexpr if section here: <a href="https://en.cppreference.com/w/cpp/language/if">https://en.cppreference.com/w/cpp/language/if</a> <br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<div><br>
</div>
<div>Regards,</div>
<div>Manu</div>
<div><br>
</div>
</div>
<div id="gmail-m_8062696499188233681appendonsend"></div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<hr style="display:inline-block;width:98%">
<div id="gmail-m_8062696499188233681divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>><br>
<b>Sent:</b> Saturday, August 22, 2020 2:14 AM<br>
<b>To:</b> Manu agarwal <<a href="mailto:Manu.Agarwal@live.in" target="_blank">Manu.Agarwal@live.in</a>><br>
<b>Cc:</b> <a href="mailto:cfe-users@lists.llvm.org" target="_blank">cfe-users@lists.llvm.org</a> <<a href="mailto:cfe-users@lists.llvm.org" target="_blank">cfe-users@lists.llvm.org</a>><br>
<b>Subject:</b> Re: [cfe-users] inconsistent compilation error inside constexpr if</font>
<div> </div>
</div>
<div><font size="2"><span style="font-size:11pt">
<div>From what I could test on godbolt, using LLVM evrsions back to 5.0,<br>
Clang does reject the "return ClientMain();" call you aren't seeing an<br>
error on. So I'm not sure what compiler/version/situation you're<br>
running, but at least at first blush it doesn't look like clang.<br>
<br>
On Fri, Aug 21, 2020 at 1:29 PM Manu agarwal via cfe-users<br>
<<a href="mailto:cfe-users@lists.llvm.org" target="_blank">cfe-users@lists.llvm.org</a>> wrote:<br>
><br>
> Hello,<br>
><br>
> In the below code the compiler throws "undeclared identifier" when the commented line is uncommented. Whereas the line just before compiles fine.<br>
><br>
> Regards,<br>
> Manu<br>
><br>
> typedef bool (* DummyFunc)   ();<br>
><br>
><br>
> bool ExecDummy (DummyFunc fptr) {<br>
><br>
>     if (fptr)<br>
>         return fptr ();<br>
><br>
>     return false;<br>
> }<br>
><br>
> constexpr unsigned int IsMyAppClient = 0;<br>
><br>
> constexpr bool CheckForTypeClient (unsigned int pAppType)<br>
> {<br>
>     return ((pAppType & IsMyAppClient) != 0);<br>
> }<br>
><br>
><br>
> class  MyAppTemplate<br>
> {<br>
> public:<br>
>     template <unsigned int T><br>
>     static    bool    MyAppInit ();<br>
> };<br>
><br>
> template <unsigned int T><br>
> bool<br>
> MyAppTemplate::MyAppInit ()<br>
> {<br>
>     if constexpr (CheckForTypeClient(T)) {<br>
><br>
>         return ClientMain ();                    // no error<br>
>         //return ExecDummy(ClientMain);            // error: use of undeclared identifier 'ClientMain'<br>
>     }<br>
><br>
>     return false;<br>
> }<br>
><br>
> int __cdecl<br>
> main (int pArgc, char* pArgv[])<br>
> {<br>
>     constexpr int TVal = 3;<br>
><br>
>     MyAppTemplate::MyAppInit<TVal> ();<br>
><br>
>     return 0;<br>
> }<br>
><br>
><br>
> _______________________________________________<br>
> cfe-users mailing list<br>
> <a href="mailto:cfe-users@lists.llvm.org" target="_blank">cfe-users@lists.llvm.org</a><br>
> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users</a><br>
</div>
</span></font></div>
</div>

</blockquote></div></div>