noexcept Questions

1

I am learning C++ using the books listed here. I wrote the following example(for purely academic reasons) that compiles with GCC but not with Clang and MSVC. Demo. struct C { static bool f() noexc...
Footmark asked 10/10, 2022 at 12:47

2

Solved

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 an...
Discipline asked 10/6, 2024 at 13:56

1

Solved

I noticed that the std::vector container's swap function has a different noexcept-specification than all other containers. Specifically, the function is noexcept if the expression std::allocator_tr...
Shadowy asked 10/5, 2023 at 19:44

2

Solved

Simple question: If change this: void someMethod(); to void someMethod() noexcept; will it break binary compatibility, or does the method signature remain the same?
Bandaranaike asked 19/7, 2018 at 18:20

3

Solved

See the following code containing 3 implementations of a function calling another throwing function. # include <stdexcept> void f() { throw std::runtime_error(""); } void g1() { ...
Gazo asked 20/3, 2024 at 10:46

10

Solved

The noexcept keyword can be appropriately applied to many function signatures, but I am unsure as to when I should consider using it in practice. Based on what I have read so far, the last-minute a...
Heterogenous asked 28/5, 2012 at 16:29

1

Solved

class C { public: C(C&&) = default; // (1) C& operator=(C&&) = default; // (1) C(C&&) noexcept = default; // (2) C& operator=(C&&) noexcept = default; ...
Chafe asked 15/1, 2024 at 6:10

2

Solved

I am wondering whether there would be a trick to simplify the writing of a trait to return whether a type is a noexcept function. Currently my implementation is the following, and it just lists all...
Kumar asked 16/6, 2020 at 14:42

3

Solved

Recently in my code I have been explicitly writing noexcept(false) on functions that I know do throw exceptions, mainly for people reading the code. However, I am wondering if this affects the beha...
Cotton asked 26/4, 2013 at 20:0

2

Solved

I know, marking a function noexcept may be useful in order to get many awesome optimizations [in some cases], such as move semantics, for example. But assume, I have a function in my code tha...
Fairhaired asked 23/12, 2022 at 13:38

1

Solved

Some functions should be non-throwing, but the standard doesn't say anything about it. Such as erase(q) (q denotes a valid dereferenceable constant iterator) of associative containers. This allows ...
Icelander asked 15/8, 2022 at 10:51

2

Solved

I've noticed that MSVC sometimes fails to deduce non-type parameters that other compilers accept, and recently came upon a simple example involving the function noexcept specifier (which is part of...
Pollux asked 1/6, 2022 at 19:50

1

Solved

Consider the following which uses the ternary operator to get the common function pointer type of the two lambdas int main() { true ? [](auto) noexcept {} : [](int) {}; } GCC-trunk only accepts i...
Grunion asked 11/4, 2022 at 10:33

1

Is there a way (compiler extensions are acceptable) to include C headers and mark included C functions as noexcept, but without modifying headers? For example, I have a C library and its header hea...
Branton asked 14/1, 2022 at 6:52

1

On C++ Primer on noexcept exception specification, it is said that a pointer to a function that may throw Implicitly (defined without exception specification e.g: void(*p)();) or explicitly (void(*...
Overzealous asked 10/3, 2021 at 23:25

2

I'm trying to write exception safe code. I find that using C++11's noexcept specifier makes this goal a whole lot more achievable. The general idea, of course, is that a function should be marked ...
Bet asked 1/2, 2013 at 17:53

2

Solved

It is not specified if call to ostream operator<< can fail or throw any exception and I have never encounter this. Is there a case where ostream operator<< could fail ? If no, why sta...
Illdisposed asked 7/11, 2019 at 15:50

4

Solved

In More Effective C++, Scott Meyers says C++ specifies that an object thrown as an exception is copied. I suppose then, that if the copy constructor throws an exception in turn, std::terminate...
Pilloff asked 8/2, 2014 at 10:16

2

Solved

I'm trying to experiment with code by myself here on different compilers. I've been trying to lookup the advantages of disabling exceptions on certain functions (via the binary footprint) and to co...
Vulture asked 20/8, 2021 at 14:53

1

Here is an example about my question: struct B { B(B&&, int = (throw 0, 0)) noexcept {} }; I know this is a very strange piece of code. It is just used to illustrate the problem. The move...
Joaquin asked 11/8, 2021 at 13:4

1

Solved

It appears that MSVC treats all lambdas as noexcept. This code compiles in msvc 19.28 (checked in Compiler Explorer), but expectedly fails the static assertion in gcc: void foo() { auto lambda_may...
Nissensohn asked 7/2, 2021 at 11:6

5

Solved

I can't find anything in the standard that forces functions declared with extern "C" to be noexcept, either implicitly or explicitly. Yet, it should be clear that C calling conventions cannot supp...
Turrell asked 23/6, 2014 at 9:32

3

Solved

I have a function template like this: template <typename T> constexpr auto myfunc() noexcept { return T{}; } Is this function template guaranteed to be noexcept because of copy elision? I...
Caracole asked 21/4, 2018 at 15:27

1

Solved

[expr.call]/6: Calling a function through an expression whose function type is different from the function type of the called function's definition results in undefined behavior. void f() noexcep...
Insomnolence asked 11/1, 2021 at 22:24

1

Solved

Assume the following c++17 code: #include <type_traits> namespace dtl { struct One { explicit One(int); ~One() = default; One(const One &) = delete; auto operator=(const One &) ...
Benn asked 31/12, 2020 at 13:18

© 2022 - 2025 — McMap. All rights reserved.