Implicit String Conversions to Booleans -- Sandor Dargo
In this article, we'll learn about
-Wstring-conversion, something I learned from C++ Brain Teasers by Anders Schau Knatten](https://www.sandordargo.com/blog/2024/10/16/cpp-brain-teasers). Clang offers this compiler warning which fires on implicit conversions from C-strings to bools.
Implicit String Conversions to Booleans
by Sandor Dargo
From the article:
Let’s start with the first part by explaining why such an implicit conversion is possible. A string literal is an array of
const chars. Arrays can be converted into pointers, something we talked about last week when we discussed whyspans are so useful. This is also called decay. Furthermore, pointers can be converted into booleans. That is how a string literal can be converted into abool.static_assert(!!"" == true); static_assert(static_cast<bool>("") == true);What might be surprising though is that even an empty string literal is converted into
true. The reason is that only anullptrwould be converted intofalse, but an empty string literal is an array of a size of one so it’s not anullptr. As a result,""converted totrue. The possible confusion is that the one character in that array of one is the\0terminator. But this shouldn’t really matter. You shouldn’t use such shady implicit conversions.We could end this article right here. But life is not ideal and I tried to turn on
-Wstring-conversionin a production codebase where I found a few different cases of string literals conversions.

While most time zones use simple hour offsets from UTC, some regions have chosen unusual time differences. In this blog post, we’ll explore how we can discover such zones using C++20’s chrono library.
In this blog post, we will explore handling dates using std::chrono, including time zones. We’ll utilize the latest features of the library to retrieve the current time across various time zones, taking into account daylight saving time changes as well. Additionally, we will incorporate new capabilities introduced in C++23, such as enhanced printing functions and more.
Recent versions of the C++ language (C++20 and C++23) may allow you to change drastically how you program in C++. I want to provide some fun examples.