dimanche 31 mai 2015

const constexpr char* vs. constexpr char*

I know the difference between const and constexpr. One is a compile time constant and the other is either compile time or runtime constant.

However, for array of chars/strings, I'm confused why the compiler complains about one being used over the other.

For example I have:

constexpr char* A[2] = {"....", "....."};

const constexpr char* B[2] = {"....", "....."};

With declaration "A" I get:

ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

but with declaration "B" I get no warnings.

Why does the extra const qualifier get rid of the warning? Aren't both of them "const char*" anyway? I ask because both are declared with constexpr which should make it a const char* by default?

I'd expect A to be fine :S

Aucun commentaire:

Enregistrer un commentaire