Tag: c++23
-
Are `int main()` and `int main(void)` equivalent prototypes in C23?
11 C23 introduced new semantics in function declarators: 6.7.6.3 Function declarators […] 13 For a function declarator without a parameter type list: the effect is as if it were declared with a parameter type list consisting of the keyword void. A function declarator provides a prototype for the function. This seems to imply that a function…
-
Which version of the C Standard Library does the C++23 Standard incorporate?
7 (My original question was going to be about "What happened to _BitInt?" but that was based on a misreading of some cppreference pages). The Library Introduction section 16.2 of the C++23 Draft Standard says that the C Standard library is supported in C++. The only reference to a specific C standard, however, is in…
-
What happens when an assumption, i.e. [[assume]] contains UB?
6 In C++23, the [[assume(expression)]] attribute makes it so that if expression is false, the behavior is undefined. For example: int div(int x, int y) { [[assume(y == 1)]]; return x / y; } This compiles to the same code as if y was always 1. div(int, int): mov eax, edi ret However, what happens…
-
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…
-
What is the best approach for using std::ranges/std::views with std::expected in C++23?
8 Let me describe a scenario, first we have a function which returns us some sort of data which we can’t be sure about the validity of, i.e. auto random_predicate() -> bool { int v = uniform_dist(e1); // uniform distribution 1 to 100 return (v % 5); } where uniform_dist() is an appropriately seeded uniform…