language-lawyer Questions

3

Solved

The section 3.4 Using Bracket Expressions of GNU awk manual, reads To include one of the characters ‘\’, ‘]’, ‘-’, or ‘^’ in a bracket expression, put a ‘\’ in front of it. For example: &nbsp...
Foreigner asked 2/11 at 14:38

2

Solved

Assuming alignment is a uintptr_t power of 2, looking for the next properly aligned address can be done using this expression: (address + alignment - 1u) & ~(alignment - 1u) This is used in cu...
Earthwork asked 23/10 at 23:36

2

Consider this example: #include <iostream> #include <atomic> #include <thread> #include <chrono> #include <cassert> int main(){ std::atomic<int> v = 0; std::at...
Eijkman asked 23/10 at 13:20

1

Solved

Consider this example: #include <iostream> #include <atomic> #include <thread> struct SpinLock{ std::atomic<bool> state; void lock(){ bool expected = false; while(!stat...
Tricksy asked 17/10 at 13:41

1

Solved

Should the following program be rejected? Clang seems to accept it. template<typename T> concept c = requires { T::n; }; struct z; constexpr bool b(auto...) { return c<z>; } struct z { ...
Refutation asked 12/10 at 22:32

2

Solved

I was reviewing a code I proposed to initialize a std::array at compile-time for non-default-constructible objects: https://mcmap.net/q/905632/-idiom-for-initializing-an-std-array-using-a-generator...

2

Solved

There is a part in the C++ standard about multi-threading memory model that I don't understand. A visible side effect A on a scalar object or bit-field M with respect to a value computation B of M...
Swinge asked 18/4, 2020 at 0:23

3

Solved

In [conv.lval] p3.4, the result of lvalue-to-rvalue conversion is described as follows: Otherwise, the object indicated by the glvalue is read ([defns.access]), and the value contained in the obje...

1

Solved

A requires-expression similarly to a function can introduce local parameters using a parameter list. And lambda expressions defined at block scope may have captures without initializers. Is it allo...
Interlace asked 25/9 at 19:40

2

Solved

GCC accepts this code, Clang and MSVC reject it due to failed static assertion in assert. What does the standard say? https://godbolt.org/z/PKMKzYGsc template<typename T> constexpr int assert...
Effectuate asked 24/9 at 2:53

1

Solved

This code is an attempt to reinterpret memory contents as a different type without violating strict aliasing rules. It was suggested as an answer to "Using std::memmove to work around strict a...
Discharge asked 20/9 at 13:37

1

Solved

A requires-expression can introduce local parameters using a parameter list. If any of these parameters has void type, will the requires expression just yield false or shall it be hard compilation ...
Northeastwards asked 19/9 at 20:32

1

Solved

#include <memory> #include <atomic> #include <iostream> #include <thread> #include <cassert> int main() { std::atomic<bool> flag = {false}; std::atomic<int&...

1

The following code compiles with g++ 14.2 and clang++ 18.1, but fails with MSVC 17.10. class Base { public: using peak = Base; Base() = default; }; class Derived : public Base { protected: usin...

1

std::bit_cast is advertised as the safe alternative to type-punning via reinterpret_cast. However, I see very often that people just blindly replace reinterpret_cast with bit_cast and calls it a da...
Idalla asked 10/9 at 7:30

2

Solved

Consider this example: std::atomic<int> v = {0}; // thread 1: for(int i = 0; i<999999;i++) v.load(memory_order::seq_cst); // #1 v.exchange(2,memory_order::seq_cst); // #2 //thread 2: ...
Engen asked 5/9 at 9:52

3

Solved

I noticed that the parameter of vector<T>::push_back is const T&. I know that a reallocation may take place when I call push_back, but vector<T>::back returns a reference. So ...
Joyce asked 7/9 at 9:18

1

Solved

Having this code, GCC and MSVC are both happy with it, when clang complains. Any two lambdas must have different types, which makes me think that clang "caches" the type of the default te...
Linotype asked 6/9 at 19:6

1

Solved

Consider the following setup: struct MyInt { template<class T> operator T() = delete; operator int(){ return 42; } }; struct TestCArr { int arr[2]; }; struct TestStdArr { std::array&l...

3

Solved

C99 defines these three as macros that "are expressions of type ‘‘pointer to FILE’’ that point to the FILE objects associated, respectively, with the standard error, input, and output streams&...
Uncertainty asked 30/5, 2023 at 13:8

1

Solved

When I compiled the code below using GCC 12, I encountered an error saying "no match for 'operator=='", but the code compiles fine with GCC 11. #include <iostream> #include <algo...
Headword asked 30/8 at 10:47

1

cppreference is explicit about calling std::shared_future<T>::wait from multiple threads: Calling wait on the same std::shared_future from multiple threads is not safe; the intended use is f...
Blotter asked 23/3, 2021 at 14:27

3

Solved

Consider this example: #include <iostream> #include <atomic> #include <random> #include <thread> int need_close(){ random_device rd; std::mt19937 gen(rd()); uniform_int_d...
Ghostwrite asked 27/8 at 8:24

3

Solved

Suppose I have a function returning by value S f(); and I call it like that: auto s = f(); If copy-constructor of S throws, and return some_s; inside f is surrounded by try-catch block, is it gu...
Mourning asked 19/8 at 9:30

1

Solved

Consider the following move-only type: struct MoveOnly { MoveOnly() = default; ~MoveOnly() = default; MoveOnly(const MoveOnly&) = delete; MoveOnly& operator=(const MoveOnly&) = del...

© 2022 - 2024 — McMap. All rights reserved.