C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Proposal: -Wverbose-style

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Tue, 14 Oct 2025 18:26:32 +0100
On Tue, 14 Oct 2025 at 18:25, Jonathan Wakely <cxx_at_[hidden]> wrote:

> This is out of scope for the C++ standard, talk to compiler vendors.
>

cppcheck or clang-tidy would probably be even more suitable.



>
> On Tue, 14 Oct 2025 at 18:21, Jerome Saint-Martin via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
>
>> *Title:*
>> A Warning Against Excessive Verbosity in Code Style
>> *Author:*
>> A concerned minimalist who believes in trusting operator precedence and
>> the elegance of concise expression.
>> *Abstract:*
>> This proposal introduces a new compiler warning category: -Wverbose-style,
>> designed to gently steer developers toward more confident, geek-approved
>> syntax. It targets overly cautious constructs that, while technically
>> correct, lack stylistic flair and betray a fear of trusting the language
>> *Motivation*
>> Modern C++ encourages clarity and safety. However, some developers take
>> this too far, writing code that is syntactically valid but stylistically
>> bloated. Examples include:
>>
>> - Redundant parentheses in logical expressions
>> - Literal comparisons to true or false
>> - Over-commenting obvious constructs
>> - Overly cautious initializations
>>
>> This proposal aims to gently nudge developers toward more idiomatic and
>> minimalist C++ — not by enforcing correctness, but by celebrating elegance.
>> *2. Examples*
>> *✅ Preferred Geeklike Style:*
>> /* clean, readable, confident */
>> if (a && b && c) { }
>> ❌ Triggers -Wverbose-style:
>> // warning: verbose-style detected. Consider trusting operator precedence.
>> if ((a && b) && (a && c))
>> // warning: verbose-style detected. Just write `if (flag)`
>> if (flag == true)
>> warning: verbose-style detected. Consider `std::string{}` or direct usage.
>> std::string s = "";
>> warning: verbose-style detected. Initialization could be more idiomatic.
>> int x = 0; // instead of `int x{};`
>> warning: verbose-style detected. Comment restates the obvious
>> if (x > 0) // Check if x is positive
>> i++; // Increment i
>> warning: verbose-style detected. Initialization could be more idiomatic.
>> Consider direct usage
>> std::vector<int> v = std::vector<int>();
>> *Implementation*
>> This warning would be opt-in via compiler flag:
>> g++ -Wverbose-style
>>
>> --
>> Std-Proposals mailing list
>> Std-Proposals_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>
>

Received on 2025-10-14 17:26:53