GeneralPurpose-UseOfDeprecatedLanguageFeatures

Deprecated features should not be used

Required inputs: IR

Deprecated language features are removed from newer C++ standards and should not be used in new code. Using deprecated features complicates maintenance, limits compiler upgrades, and may become compilation errors in future standards. Modern replacements exist for most deprecated features and should be preferred.
Bad code (deprecated auto_ptr):
std::auto_ptr<int> ptr(new int(42));  // ERROR: auto_ptr is deprecated
std::auto_ptr<int> copy = ptr;        // ERROR: transfer of ownership is confusing
Good code (using unique_ptr):
std::unique_ptr<int> ptr(new int(42));  // OK: clear ownership semantics
auto copy = std::move(ptr);              // OK: explicit ownership transfer
Bad code (dynamic_exception_specifications):
void function() throw(std::runtime_error) {  // ERROR: deprecated specification
    // ...
}
Good code (using noexcept):
void function() noexcept {  // OK: modern exception specification
    // ...
}
Bad code (register keyword):
register int counter = 0;  // ERROR: register keyword is deprecated
for (int i = 0; i < 10; ++i) {
    counter += i;
}
Good code (compiler optimization):
int counter = 0;  // OK: let compiler optimize
for (int i = 0; i < 10; ++i) {
    counter += i;
}
Deprecated features include:
  • std::auto_ptr (use std::unique_ptr or std::shared_ptr)
  • Dynamic exception specifications throw(...) (use noexcept)
  • register keyword (compiler does optimization)
  • std::codecvt functions (use std::locale)
  • volatile for synchronization (use std::atomic)
  • Implicit copy operations (use explicit =default or =delete)

Possible Messages

Key

Text

Severity

Disabled

cafe_message

{}

None

False

deprecated_implicit_copy

Class with deprecated implicit {}.

None

False

lib_header_entity_use

Usage of forbidden entity from <{}>.

None

False

lib_header_include

Unit includes <{}>.

None

False

throw_in_decl

Do not specify any exceptions in signatures.

None

False

type_used

The std::auto_ptr shall not be used.

None

False

Options

allowed_symbols

allowed_symbols : set[str] = {'NULL', 'size_t'}

Symbols which should be allowed despite being defined in the headers (used for symbols like NULL and size_t which are defined in multiple headers).
 

message_predicate

message_predicate : typing.Callable[[Cafe_Message], bool] | None = None

If provided, a custom predicate to filter relevant messages. Receives the message node and should return True for messages to report.
 

report_class_if_deprecated_smf_unused

report_class_if_deprecated_smf_unused : bool = False

If set to True, a class is reported if any of the C++17-deprecated special member functions (SMF) is implicitly defined, even if none of them is ever called.
 

reported_severities

reported_severities : set[str] = {'error', 'remark', 'warning'}

List of severities to display.
 

use_error_number

use_error_number : bool = False

Whether the error number from the frontend should be used.
 

use_rule_severity

use_rule_severity : bool = False

Whether the rule's severity or the compiler's severity should be used.
 

user_header

user_header : set[str] = set()

Name of the user header files which should not be used.