You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Cannot handle assignment to u8 and i16 from literal values #1446
Describe the bug
If a variable is declared as u8 and a character literal is assigned to it, or a variable is declared as i16 and an integer literal is assigned to it, the generated code cannot be compiled by clang++ (g++ compiles but with warnings). I suspect this also applies to the respective signed/unsigned counterparts.
To Reproduce
Steps to reproduce the behavior:
Sample code - distilled down to minimal essentials please
main: () -> int = {
foo: u8;
foo = 'a';
bar: i16;
bar = 3;
}
Command lines including which C++ compiler you are using
clang++ fails when trying to expand #define CPP2_FORWARD(x) std::forward<decltype(x)>(x) with the following note:
test.cpp2:3:8: note: in instantiation of function template specialization 'cpp2::impl::deferred_init<unsigned char>::construct<char>' requested here
3 | foo.construct('a');
Additional context
Add any other context about the problem here.
The first problem can be bypassed if foo is declared as char (or _schar but that is probably platform dependent). However, the second one remains, even if bar is declared as short, since (AFAIK) there is no way of indicating an integer literal is a short.
Activity
Fix deferred init narrowing hsutter#1446 by keeping brace-init in cal…
Fix deferred init narrowing hsutter#1446 by keeping brace-init in cal…
Fix deferred init narrowing hsutter#1446 by keeping brace-init in cal…
Fix deferred init narrowing hsutter#1446 by keeping brace-init in cal…
Fix deferred init narrowing hsutter#1446 by keeping brace-init in cal…
dima-starosud commentedon Jul 17, 2026
The fix #1449 is on its way, waiting for review.