Bug 95763 (Feature, Line, Max, Width) - Feature request: compiler warning if line width exceeds N symbols
Summary: Feature request: compiler warning if line width exceeds N symbols
Status: NEW
Alias: Feature, Line, Max, Width
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic, easyhack
Depends on:
Blocks: new-warning, new_warning
  Show dependency treegraph
 
Reported: 2020-06-19 09:55 UTC by Erich Erstu
Modified: 2024-06-20 20:58 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-04-17 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Erich Erstu 2020-06-19 09:55:02 UTC
Actually, this is a feature request, not a bug report.

It would be very useful if I could specify in a source file the maximum number of symbols per line that the source file is allowed to contain. If some line exceeds that limit, then the compiler should print the respective warning mentioning the line number where the limit is exceeded.
Comment 1 Jonathan Wakely 2020-06-19 12:08:23 UTC
This seems like a better fit for something like clang-tidy than being hardcoded into the compiler.
Comment 2 Erich Erstu 2020-06-19 13:12:59 UTC
(In reply to Jonathan Wakely from comment #1)
> This seems like a better fit for something like clang-tidy than being
> hardcoded into the compiler.

I can see the reasoning there, but different source/header files may have different maximum line width limitations. For example, we may have a project where most files are limited to 80 symbols per line but a subset of header files is limited to 240 symbols per line (as an exception). So, this could not be handled as a project-wide restriction but rather case-by-case. For example, those header files may contain large multidimensional nested arrays/tables (basically data) which requires an exception to be made.

For the above reasons, it would make sense to keep the line width limit as part of the code file that is supposed to respect that limit. Clang-tidy would have to get these limits from an external configuration file which bloats the project. Since GCC already implements special comments such as "// fall through" for switch statements, I could see this implemented similarly, as a comment in the beginning of the code file.
Comment 3 jsm-csl@polyomino.org.uk 2020-06-19 14:42:26 UTC
FWIW, the Ada front end has some style checking support (I once broke 
bootstrap by applying spelling corrections there, where fixing the 
spelling in a comment made a line too long).  It wouldn't be ridiculous to 
have such checks available for C and C++, so far as formatting checks work 
reasonably in the presence of macros.
Comment 4 Jakub Jelinek 2020-06-19 14:55:28 UTC
The fortran FE also has diagnostics about source line lengths.
The question is e.g. if comments should be an exception or not.
Comment 5 Drea Pinski 2021-04-17 21:36:26 UTC
I assume you are talking about stuff like:
int t, t1, t2, t43, t55, t6, t7888888, t99999, t999876, t323434, ttsdgsdg, thfgd, tdfhghh, t354635463546;

?
If so confirmed. I have not looked into how to do this and if this is normally not useful without a code style checker.

Having a code style checker part of GCC would be a good long term really.
Comment 6 Michael Levine 2024-06-20 20:44:24 UTC
Has there been an effort already to add a code style checker as part of GCC, similar to clang-tidy?