# Regarding C++11 noexcept

**URL:** https://discourse.itk.org/t/regarding-c-11-noexcept/1517
**Category:** Uncategorized
**Created:** [January 11, 2019, 2:31pm UTC](https://discourse.itk.org/t/regarding-c-11-noexcept/1517 "2019-01-11T14:31:50Z")
**Posts on this page:** 4
**Page:** 2

<div class="post-metadata">

### Author: ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)
#### Post date: [May 4, 2020, 12:19pm UTC](https://discourse.itk.org/t/regarding-c-11-noexcept/1517/21 "2020-05-04T12:19:14Z")

</div>

The Visual C++ issue about the possibly negative performance effect of `noexcept` is still active, actually! It’s even relevant for the latest version of VS2019! There’s another aspect that I was not aware of before. It appears that MSVC does not inline-expand a `noexcept` member function of a DLL-imported class! Even if it would do so for a non-noexcept member function! As reported by gast128, April 16, 2020 in the discussion at [https://developercommunity.visualstudio.com/content/problem/425370/c11-noexcept-implementation-still-a-performance-lo.html](https://developercommunity.visualstudio.com/content/problem/425370/c11-noexcept-implementation-still-a-performance-lo.html)

I think it’s also interesting to read the comments Terry Mahaffey [MSFT]. Basically there’s another question, independent of `noexcept`: Should the compiler _ever_ inline-expand a member function of a DLL-imported class, at all? What do you think?

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [May 4, 2020, 9:41pm UTC](https://discourse.itk.org/t/regarding-c-11-noexcept/1517/22 "2020-05-04T21:41:53Z")

</div>

> [@Niels\_Dekker](#):
>
> I think it’s also interesting to read the comments Terry Mahaffey [MSFT]. Basically there’s another question, independent of `noexcept` : Should the compiler _ever_ inline-expand a member function of a DLL-imported class, at all? What do you think?

If you want to guarantee that you can apply a (security) update in a library by only updating the DLL in the application, then never inline would be needed. However, requiring to rebuild a whole applicate for updates may be OK for some high performance applications. The view form Terry Mahaffey seems to be coming from a systems application perspective as opposed to a scientific computing perspective.

---

<div class="post-metadata">

### Author: ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)
#### Post date: [May 5, 2020, 11:05am UTC](https://discourse.itk.org/t/regarding-c-11-noexcept/1517/23 "2020-05-05T11:05:31Z")

</div>

> [@blowekamp](#):
>
> If you want to guarantee that you can apply a (security) update in a library by only updating the DLL in the application, then never inline would be needed. However, requiring to rebuild a whole applicate for updates may be OK for some high performance applications. The view form Terry Mahaffey seems to be coming from a systems application perspective as opposed to a scientific computing perspective.

Thanks, Bradley @blowekamp It sounds to me like an extra compiler option would be useful, to specify either “inline-expand whenever possible”, or “dll-import whenever possible”. (I only tried MSVC optimization option /O2 so far.)

Here a simple code example: [Compiler Explorer](https://godbolt.org/z/-QTMy5)  
As follows:

```
class __declspec(dllimport) MyClass
{
public:
    void f() {}
    void g() noexcept {}
};

int main()
{
    MyClass var;
    var.f(); // Function call inline-expanded by MSVC
    var.g(); // Function call via DLL-import
}

```

---

<div class="post-metadata">

### Author: ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)
#### Post date: [January 7, 2022, 6:34pm UTC](https://discourse.itk.org/t/regarding-c-11-noexcept/1517/24 "2022-01-07T18:34:41Z")

</div>

A new book on C++, “Embracing Modern C++ Safely”, by John Lakos, Vittorio Romeo, Rostislav Khlebnikov, and Alisdair Meredith ([https://emcpps.com](https://emcpps.com)) has an extensive section dedicated to `noexcept`.

I made it into the Acknowledgments section of the book 😊

> Niels Dekker reviewed another unsafe C++11 feature (see Section 3.1.“noexcept Specifier” on page 1085) and provided valuable additional information as well as pointers to his own benchmark research.

 ![EmbracingModernCppSafely](https://discourse.itk.org/uploads/default/original/2X/1/15136e7301fa17caed18e4cba19e1f1fb035e1e2.jpeg)

My noexcept benchmark is still online: [GitHub - N-Dekker/noexcept\_benchmark: Compares the performance effect of 'noexcept' to an implicit exception specification](https://github.com/N-Dekker/noexcept_benchmark)

[Previous page](https://discourse.itk.org/t/regarding-c-11-noexcept/1517.md?page=1)
