Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dynamic exception specifications are deprecated

Tags:

c++

c++11

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.

like image 417
user846566 Avatar asked May 09 '18 13:05

user846566


People also ask

What is the dynamic exception specification in C++?

The dynamic exception specification, or throw (optional_type_list) specification, was deprecated in C++11 and removed in C++17, except for throw (), which is an alias for noexcept (true). This exception specification was designed to provide summary information about what exceptions can be thrown out of a function, ...

What is the explicit dynamic specification?

Explicit dynamic specification allowed specifying one or more types for exception that might be thrown by a function. In 1978, Brian Kernighan and Dennis Ritchie published the first edition of The C Programming Language. It's a very reasonable question. P1018: Cable sold today under any RG label is unlikely to meet military MIL-C-17 specifications.

What is the purpose of exception specification?

Privacy policy. Thank you. Exception specifications are a C++ language feature that indicate the programmer's intent about the exception types that can be propagated by a function. You can specify that a function may or may not exit by an exception by using an exception specification.

What happened to dynamic exceptions in C++17?

And new standard and have been removed from the C++ Standardization Committee has finished meeting. With dynamic exceptions when they were proposed sure you have a product-specific question please on. Separate loops than in a combined loop C with Classes '', the set iso c++17 does not allow dynamic exception specifications all types the.


1 Answers

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?.

like image 80
Holt Avatar answered Sep 21 '22 23:09

Holt