Closed Brensom closed 1 year ago
Thank you. I am fairly certain that this is a spurious warning, where gcc/g++ isn't quite bright enough to follow the logic through to see that jupiter_loc[0...2]
really will be initialized. It does seem odd that it's not noticing that, by its logic, saturn_loc[0...2]
might also be uninitialized.
Does the following patch (which says "always copy Jupiter's location into jupiter_loc
, whether we're within the Galilean limits or not") cause the warnings/errors to go away?
@@ -1025,11 +1025,9 @@ int calc_derivativesl( const ldouble jd, const ldouble *ival, ldouble *oval,
if( i == IDX_JUPITER)
{
+ memcpy( jupiter_loc, planet_loc + 12, 3 * sizeof( double));
if( r < GALILEAN_LIMIT)
- {
- memcpy( jupiter_loc, planet_loc + 12, 3 * sizeof( double));
local_perturbers |= (15 << 11);
- }
else /* "throw" Galileans into Jupiter: */
mass_to_use = MASS_JUPITER_SYSTEM;
}
Failing that, we may just have to do a for( i = 0; i < 3; i++) jupiter_loc[i] = 0.;
redundant (and incorrect) initialization. But I'd prefer the above patch.
I've made the above patch (see commit aee89e961ed33d62d52b76daace662815edc50). I don't see that it does any harm, and may appease the compiler into not giving us spurious warnings... please let me know if I'm wrong about that.
I don't see any changes. I build from Master the latest version:
g++ -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fstack-clash-protection -fcf-protection -Wp,-D_GLIBCXX_ASSERTIONS -c -Wall -pedantic -Wextra -Werror -I ~/include -O3 miscell.cpp
runge.cpp: In function ‘int calc_derivativesl(long double, const long double*, long double*, int)’:
runge.cpp:993:28: error: ‘jupiter_loc[0]’ may be used uninitialized [-Werror=maybe-uninitialized]
993 | coord = jupiter_loc[j] + planet_loc[12 + j] * JUPITER_R;
| ^
runge.cpp:839:25: note: ‘jupiter_loc[0]’ was declared here
839 | double lunar_loc[3], jupiter_loc[3], saturn_loc[3];
| ^~~~~~~~~~~
runge.cpp:993:28: error: ‘jupiter_loc[1]’ may be used uninitialized [-Werror=maybe-uninitialized]
993 | coord = jupiter_loc[j] + planet_loc[12 + j] * JUPITER_R;
| ^
runge.cpp:839:25: note: ‘jupiter_loc[1]’ was declared here
839 | double lunar_loc[3], jupiter_loc[3], saturn_loc[3];
| ^~~~~~~~~~~
runge.cpp:993:28: error: ‘jupiter_loc[2]’ may be used uninitialized [-Werror=maybe-uninitialized]
993 | coord = jupiter_loc[j] + planet_loc[12 + j] * JUPITER_R;
| ^
runge.cpp:839:25: note: ‘jupiter_loc[2]’ was declared here
839 | double lunar_loc[3], jupiter_loc[3], saturn_loc[3];
| ^~~~~~~~~~~
g++ -o eph2tle eph2tle.o conv_ele.o elem2tle.o simplex.o lsquare.o -L ~/lib -lm -llunar -ljpl -lsatell
cc1plus: all warnings being treated as errors
make: *** [makefile:357: runge.o] Error 1
==> ERROR: A failure occurred in build().
The program is still not building...
Sorry, I'm still baffled by this one. For the nonce, I'd suggest adding these lines :
for( i = 0; i < 3; i++) /* redundant initialization */
jupiter_loc[i] = 0.; /* to avoid gcc-13 warning */
just above line 959 (if( perturbers)
.) This should do exactly what the comment suggests : tell gcc/g++-13 that those values really have been initialized.
If that fails, and/or if you encounter further such errors, I'd suggest doing the build with make -DNO_ERRORS
. This will cause the -Werror
flag to be dropped, and the error message will go back to being an "ordinary" warning.
I regard both of these as stopgap measures. At some point, I need to spin up a more bleeding-edge distro and compile with gcc/g++-13 (latest version I have is 12, which doesn't exhibit this behavior.)
Generally speaking, I'm a strong proponent of -Werror
. Some people complain that the compiler emits bogus warnings that are difficult to remove. I've mostly been able to dismiss such concerns. But this is one stubborn warning...
Please let me know what you find!
Building fails to me on the current version:
My building system: