<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body 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><br>
</div>
<div>Regards,</div>
<div>Manu</div>
<div><br>
</div>
</div>
<div id="appendonsend"></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 tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> David Blaikie <dblaikie@gmail.com><br>
<b>Sent:</b> Saturday, August 22, 2020 2:14 AM<br>
<b>To:</b> Manu agarwal <Manu.Agarwal@live.in><br>
<b>Cc:</b> cfe-users@lists.llvm.org <cfe-users@lists.llvm.org><br>
<b>Subject:</b> Re: [cfe-users] inconsistent compilation error inside constexpr if</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText">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>
<cfe-users@lists.llvm.org> 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>
> cfe-users@lists.llvm.org<br>
> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users</a><br>
</div>
</span></font></div>
</body>
</html>