Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

-Wconversion and implicit string to bool cast

I got used to writing this idiom:

assert(!"Something went wrong");

But now -Wconversion has been enabled in the project, and this code no longer compiles:

error: implicit conversion turns string literal into bool

I understand that if I cast it explicitly, the error will go away, but it is too cumbersome:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

assert(!static_cast<bool>("Something went wrong"));

Is there a more elegant solution to this?

>Solution :

And my options, shorter than the other earlier answered:

assert(!"something went wrong"[0]);
assert(!*"something went wrong");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading