Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to fix:

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

What I have tried:

C++
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.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900