8,978 questions
- Bountied 1
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
3
votes
1
answer
175
views
std::memmove and std::memcpy requiring objects as source, according to cppreference
According to cppreference documentation, std::memmove and std::memcpy would expect an object address as input, which will theoretically limit there usage with buffer obtained from C-like API (mmap, ...
2
votes
3
answers
141
views
Does the returned value from `std::steady_clock::now()` denote a point in global time of the program?
Consider this example:
#include <atomic>
#include <chrono>
#include <thread>
uint64_t timestamp() {
auto now = std::chrono::steady_clock::now().time_since_epoch();
return ...
11
votes
1
answer
345
views
Clang accepts designated initialization where GCC/MSVC reject — compiler bug or invalid C++?
Clang compiles the following C++20 code snippet, while at the same time it is rejected by both GCC and MSVC.
There are at least two options:
The code is illegal and Clang fails to report an ...
4
votes
1
answer
162
views
Do compatible types have the same representation?
Furthermore, is the sizeof guaranteed to be the same on compatible types?
I expect the answer to both of these questions is likely "yes" in practice, but I don't see anything in the standard ...
2
votes
1
answer
120
views
Does an explicit instantiation declaration allow an explicit template specialization to be only declared in a separate translation unit?
Short version: Does an explicit instantiation declaration guarantee that a visible template definition is never used (unless an explicit instantiation definition is also encountered), and therefore ...
-4
votes
0
answers
313
views
Is it true that only a single thread can guarantee the linearizability? [closed]
Consider this example:
#include <atomic>
#include <chrono>
#include <thread>
int main() {
std::atomic<long int> key;
auto t1 = std::thread([&]() {
auto now =...
2
votes
0
answers
263
views
+50
Does the *happen-before* guarantee the order of delivery for data to a file?
Consider this example:
#include <thread>
#include <atomic>
#include <stream>
int main(){
std::ofstream outFile("example.txt", std::ios::out | std::ios::trunc);
std::...
-1
votes
0
answers
136
views
Is the updated data in MySQL guaranteed to be visible to the query in another thread when the notification doesn't establish synchronization?
Consider this example:
#include <thread>
#include <atomic>
extern char* mysql_query(MYSQL* mysql,char const*);
extern char* do_mysql_update(MYSQL* mysql);
int main(){
std::atomic<bool&...
15
votes
3
answers
436
views
Workarounds for using __has_include when it may or may not be defined - Is it valid to pass __has_include as a macro argument?
Often, I'd like to chain preprocessor conditionals involving __has_include (defined in C++17 and C23, and supported in earlier versions as an extension by many compilers (GCC 4.9.2 and up, and Clang ...
5
votes
1
answer
175
views
Why don't function pointers allow adding CV-qualifiers to pointer arguments?
I am work a mature codebase, one of the signs of its age is lack of consts which make the code difficult to reason about when refactoring.
I have found a function which takes an argument as a mutable ...
5
votes
2
answers
258
views
Why does floating-point std::to_chars not have a default argument?
std::to_chars has these two declarations:
to_chars_result to_chars(char* first, char* last,
floating-point-type value);
to_chars_result to_chars(char* first, char* last,
...
17
votes
1
answer
674
views
Should a friend function in a namespace different from the class be found by argument-dependent lookup?
Consider
struct A;
namespace ns { int f(A&&); }
struct A {
friend int ns::f(A&&);
};
int x = f(A{});
GCC trunk translates the last line into a call to ns::f(A&&) in C++20 ...
1
vote
1
answer
188
views
Initialization order of static variables in class templates
What determines the order of initialization of static variables in class templates?
Consider for example the program as follows:
#include <iostream>
int f() { static int s = 0; return ++s; }
...
22
votes
1
answer
1k
views
Is GCC right when it accepts a class template having a member with a wrong default member initializer?
GCC 15.2 (and many older versions) accepts the following code, while Clang 21.1 (and many older versions) don't:
struct Wrapper
{
explicit Wrapper(int) {}
};
template <int N = 0>
struct ...
1
vote
0
answers
59
views
enum class value definition from prior values [duplicate]
According to cppreference, it is allowed to define an unscoped enum value by using prior values of the same enum, e.g. like this:
enum MyEnum_U {
u_foo = 2,
u_bar = 5,
u_baz = u_foo + ...