Skip to main content

IAR Embedded Workbench for RL78 5.20

MISRAC++2023-9.2.1 (C++ only)

In this section:
Synopsis

(Required) An explicit type conversion shall not be an expression statement

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

A functionally notated type conversion as an expression can easily be mistaken for a scoped variable declaration.

Coding standards

This check does not correspond to any coding standard rules.

Code examples

The following code example fails the check and will give a warning:

#include <memory>

// Intension: Take ownership and use incoming pointer.
void example(int* n) {
  std::unique_ptr<int>{n}; // Non-compliant, created and destroyed here.
  // n is invalid here
}

The following code example passes the check and will not give a warning about this issue:

#include <memory>

// Intension: Take ownership and use incoming pointer.
void example(int* n) {
  std::unique_ptr<int> own{n}; // Compliant
  // n is valid here
}