Tag: language-lawyer
-
Why is ‘char -> int’ promotion, but ‘char -> short’ is conversion (but not promotion)?
22 I’ve read cppreference.com’s implicit conversion: Integral promotion: prvalues of small integral types (such as char) may be converted to prvalues of larger integral types (such as int). […] Note that all other conversions are not promotions; for example, overload resolution chooses char -> int (promotion) over char -> short (conversion). The conversion from char…
-
Why ‘char -> int’ is promotion , but ‘char -> short’ is conversion (but not promotion)?
11 I’ve read this Integral promotion: prvalues of small integral types (such as char) may be converted to prvalues of larger integral types (such as int). – first line […details – not important…] Note that all other conversions are not promotions; for example, overload resolution chooses char -> int (promotion) over char -> short (conversion).…
-
Inconsistent behavior of std::common_reference_with on tuples. Which is correct?
11 Background: I’m trying to port a library to compile on MSVC. That library stores data in a tuple of vectors (std::tuple<std::vector<Ts>…>), and uses a custom iterator to iterate over all vectors simultaneously (similar to what a zip_iterator does). The iterator defines types that look like this (assuming Ts… -> <int, int>) : `value_type` is…
-
Only bitwise operations for std::byte in C++17?
12 In CPP Reference it is stated that: std::byte is a distinct type that implements the concept of byte as specified in the C++ language definition. Like char and unsigned char, it can be used to access raw memory occupied by other objects (object representation), but unlike those types, it is not a character type…
-
Does nullptr_t break type punning or pointer conversions?
7 Consider this union: typedef union { void* vptr; nullptr_t nptr; } pun_intended; nullptr_t is supposedly compatible with void*. Ok so what if we initialize the void* to some non-zero value? pun_intended foo = { .vptr = (void*)42 }; This conversion is supposedly legit (impl.defined) as per C23 6.3.2.3 §4, or at least it was…
-
Does the definition int a = 0, b = a++, c = a++; have defined behavior in C?
19 Does the definition int a = 0, b = a++, c = a++; have defined behavior in C? Or almost equivalently, does the , in an object definition introduce a sequence point as for the comma operator in expressions? Similar questions have been asked for C++: Does `int a = 0, b = a`…
-
Is every null pointer constant a null pointer?
9 From the C17 draft (6.3.2.3 ¶3): An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.67) If a null pointer constant is converted to a pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal to a…