Click here to Skip to main content
14,265,558 members
Rate this:
Please Sign up or sign in to vote.
See more:
how to fix:

Error C3249 illegal statement or sub-expression for 'constexpr' function

What I have tried:

struct CStreamCopyUtilProxy
{
                    template<bool TT, size_t ArrSize>
                    friend struct CStreamCopyUtilContainer;

                private:
                    const CustomResponseStreamWriter m_writeFunc = nullptr;

                    std::vector<char>** m_container = nullptr;

                public:
                    const CustomResponseStreamWriter Claim(std::vector<char>* myBin) const noexcept
                    {
                        if ((*m_container) != nullptr)
                        {
                            return nullptr;
                        }

                        (*m_container) = myBin;

                        return m_writeFunc;
                    }

                    const void Release() const noexcept
                    {
                        (*m_container) = nullptr;
                    }

                private:
                    constexpr CStreamCopyUtilProxy(const CustomResponseStreamWriter writeFunc, std::vector<char>** cont) noexcept : m_writeFunc(writeFunc)
                    {
                        m_container = cont; //getting error here
                    }
};
Posted
Updated 29-May-19 21:46pm
v2
Comments
Manish K. Agarwal 27-May-19 8:49am
   
(*m_container) = myBin; not allowed in const function
Member 14087451 27-May-19 9:25am
   
iam getting error here
m_container = cont;
Error C3249 illegal statement or sub-expression for 'constexpr' function
Richard MacCutchan 27-May-19 11:44am
   
I just compiled this with Microsoft (R) C/C++ Optimizing Compiler Version 19.15.26732.1 for x64, and it compiled cleanly.
Kornfeld Eliyahu Peter 28-May-19 3:20am
   
That's interesting - you probably compiled with C++ 14 and not 11...
constexpr constructor should not have any body under 11, but got extended under 14...
For me (GCC 7.1.1) it compiles only if there is no body...
Richard MacCutchan 28-May-19 3:57am
   
It is not something I have used before, but the documentation states that it can be used for functions and constructors, as in the example above. Unfortunately it is never clear which compiler version supports which level of the language.
Kornfeld Eliyahu Peter 28-May-19 3:07am
   
Have you checked all the requirements for a constexpr function?
https://en.cppreference.com/w/cpp/language/constexpr
Member 14087451 30-May-19 1:20am
   
i have compiled in vs2015
Richard MacCutchan 30-May-19 3:57am
   
Which may not support the latest version of C++.
Kornfeld Eliyahu Peter 30-May-19 6:01am
   
VS2015 has support for C++ 11's 'constexpr' feature, however, such method - under C++ 11 - must not have a body!!!
It is supported only from C++ 14...
Member 14087451 30-May-19 9:38am
   
ok thanks sir

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100