dynamic exception specifications are deprecated

17,214

You should remove or comment out these exception specifications wherever you can1, e.g.:

static Value getPriorityValue(const std::string& priorityName);
static Value getPriorityValue(const std::string& priorityName) /* throw(...) */;

You can use the -Wno-deprecated option to turn-off depreciation warnings for places where you cannot edit the code. I would recommend only using it when compiling third-party libraries. If you need to include a third-party header that raise such warning, you could do2:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated"
#include "thirdparty.h"
#pragma GCC diagnostic pop

This should work with both gcc and clang and will only disable -Wdeprecated for specific includes.

1 Dynamic exception specifications are deprecated since C++11, and are illegal since C++17, so you might want to get rid of them and upgrade third-party libraries you are using as soon as possible.

2 If you include these headers using a -I argument, you could switch to -isystem to disable all warnings for these headers, as mentioned by @Yakk - Adam Nevraumont. See also How to suppress GCC warnings from library headers?.

Share:
17,214
user846566
Author by

user846566

Updated on July 07, 2022

Comments

  • user846566
    user846566 almost 2 years

    I have C++ code that used to compile (and work), now I get lots of warnings. This happened after I did a dist-upgrade to Ubuntu-Mate.

    warning: dynamic exception specifications are deprecated in C++11

    It happens on lines as simple as this (in a header):

        static Value getPriorityValue(const std::string& priorityName)
        throw(std::invalid_argument);
    

    I got 2545 warning related to this! Is there anyway to tell the compiler to ignore this warning? What is the easiest way to make changes to the code.

    Most of the errors are in a 3rd party package so I don't want to make too many modifications to this package.

    I do have the -std=c++11 flag on in my compiler.

  • Yakk - Adam Nevraumont
    Yakk - Adam Nevraumont almost 6 years
    There is also a way to mark directories as system headers and not generate any warnings. -isystem instead of -I -- see stackoverflow.com/q/1867065/1774667
  • user7860670
    user7860670 almost 6 years
    @Yakk-AdamNevraumont Suppressing all the warnings is never a good idea.
  • Slava
    Slava almost 6 years
    @VTT if you have no intention to modify 3rd party library it actually is.
  • user7860670
    user7860670 almost 6 years
    Instead of removing them completely I would rather suggest to move them into comment section. Even though exception specifiers always were somewhat useless part of the language they may be still valuable part of code documentation.
  • user7860670
    user7860670 almost 6 years
    @Slava "Engineers are forgiven for making mistakes. They are not forgiven for hiding mistakes."