invalid conversion from C/C++ Origin: Application & API Last updated 15 Oct 2026

C++: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]

C++ forbids silently dropping const or converting between unrelated pointer types — typically a string literal assigned to char*.

Exact message you may see invalid conversion from 'const char*' to 'char*'invalid conversion from 'void*' toISO C++ forbids converting a string constant to 'char*'deprecated conversion from string constant to 'char*'
Seen on: C/C++ GCC Clang

Meaning

In C++ a string literal has type const char[N], so char* s = "hi"; is ill-formed. The same rule applies to void* (needs a cast in C++) and to int to enum conversions. The fix is to make the target type const-correct, not to add -fpermissive.

Common causes

  • String literal assigned to char* instead of const char*
  • void* from malloc assigned without a cast (valid in C, not C++)
  • const object passed where a non-const pointer is required
  • Integer assigned to an enum or pointer type
  • C code compiled as C++

⚡ Quick fix

  1. Use const char* or std::string
  2. Use static_cast<T*>(malloc(n)) — or better new/std::vector
  3. Make the function parameter const instead of casting away const

Detailed fix by platform

C++

  1. Replace char* name = "x"; with const char* name = "x"; or std::string name = "x";
  2. For a C API that wants char*, copy into a std::vector<char> and pass .data()

Code examples

const-correct string handling

cpp
// error: invalid conversion from 'const char*' to 'char*'
// char* title = "Report";

const char* title = "Report";          // OK: read-only literal
std::string editable = "Report";       // OK: owns a copy

void* raw = std::malloc(16);
int* p = static_cast<int*>(raw);       // C++ needs the cast

How to diagnose

  1. Source — Is the right-hand side a literal or a const object?
  2. Target — Can the variable type be made const?
  3. Language — Was this file meant to be compiled as C?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

call of overloaded is ambiguous — C++: error: call of overloaded 'f(int)' is ambiguous (C/C++)call of overloaded is…comparison of integers of different signs — C/C++: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' [-Wsign-compare] (C/C++)comparison of integer…discards qualifiers — C++: error: passing 'const X' as 'this' argument discards qualifiers [-fpermissive] (C/C++)discards qualifiersdoes not name a type — C++: error: 'string' does not name a type (C/C++)does not name a typeISO C++ forbids comparison between pointer and integer — C++: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] (C/C++)ISO C++ forbids compa…narrowing conversion — C++: error: narrowing conversion of 'x' from 'int' to 'char' inside { } [-Wnarrowing] (C/C++)narrowing conversionno matching function for call to — C++: error: no matching function for call to 'f(int, const char*)' (C/C++)no matching function …template argument deduction/substitution failed — C++: error: template argument deduction/substitution failed / couldn't deduce template parameter (C/C++)template argument ded…invalid c…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.