Main Content

MISRA C++:2023 Rule 4.1.2

Deprecated features should not be used

Since R2024b

Description

Rule Definition

Deprecated features should not be used.

Rationale

This rule prohibits utilizing C++ features that are listed as deprecated in Annex D of the C++ standard. A feature becomes deprecated when a safer or more efficient alternative exists. Occasionally, such features might be eliminated in subsequent versions of C++. Steering clear of deprecated features enhances the quality of your code and ensures its compatibility with future C++ versions.

Polyspace Implementation

The rule checker reports violations on the following deprecated features outlined in sections of Annex D of the C++17 standard:

Section in Annex D of C++17 StandardDeprecated Feature
D.1 Redeclaration of static constexpr data members [depr.static_constexpr]

Redeclaration of static constexpr data members

D.2 Implicit declaration of copy functions[depr.impldec]
  • Implicit declaration of copy constructor if the class has a user-declared copy-assignment operator or user-declared destructor.

  • Implicit declaration of copy assignment operator if the class has a user-declared copy constructor or user-declared destructor..

D.3 Deprecated exception specifications [depr.except.spec]

throw() exception specification

D.4 C++ standard library headers [depr.cpp.headers]

Headers <ccomplex>, <cstdalign>, <cstdbool>, <ctgmath>, and features

D.6 char* streams [depr.str.strstreams]

<strstream> header

D.7 uncaught_exception [depr.uncaught]

std::uncaught_exception() function

D.8 Old adaptable function bindings [depr.func.adaptor.binding]

Adaptable function bindings such as:

  • Types defined in std::owner_less template such as first_argument_type, second_argument_type, and result_type

  • Types defined in std::reference_wrapper template such as argument_type, first_argument_type, second_argument_type, and result_type

And similar types in templates such as std::plus, std::minus, std::multiplies, std::divides, std::modulus, std::negate, std::negate, std::equal_to, std::not_equal_to, std::greater, std::less, std::greater_equal, std::less_equal, std::logical_and, std::logical_or, std::logical_not, std::bit_and, std::bit_or, std::bit_not and std::bit_xor.

D.8.3: Negators [depr.negators]

Negators such as:

  • std::not1() and std::not2() functions

  • std::unary_negate template class and types defined in the class, for instance, argument_type and result_type

  • std::binary_negate template class and types defined in the class, for instance, first_argument_type, second_argument_type, and result_type

D.9 : The default allocator [depr.default.allocator]

Following features of std::allocator template class:

  • construct(), destroy(), address(), max_size() methods

  • pointer, reference, const_pointer, const_reference types

  • rebind template type

In addition, the instantiation std::allocator<void> is also deprecated.

D.10: Raw storage iterator [depr.storage.iterator]

std::raw_storage_iterator template class and its features such as iterator_category, value_type, difference_type, pointer and reference types

D.11: Temporary buffers [depr.temporary.buffer]

std::get_temporary_buffer() and std::return_temporary_buffer()

D.12 Deprecated type traits [depr.meta.types]

Type traits such as:

  • std::is_literal type

  • is_literal_type_v and is_literal_type_value variables

  • std::result_of and std::result_of_t types

D.13 Deprecated iterator primitives [depr.iterator.primitives]

Use of std::iterator as base class to provide typedef-s

D.14 Deprecated shared_ptrobservers [depr.util.smartptr.shared.obs]

std::shared_ptr::unique() function

D.15 Deprecated standard code conversion facets [depr.locale.stdcvt]

<codecvt> header

D.16 Deprecated convenience conversion interfaces [depr.conversions]

Conversion interfaces such as:

  • wstring_convert class and types defined in the class such as byte_string, wide_string, state_type, and int_type.

  • wbuffer_convert class and types defined in the class such as state_type.

Troubleshooting

If you expect a rule violation but Polyspace® does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.

Examples

expand all

#include <memory>

void std_allocator_member_types(void) {
    std::allocator<int> allocator;
    int* p = allocator.allocate(1);
    allocator.construct(p, 42);      // Noncompliant
    allocator.destroy(p);            // Noncompliant
}

This example violates the rule since it uses the deprecated methods construct() and destroy() in the std::allocator<> class.

Check Information

Group: General principles
Category: Required

Version History

Introduced in R2024b