8,976 questions
1
vote
1
answer
79
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
98
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 ...
0
votes
0
answers
134
views
Is it true that only a single thread can guarantee the linearizability?
Consider this example:
#include <atomic>
#include <chrono>
#include <thread>
int main() {
std::atomic<long int> key;
auto t1 = std::thread([&]() {
auto now =...
1
vote
0
answers
183
views
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
135
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
411
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
171
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
247
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
648
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
184
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
58
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 + ...
9
votes
1
answer
186
views
Does std::to_chars ever really disambiguate using round_to_nearest?
[charconv.to.chars] says the following:
The functions that take a floating-point value but not a precision parameter ensure that the string representation consists of the smallest number of ...
22
votes
1
answer
746
views
Why can the reference to the std::array be evaluated first when assigning to it using a brace enclosed list?
Running the following code:
#include <array>
#include <iostream>
using namespace std;
array<int, 2> a;
array<int, 2>& f() {
cout << "f" << endl;...
1
vote
1
answer
253
views
Should we judge whether programs are functionally equivalent based on identical modification orders?
Consider this example:
#include <atomic>
#include <iostream>
#include <thread>
std::atomic<int> canceller = {0};
int main() {
auto t1 = std::thread([]() {
auto v = ...