Hi David,
Thanks for the reply. I missed to mention the environment and what i am trying
to do.
1. Environment is ClangCL (version 10.0), Microsoft Visual Studio.
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.
Here is the assembly generated from the successful compilation (with the first
line inside 'constexpr if' enabled).
"??$MyAppInit@$02@MyAppTemplate@@SQ_NXZ": #
@"??$MyAppInit@$02@MyAppTemplate@@SQ_NXZ"
.Lfunc_begin2:
.cv_func_id 2
.cv_loc 2 1 32 0 # Main.cpp:32:0
# %bb.0:
.cv_loc 2 1 39 0 # Main.cpp:39:0
xor eax, eax
# kill: def $al killed $al killed $eax
.Ltmp6:
ret
.Ltmp7:
.Lfunc_end2:
Here is how the compiler is invoked:
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
1> Done executing task "CL".
Is my understanding of 'constexpr if' wrong ? won't the body get discarded in
case it gets evaluated to false?
Regards,
Manu
________________________________
From: David Blaikie <[email protected]>
Sent: Saturday, August 22, 2020 2:14 AM
To: Manu agarwal <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: [cfe-users] inconsistent compilation error inside constexpr if
>From what I could test on godbolt, using LLVM evrsions back to 5.0,
Clang does reject the "return ClientMain();" call you aren't seeing an
error on. So I'm not sure what compiler/version/situation you're
running, but at least at first blush it doesn't look like clang.
On Fri, Aug 21, 2020 at 1:29 PM Manu agarwal via cfe-users
<[email protected]> wrote:
>
> Hello,
>
> In the below code the compiler throws "undeclared identifier" when the
> commented line is uncommented. Whereas the line just before compiles fine.
>
> Regards,
> Manu
>
> typedef bool (* DummyFunc) ();
>
>
> bool ExecDummy (DummyFunc fptr) {
>
> if (fptr)
> return fptr ();
>
> return false;
> }
>
> constexpr unsigned int IsMyAppClient = 0;
>
> constexpr bool CheckForTypeClient (unsigned int pAppType)
> {
> return ((pAppType & IsMyAppClient) != 0);
> }
>
>
> class MyAppTemplate
> {
> public:
> template <unsigned int T>
> static bool MyAppInit ();
> };
>
> template <unsigned int T>
> bool
> MyAppTemplate::MyAppInit ()
> {
> if constexpr (CheckForTypeClient(T)) {
>
> return ClientMain (); // no error
> //return ExecDummy(ClientMain); // error: use of
> undeclared identifier 'ClientMain'
> }
>
> return false;
> }
>
> int __cdecl
> main (int pArgc, char* pArgv[])
> {
> constexpr int TVal = 3;
>
> MyAppTemplate::MyAppInit<TVal> ();
>
> return 0;
> }
>
>
> _______________________________________________
> cfe-users mailing list
> [email protected]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
_______________________________________________
cfe-users mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users