C library header included in C++ code

ID

c.maintainability.deprecated_headers

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Deprecated Header

Language

C / C++

Description

This C file includes a C standard library header (`<xxx.h>`). Prefer the C counterpart (<cxxx>, e.g. <cstdio>, <cstdlib>, <cstring>, <cmath>), which places the declarations in namespace std and is the maintained form for C++.

Rationale

This C file includes a C standard library header (`<xxx.h>`). Prefer the C counterpart (<cxxx>, e.g. <cstdio>, <cstdlib>, <cstring>, <cmath>), which places the declarations in namespace std and is the maintained form for C++.

The following code illustrates the pattern detected by this rule:

// Adapted from clang-tidy modernize-deprecated-headers upstream test:
// clang-tools-extra/test/clang-tidy/checkers/modernize/deprecated-headers.cpp
// FLAGGED: C library header included in C++ code
#include <stdio.h>
// FLAGGED: C library header included in C++ code
#include <stdlib.h>
// FLAGGED: C library header included in C++ code
#include <string.h>
// FLAGGED: C library header included in C++ code
#include <math.h>

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.