C++: error: narrowing conversion of 'x' from 'int' to 'char' inside { } [-Wnarrowing]
Brace initialisation {} refuses conversions that can lose data, such as double to int or a runtime int to char.
narrowing conversion ofnarrowing conversion of from 'int' to 'char' inside { }non-constant-expression cannot be narrowed from typeconstant expression evaluates to which cannot be narrowed Meaning
List-initialisation was designed to catch lossy conversions. Constants that fit are allowed (char c{65};), but a variable or an out-of-range literal is an error in C++11 and later. Use the right type, or make the conversion explicit with static_cast when you really want it.
Common causes
- Initialising a smaller type from a variable with braces (
inttochar,longtoint) - Braced initialisation of an integer from a floating-point value
- Value outside the target type's range
- Signed to unsigned conversion of a negative or non-constant value in
{}
⚡ Quick fix
- Use the matching type (
intinstead ofchar) - Add
static_cast<T>(x)where narrowing is intended - Use
=initialisation only if you accept silent truncation (not recommended)
Detailed fix by platform
C++
char c{static_cast<char>(n)};makes the intent explicit- Prefer
autoor the exact type returned by the function you call
Code examples
Braces catch lossy conversions
int n = 300;
// char c{n}; // error: narrowing conversion of 'n' from 'int' to 'char'
char c{static_cast<char>(n)}; // OK, truncation is explicit (value 44)
double d = 3.9;
// int i{d}; // error: narrowing conversion
int i = static_cast<int>(d); // 3How to diagnose
- Types — Source and target types in the message?
- Constant — Is the value a compile-time constant that fits?
- Intent — Is truncation really wanted?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- call of overloaded is ambiguous C++: error: call of overloaded 'f(int)' is ambiguous
- comparison of integers of different signs C/C++: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' [-Wsign-compare]
- does not name a type C++: error: 'string' does not name a type
Most viewed in C/C++
- terminate called after throwing an instance of C++: terminate called after throwing an instance of 'std::out_of_range' — what(): vector::_M_range_check
- double free or corruption C/C++: free(): double free detected / double free or corruption (out) — Aborted (core dumped)
- undefined reference to C/C++: undefined reference to `function' — collect2: error: ld returned 1 exit status
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 15 Oct 2026