This is an archive of the discontinued LLVM Phabricator instance.

[clang] Warning for inline constexpr functions
AbandonedPublic

Authored by Izaron on Jan 16 2022, 10:11 AM.

Details

Summary

"inline constexpr" and "inline consteval" function declarations are redundant and shall be written rather as "constexpr" and "consteval".

Diff Detail

Event Timeline

Izaron requested review of this revision.Jan 16 2022, 10:11 AM
Izaron created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 16 2022, 10:11 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

I will provide more context in this comment.

Why this patch?
Clang currently has a warning for duplicating specifiers (inline inline, extern extern, consteval consteval, etc.), but has no warnings for redundant weaker specifiers.
I suggest to add such a group of warnings, starting from inline constexpr/inline consteval functions.

The Standard says (dcl.constexpr) that constexpr/consteval functions are implicitly inline. But Clang doesn't tell programmers that.
The volume of affected code can be seen in GitHub Search: inline constexpr, inline consteval.

What about the other meaning of inline?
Some years ago, the inline keyword meant not only "there may be multiple definitions", but also "there will be inlinehint attribute added in LLVM IR".
Fortunately, this is no more since Clang 3.3 release.
constexpr and inline constexpr functions emit the same LLVM IR attributes. (consteval function aren't even emitted to LLVM IR, executing exclusively at compile-time)

Izaron updated this revision to Diff 400399.Jan 16 2022, 12:03 PM

Fix tests

rjmccall requested changes to this revision.Jan 16 2022, 12:04 PM

I don't remember if this is written up anywhere, but clang has a longstanding policy that style enforcement belongs in a linter rather than the compiler. One programmer's "redundant" is another programmer's "clear and explicit". I don't think this warning is consistent with that.

This revision now requires changes to proceed.Jan 16 2022, 12:04 PM
Izaron added inline comments.Jan 16 2022, 12:07 PM
clang/test/Headers/x86-intrinsics-headers-clean.cpp
4–5

Honestly I have a doubt for this "fix" (just ignoring the new diagnostic), but I couldn't change the included file.

I don't remember if this is written up anywhere, but clang has a longstanding policy that style enforcement belongs in a linter rather than the compiler. One programmer's "redundant" is another programmer's "clear and explicit". I don't think this warning is consistent with that.

Thanks, didn't know this. Hope I'll make it to clang-tidy then.
(There was an abandoned review back in time when "inline" meant "inlinehint" for LLVM IR. https://reviews.llvm.org/D18914)

Izaron abandoned this revision.Jan 16 2022, 12:17 PM