diff --git a/compiler/src/dmd/backend/cgelem.d b/compiler/src/dmd/backend/cgelem.d index 56768622749f..a670e27f0e44 100644 --- a/compiler/src/dmd/backend/cgelem.d +++ b/compiler/src/dmd/backend/cgelem.d @@ -3296,7 +3296,7 @@ private elem* elbit(elem* e, Goal goal) e2.Ety = e.Ety; OPER shift = OPshr; - if (!tyuns(tym1)) + if (!tyuns(tym1) && tybasic(tym1) != TYbool) shift = OPashr; e.E1 = el_bin(shift,tym1, el_bin(OPshl,tym1,e.E1,el_long(TYint,c)), diff --git a/compiler/test/runnable/issue22663.d b/compiler/test/runnable/issue22663.d new file mode 100644 index 000000000000..12248f61f6d9 --- /dev/null +++ b/compiler/test/runnable/issue22663.d @@ -0,0 +1,22 @@ +// https://github.com/dlang/dmd/issues/22663 + +void main() +{ + struct S + { + bool b: 1; + } + S s = S(true); + + assert(s.b == true); + assert(s.b == 1); + + assert(!s.b == false); + assert(!s.b == 0); + + assert(s.b ? true : false); + assert(!s.b ? false: true); + + if (s.b) assert(1); + if (!s.b) assert(0); +}