Il 23/02/26 11:52, Schimkowitsch Robert ha scritto:
bool isAskingWhen(Question q)
{
     return {q & QuestionFlag::When};
}

As you can see in the CE link, this produces a "narrowing" warning, which I 
want to avoid.


I guess you have a couple of options here, you could either:

* not put braces at all, or use round braces instead of curly. Round braces just group the expression, and are even redundant here. Round braces or not, the `q & QuestionFlag::When` expression has type QFlags<X>, and it converts to bool via its implicit operator int(). Curly braces instead trigger copy-list-initialization of the returned bool again via the implicit operator int(), but since int->bool is a narrowing conversion, and narrowing conversions are invalid in list initializations, then compiler warns or rejects the code; or

* use the slightly more expressive/verbose testFlag (or testAnyFlag depending on your use case), e.g.

    return q.testFlag(QuestionFlag::When);


HTH,
--
Giuseppe D'Angelo | [email protected] | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - Trusted Software Excellence

Attachment: smime.p7s
Description: Firma crittografica S/MIME

_______________________________________________
Interest mailing list
[email protected]
https://lists.qt-project.org/listinfo/interest

Reply via email to