Skip to main content
edited tags
Link
Nicol Bolas
  • 481.4k
  • 66
  • 861
  • 1.1k
Source Link
bpeikes
  • 3.7k
  • 12
  • 48
  • 93

c++20 handling of string literals

We’re updating a project to c++20, and are running into errors where we pass string literals into functions which take char *. I know this has been changed to make code more safe, but we are interfacing with libraries which we cannot change.

I’d rather not disable the strict treatment of literals via compiler flags, so is there a good way to wrap these literals just in these particular cases?

I was thinking of an inline function, that was named something specific to the library, that internally would use const_cast. That way later if we want to change the code because the library gets updated, we know exactly where to look.

Any other ideas?