Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of compiler warnings #392

Open
plexoos opened this issue Sep 2, 2022 · 0 comments
Open

Get rid of compiler warnings #392

plexoos opened this issue Sep 2, 2022 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@plexoos
Copy link
Member

plexoos commented Sep 2, 2022

Our build system currently asks the compiler to print many useful warnings (-Wall). This sounds like a good idea since warnings may indicate problematic places in the code, obsolete features, or the use of nonstandard extension of C/C++. However, it appears that the reported warnings have been ignored for quite a long time. Currently there are about 3,000 warnings reported by gcc 4.8.5. A goal to address all the warnings should be recognized and a zero-warning policy should be enforced for all future code modifications.

A list of warnings sorted by their frequency in the build log (gcc 4.8.5, root 5):

                                                                      msg  count   freq
0         deprecated conversion from string constant to [-Wwrite-strings]    798  27.0%
1      may be used uninitialized in this function [-Wmaybe-uninitialized]    435  14.7%
2   deleting object of polymorphic class type which has non-virtual de...    403  13.6%
3                   variable set but not used [-Wunused-but-set-variable]    341  11.5%
4                                     unused variable [-Wunused-variable]    293   9.9%
5      format expects argument of type, but argument has type [-Wformat=]    210   7.1%
6   comparison between signed and unsigned integer expressions [-Wsign...     73   2.5%
7   iteration invokes undefined behavior [-Waggressive-loop-optimizati...     56   1.9%
8                        operation on may be undefined [-Wsequence-point]     54   1.8%
9                           declaration of shadows a member of [-Wshadow]     41   1.4%
10           converting to non-pointer type from NULL [-Wconversion-null]     30   1.0%
11                                  unused parameter [-Wunused-parameter]     25   0.8%
12                       ignoring #pragma omp section [-Wunknown-pragmas]     22   0.7%
13                                      was hidden [-Woverloaded-virtual]     20   0.7%
14                 array subscript is above array bounds [-Warray-bounds]     14   0.5%
15  dereferencing type-punned pointer will break strict-aliasing rules...     13   0.4%
16                               defined but not used [-Wunused-variable]     12   0.4%
17                                  will be initialized after [-Wreorder]     11   0.4%
18                               defined but not used [-Wunused-function]      9   0.3%
19                unknown conversion type character in format [-Wformat=]      8   0.3%
20               control reaches end of non-void function [-Wreturn-type]      7   0.2%
21  argument to in call is the same pointer type as the destination; e...      7   0.2%
22                    too many arguments for format [-Wformat-extra-args]      7   0.2%
23  type qualifiers ignored on function return type [-Wignored-qualifi...      6   0.2%
24                            value computed is not used [-Wunused-value]      6   0.2%
25             suggest explicit braces to avoid ambiguous [-Wparentheses]      6   0.2%
26                               statement has no effect [-Wunused-value]      5   0.2%
27                                             within comment [-Wcomment]      5   0.2%
28  base class should be explicitly initialized in the copy constructo...      4   0.1%
29  comparison with string literal results in unspecified behaviour [-...      4   0.1%
30  cast to pointer from integer of different size [-Wint-to-pointer-c...      4   0.1%
31                      suggest parentheses around within [-Wparentheses]      3   0.1%
32                     the address of will always evaluate as [-Waddress]      3   0.1%
33    suggest parentheses around comparison in operand of [-Wparentheses]      3   0.1%
34           extra tokens at end of #endif directive [enabled by default]      2   0.1%
35       large integer implicitly truncated to unsigned type [-Woverflow]      2   0.1%
36         typedef locally defined but not used [-Wunused-local-typedefs]      2   0.1%
37                                         redefined [enabled by default]      2   0.1%
38                                    repeated flag in format [-Wformat=]      2   0.1%
39  argument to in call is the same expression as the destination; did...      2   0.1%
40                      ignoring #pragma omp parallel [-Wunknown-pragmas]      2   0.1%
41     no return statement in function returning non-void [-Wreturn-type]      2   0.1%
42                 use of length modifier with type character [-Wformat=]      1   0.0%
43                          initialized and declared [enabled by default]      1   0.0%
44  field precision specifier expects argument of type, but argument h...      1   0.0%
45            zero-length gnu_printf format string [-Wformat-zero-length]      1   0.0%
46                         format expects a matching argument [-Wformat=]      1   0.0%
47                            label defined but not used [-Wunused-label]      1   0.0%

fix_warns_orig

@plexoos plexoos added the help wanted Extra attention is needed label Sep 8, 2022
plexoos added a commit that referenced this issue Nov 3, 2022
GCC 11
warning: ISO C++ forbids converting a string constant to 'char*'
[-Wwrite-strings]

GCC 485
warning: deprecated conversion from string constant to 'char*'
[-Wwrite-strings]

See #392 for motivation

Co-authored-by: Dmitry Kalinkin <[email protected]>
plexoos added a commit that referenced this issue Dec 9, 2022
These changes do not affect how the code is built by default using
`cons` but allows one to interrupt compilation when the compiler (GCC
4.8.5) produces a warning.

```
cons EXTRA_CXXFLAGS="-Werror"
```

The source files matching the regex patterns in `mgr/warnoff_dirs.txt`
are excluded from the above rule in order to let CI pass with known
problems. We hope this will prevent introduction of questionable code in
all other directories or new packages.

See issue #392

Co-authored-by: Dmitry Kalinkin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant