6,216 questions
0
votes
0
answers
90
views
Linkage error using STD on Windows GCC 15.2.0
I follow How to use module `std` with gcc to generate "gcm.cache/std.gcm" on Windows using GCC 15.2.0 and ran g++ -std=c++23 -fmodules -fsearch-include-path -c bits/std.cc at "C:\bak\...
4
votes
3
answers
299
views
Does std::atomic remain atomic when a struct is allocated with malloc?
I have a struct that contains a std::atomic member:
#include <atomic>
#include <cstdint>
struct Foo {
std::atomic<int64_t> value;
int64_t age;
};
If I allocate memory for ...
2
votes
1
answer
320
views
Is std::system thread safe? If not, in which way?
Is std::system thread safe? If not, in which way? Clangd gives me warning about it, says this function is not thread safe. If not, I want to execute different task in a thread safe way, is there a ...
4
votes
1
answer
166
views
CMake looks for `std.cppm` in wrong directory when using `import std`
Recently I've decided to "modularize" my library. No success. Here is the repo where you can find CMakeLists.txt & CMakePresets.json: kissra (GitHub)
The issue is that CMake cannot find ...
6
votes
4
answers
265
views
Size mismatch of more than 2 arrays
Let's say I have n arrays (right now I have 4 but that might go up) and they're supposed to be of the same size, but since I'm fetching them from outside the code I want to be sure
std::vector<int&...
Advice
0
votes
10
replies
254
views
Valid but unspecified state. What is specified then?
The standard says that after a move, an object is in a "valid but unspecified state". I found nothing in the standard on the properties of being in a "specified state" and being in ...
Advice
3
votes
8
replies
330
views
Why do people use macros to declare namespaces in c++?
Off the top of my head, I only remember LLVM's standard library do this, but I remember seeing other libraries also do this. I'm not entirely sure what is the advantage here. I feel like namespace std ...
Advice
0
votes
6
replies
235
views
C++ compile type endianness for use in macros
I need to layout a structure in two different ways depending on the endianness of the target platform. Currently I'm using an additional pre-compile phase to run a program to test the endianness, and ...
-1
votes
1
answer
234
views
What are the disadvantages of std::try_lock()?
I am currently studying the work of the mutex and I have a question, if we have the std::try_lock() method, then why not always use it instead of std::lock(), what are its disadvantages?
For example, ...
Advice
1
vote
7
replies
186
views
How does Microsofts std::lib implementation perform debug iterator checks?
In the question Why does Microsoft's implementation of std::string require 40 bytes on the stack? the observation is made, that a std::string requires 8 additional bytes in Debug mode.
After ...
0
votes
0
answers
88
views
Debug configuration build with OR'ing std::wregex constansts throws an unexpected std::regex_error exception
I'm compiling this with VS 2022 C++ compiler, as "ISO C++20 Standard (/std:c++20)" for a Debug configuration.
How come this throws the following std::regex_error:
regex_error(error_backref):...
6
votes
4
answers
288
views
Constexpr function that builds an integral value from a list of bits
Sometimes, it may be useful to build an integral value from a list of bits (in increasing order). Such a function could be named to_integral.
Example:
static_assert (to_integral(1,1,0,1,0,1) == ...
0
votes
0
answers
118
views
Does std::is_invocable_r with void as return type lead to UB?
Today I stumbled upon weird behavior of std::is_invocable_r.
While doing research for why it is happening, I stumbled upon this question on Stack Overflow:
is_invocable_r ignoring the return parameter
...
15
votes
1
answer
1k
views
Is it Undefined Behavior to backport namespace std features to older C++ versions?
According to What are the reasons that extending the std namespace is considered undefined behavior?, adding anything to namespace std is Undefined Behavior, with some exceptions carved out, such as ...
1
vote
1
answer
606
views
Apple Clang 21 unable to compile with c++ 23 stacktrace header
I am trying to use the C++ 23 stacktrace header in my project but I can't get it to compile. I've reproduced this with a minimal case to demonstrate the error I am getting. Any input would be greatly ...