constexpr causes a gcc warning when used with string literals

Whether or not you are using constexpr here is not the issue. You are trying to store a string literal in a char* const which is not a pointer to immutable data (which the string literal is), but rather a pointer with a constant address. A string literal can be stored as const char* or const char* const instead.

const char* str = "This is a constant string."

Adding constexpr would look like this:

constexpr const char* str = "This is a constant string."

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top