Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

static constexpr char m_pszFoo[] = "***FOO***" has compile error expression did not evaluate constant

error code is C2131.

intelisense does not complain even when I call size of on this variable in other files intelisense knows the size. what am I missing to get this working? Any help is greatly appreciated. In the pic below see intelisense not complaining and also determining size.

enter image description here

example a.h:

class a
{
private:
static constexpr char m_pszFoo[] = "***FOO***"; // compile error on this line C2131 expression did not evaluate to a constant

public:
a() { sizeof(m_pszFoo); }; // no compile error here
};

to reproduce all you need to do is include a.h in any other file. It won't reproduce without the include.

like image 375
noztol Avatar asked Jun 01 '16 16:06

noztol


1 Answers

So I came up with a work around b\c that error message made it seem like i needed to add a const somewhere

static constexpr char const m_pszFoo[] = "**FOO***";

for some reason if we tell the compiler that we should not be able to change the char to which the string points msvc is happy.

* Edit *

I got some suggestions to file a bug with microsoft and let them investigate as this looks to be an interop bug with msvc. here is the connect.microsoft link: https://connect.microsoft.com/VisualStudio/feedback/details/2781048

like image 59
noztol Avatar answered Nov 14 '22 23:11

noztol