357 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
3
votes
0
answers
202
views
Deducing noexcept [closed]
I sometimes have function templates whose body consist of a single expression E, where the function's noexcept specifier should be noexcept(E). To my best knowledge, I need to repeat the invocation of ...
8
votes
2
answers
284
views
Why should I be careful in "noexcept-ing all the functions" just like I "const all the things"?
I haven't found a video about const all the things 1, but there's at least Con.3: By default, pass pointers and references to consts from the Cpp Core Guidelines.
There's lots of presentations and ...
4
votes
1
answer
133
views
Unexpected call to constructor when non-throwing operator new returns a nullptr
In the following code, there is a no-throw operator new for the struct TestNew. It is required to further declare it as noexcept to ensure that the constructor is not called, when operator new returns ...
7
votes
1
answer
181
views
Can contract violations result in std::terminate on noexcept functions?
I have some code in the following style:
struct S {
private:
T* resource;
public:
S(T* r) : resource{r} {
if (r == nullptr) {
throw std::invalid_argument(":("...
5
votes
2
answers
152
views
Checking noexceptness when applying function to a pack
I have the following C++26 function which runs some code for each field of a structure:
template <typename S, typename F>
constexpr auto for_each_field(S&& s, F&& f)
{
auto&...
4
votes
1
answer
172
views
Can a function be marked noexcept if it takes a value type that may throw?
In C++, I mark a function as noexcept in the following cases:
The function itself does not throw exceptions, but its value type parameters may throw exceptions when constructing.
The following code ...
2
votes
1
answer
117
views
Issue with exception constructor parameter type in the standard library
In the standard library, the parameter type of the exception class's constructor, such as std::runtime_error, follow this pattern:
runtime_error( const std::string& what_arg ); // (1)
...
0
votes
0
answers
81
views
Why is clang not consistent on noexcept(++it) and noexcept(*it) for containers?
I'm not sure if it is specified in the standard that advance/dereference of standard container iterator are noexcept. GCC and MSVC consistently make them noexcept for all standard containers. But ...
1
vote
0
answers
50
views
Clarification on noexcept qualifier for wrapper functor using std::is_nothrow_invocable variants
I have a mini-personal library that I am creating and I have a wrapper functor I created in order to easily go from static invocable objects to functors.
For example, for something like std::...
2
votes
1
answer
103
views
Is there a way to access a variable in a thread-safe way with nothrow guarantee when std::atomic is not an option?
Let's say I have a class like this that can copy a value without throwing:
#include <type_traits>
template<typename T>
requires std::is_nothrow_copy_constructible_v<T>
&&...
9
votes
1
answer
151
views
Under what situations is the compiler meant to generate exception handling code with noexcept functions?
I have the following bit of code:
#include <cmath>
#include <stdexcept>
#include <vector>
void zoo(double& i) {
std::vector<int> v(static_cast<std::size_t>(i));
}...
4
votes
2
answers
155
views
Short-circuit in noexcept expressions
given the follow code:
// g++ main.cpp -std=c++23
#include <type_traits>
using namespace std;
template<typename P>
concept pointer_like = is_pointer_v<P> || requires (P p) { p....
0
votes
0
answers
87
views
Conditions for the noexcept expression
Please tell me if I defined the conditions for noexcept expressions correctly in this cases?
class scheme_host_port
{
public:
using value_type = std::string;
scheme_host_port()...
8
votes
2
answers
361
views
Should std::variant be nothrow destructible when its alternative has potentially throwing destructor?
TL;DR: see compilers disagree on code by Godbolt link: https://godbolt.org/z/f7G6PTEsh
Should std::variant be nothrow destructible when its alternative has potentially throwing destructor? Clang and ...
4
votes
1
answer
236
views
Can I mark a function with noexcept if it has an argument passed by copy?
So I wanted to improve the noexcept of some operators and functions in my code
can I mark this function noexcept ?
std::string remove_suffix(/*passed by copy*/ std::string s)
/*noexcept*/
// is ...
user avatar
user24551355