llvm / llvm/llvm-project

[Clang] Add new warning for a == 10 ? false : true called -Wredundant-ternary.

Open
#214,715 1 comment 0 reactions 0 assignees View on GitHub
clang:diagnostics
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

[GCC bug 126715](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126715)
[Clang trunk godbolt](https://godbolt.org/z/hPov6qTGs) with -O3 -Wall -Wextra -Weverything
does not warn that the C/C++ ternary is redundant:

```c++
extern bool src (int a);

bool
src (int a)
{
return a == 10 ? false : true;
}

```

This shows up in GCC pre [r17-2872 / 2f5ed170082f9f2401a0c1c4a18e538c0cf75013](https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=2f5ed170082f9f2401a0c1c4a18e538c0cf75013).

Maybe call this warning -Wredundant-ternary and make it default in -Wall?

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the C/C++ example from the issue in the linked Clang trunk Godbolt configuration and compare it with the referenced GCC behavior. The issue names no repository files or tests; completion requires a diagnostic for the redundant ternary, with the warning name and whether it belongs in -Wall resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cpp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.