lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] How to suppress this gcc-9 diagnostic?


From: Greg Chicares
Subject: [lmi] How to suppress this gcc-9 diagnostic?
Date: Wed, 29 Apr 2020 12:44:59 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0

A unit test (which has always worked) now fails to compile with
MinGW-w64 gcc-9.3 due to -Werror and -Wnull-dereference. I don't
see how this code can possibly dereference a null pointer. Vadim,
do you know a way to rewrite it so that it doesn't trigger this
warning?

Observed diagnostic, including full compiler command:

i686-w64-mingw32-g++ -MMD -MP -MT financial_test.o -MF financial_test.d  -c -I 
/opt/lmi/src/lmi -I /opt/lmi/src/lmi/tools/pete-2.1.1 -I 
/opt/lmi/local/gcc_i686-w64-mingw32/lib/wx/include/i686-w64-mingw32-msw-unicode-3.1
 -I /opt/lmi/local/include/wx-3.1 -I /opt/lmi/third_party/include -I 
/opt/lmi/third_party/src -I /opt/lmi/local/include -I 
/opt/lmi/local/include/libxml2 -DLMI_WX_NEW_USE_SO  -DLIBXML_USE_DLL -DSTRICT   
 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXMSW__ -D_FILE_OFFSET_BITS=64 
-DBOOST_NO_AUTO_PTR -DBOOST_STRICT_CONFIG -DBOOST_STATIC_ASSERT_HPP   
-fno-ms-extensions -frounding-math -std=c++17 -pedantic-errors -Werror -Wall 
-Walloc-zero -Walloca -Wcast-align -Wconversion -Wdangling-else 
-Wdeprecated-declarations -Wdisabled-optimization -Wdouble-promotion 
-Wduplicated-branches -Wduplicated-cond -Wextra -Wformat-nonliteral 
-Wformat-security -Wformat-signedness -Wformat-y2k -Wimport -Winit-self 
-Winvalid-pch -Wlogical-op -Wmissing-include-dirs -Wmultichar 
-Wnull-dereference -Wpacked -Wpointer-arith -Wredundant-decls -Wrestrict 
-Wshadow -Wsign-compare -Wstack-protector -Wswitch-enum -Wtrampolines -Wundef 
-Wunreachable-code -Wunused-macros -Wvector-operation-performance 
-Wwrite-strings -Wno-parentheses  -Wc++11-compat -Wc++14-compat -Wc++1z-compat 
-Wconditionally-supported -Wctor-dtor-privacy -Wdelete-non-virtual-dtor 
-Wdeprecated -Wnoexcept -Wnoexcept-type -Wnon-template-friend 
-Wnon-virtual-dtor -Woverloaded-virtual -Wpmf-conversions -Wregister -Wreorder 
-Wstrict-null-sentinel -Wsynth -Wuseless-cast  -Wcast-qual    
-D'BOOST_STATIC_ASSERT(A)=static_assert((A))'   -ggdb -O2 
-fno-omit-frame-pointer    /opt/lmi/src/lmi/financial_test.cpp 
-ofinancial_test.o
/opt/lmi/src/lmi/financial_test.cpp: In function ‘int test_main(int, char**)’:
/opt/lmi/src/lmi/financial_test.cpp:194:16: error: potential null pointer 
dereference [-Werror=null-dereference]
  194 |     accum_p[0] = p[0] * one_plus_i;
cc1plus: all warnings being treated as errors
make[2]: *** [/opt/lmi/src/lmi/workhorse.make:958: financial_test.o] Error 1

The code is:

    std::vector<double> p0(7);       // Payments.
[...]
    static double const one_plus_i = 1.0 + i;
    std::vector<double> accum_p(p.size());
    accum_p[0] = p[0] * one_plus_i;

AFAICT, if line 194 is reached, then both 'p0' and 'accum_p'
must be vectors with seven elements, so dereferencing their
first elements is valid.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]