[cfe-users] inconsistent compilation error inside constexpr if
David Blaikie via cfe-users
cfe-users at lists.llvm.org
Fri Aug 21 13:44:01 PDT 2020
>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
<cfe-users at lists.llvm.org> 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
> cfe-users at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
More information about the cfe-users
mailing list