6,145 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
9
votes
1
answer
207
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 ...
3
votes
1
answer
161
views
Lifetime of temporary to which a local reference is bound in a c++ coroutine
On cppreference (which I understand is not the c++ standard itself) I have read that the coroutine state contains "local variables and temporaries whose lifetime spans the current suspension ...
3
votes
3
answers
179
views
C++ std::span overload resolution
I want to pass a C-style array to a function taking a std::span, but overload resolution chooses to convert the array to bool instead. Is this behavior required by the standard, or is it a compiler ...
3
votes
2
answers
228
views
How to avoid implicit conversion in C++ concepts?
Is there a way to prevent implicit conversions happening in concepts? For example, this example compiles with GCC and clang when I actually want it to give an error that the char constructor is ...
-3
votes
0
answers
181
views
nlohmann: Assertion failed: endptr == token_buffer.data() + token_buffer.size(), file include/nlohmann/detail/input/lexer.hpp, line 1292 [closed]
anybody anytime get next error?
Assertion failed: endptr == token_buffer.data() + token_buffer.size(), file include/nlohmann/detail/input/lexer.hpp, line 1292
i've next code:
int main(int argc, char *...
1
vote
2
answers
124
views
Is it valid to rethrow an unhandled C++ coroutine exception with `throw;`?
Is the following code valid in a C++ coroutine promise object?
void
promise_type::unhandled_exception() noexcept
{
try {
// re-throw current exception
throw;
} catch (const std::exception &...
17
votes
1
answer
662
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 ...
4
votes
1
answer
201
views
Passing a temporary into a coroutine by const reference
Assume that we have a potentially dangerous code that passes a const reference to a coroutine:
#include <boost/asio.hpp>
#include <iostream>
namespace asio = boost::asio;
using asio::...
Best practices
0
votes
13
replies
147
views
Is there a best practice on how to mimic defer/finalize blocks which can throw exceptions and should then throw nested exceptions
I'm trying to implement these requirements:
I have to execute functions i cannot modify.
Unfortunately, the functions also needs a specific global state which needs to be set before calling the ...
Advice
0
votes
3
replies
66
views
How to manage build order for C++ 20 modules in MSVC (vcxproj)?
I am creating a new project heavily laveraging C++ 20 modules in Visual Studio 2022.
For me it is working perfectly as I can successfully build my sources, the only drawback is I still do not know how ...
4
votes
1
answer
405
views
Why does Clang warn when using C++20 designated initializers with uniform initialization syntax?
According to some modern C++ guidelines, we should prefer uniform initialization everywhere, for example:
int x{0};
However, when I try to combine uniform initialization with C++20’s designated ...
3
votes
1
answer
142
views
When is the definition of an exported function available to an importing TU?
Consider the following translation unit:
export module Example;
export inline void fn1();
export void fn2();
export void fn3();
void fn1() {}
void fn2() {}
module :private;
void fn3() {}
Firstly, ...
0
votes
0
answers
106
views
Modifying object representation in presence of padding bits
This question is a follow-up of std::bit_cast padding and undefined behavior. This "revival" is motivated by my answer to Accessing object storage where I proposed a function to modify a ...
-2
votes
1
answer
98
views
How to access named capture groups in C++? [duplicate]
On Regex101, I have simple Regex with a named capture group in ECMAScript flavor:
(?<name>.*)
I'm trying to do the same thing in C++:
#include <iostream>
#include <regex>
using ...
Best practices
2
votes
8
replies
218
views
What is the optimal way to define a global constant string in C++20?
I need to define several constant strings that will be used across an entire C++20 project.
I am considering the following options :
constexpr char[] str1 = "foo";
constexpr std::string str2 ...