llvm / llvm/llvm-project

[clang-tidy] detect `errno` being compared with a number literal

Open
#182,518 1 comment 0 reactions 0 assignees View on GitHub
check-request clang-tidy
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The actual values of the error constants utilized by `errno` are not being document so technically that makes them implementation-defined (it is stated more than specified by the standard might be defined). So checking it against a number might not be portable.

See
https://en.cppreference.com/w/c/error/errno_macros.html
https://en.cppreference.com/w/cpp/error/errno_macros.html
https://www.man7.org/linux/man-pages/man3/errno.3.html

They are actually document as "implementation-defined" in https://en.cppreference.com/w/c/header/errno.html.

And the Visual Studio documentation provides some actual values: https://learn.microsoft.com/en-us/cpp/c-runtime-library/errno-constants.

Contributor guide

Open the contributing guide

Research direction

Start at the clang-tidy entry point and locate the existing checks related to errno or portability diagnostics. Confirm how comparisons with numeric literals are represented and tested, then define the diagnostic behavior for detecting errno compared with a number literal. Done means the new case is diagnosed with coverage for the relevant comparison forms.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.