mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 04:13:03 +00:00
For instance with GCC8:
616. regression.at:1560: testing Lex and parse params: glr2.cc ...
tests/regression.at:1560: COLUMNS=1000; export COLUMNS; NO_TERM_HYPERLINKS=1; export NO_TERM_HYPERLINKS; bison --color=no -fno-caret -o input.cc input.y
tests/regression.at:1560: $CXX $CXXFLAGS $CPPFLAGS $LDFLAGS -o input input.cc $LIBS
stderr:
input.cc: In member function 'YYRESULTTAG glr_stack::yyresolveValue(glr_state*)':
input.cc:1796:10: error: potential null pointer dereference [-Werror=null-dereference]
return yypred ? &(asItem(this) - yypred)->getState() : YY_NULLPTR;
^~~~~~
input.cc:1796:10: error: potential null pointer dereference [-Werror=null-dereference]
return yypred ? &(asItem(this) - yypred)->getState() : YY_NULLPTR;
^~~~~~
cc1plus: all warnings being treated as errors
It complains that the implicit this in yypred might be null. It fears
it because of loops such as
for (glr_state* yys = firstTopState();
yys != yystateStack.yysplitPoint;
yys = yys->pred())
yyn += 1;
that could possibly set yys to null, since yys->pred might return
null. However, the warning is incorrect, since in C++ `this` cannot
be null. GCC 10 no longer emits this warning.
GCC 7 also complains many times about glr_stack::yyresolveLocations
when NDEBUG is enabled (when it is not, YYASSERT (yyoption !=
YY_NULLPTR) is probably enough to pacify GCC):
616. regression.at:1560: testing Lex and parse params: glr2.cc ...
tests/regression.at:1560: COLUMNS=1000; export COLUMNS; NO_TERM_HYPERLINKS=1; export NO_TERM_HYPERLINKS; bison --color=no -fno-caret -o input.cc input.y
tests/regression.at:1560: $CXX $CXXFLAGS $CPPFLAGS $LDFLAGS -o input input.cc $LIBS
stderr:
input.cc: In member function 'void glr_stack::yyresolveLocations(glr_state*, int)':
input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
input.cc: In member function 'YYRESULTTAG glr_stack::yyresolveValue(glr_state*)':
input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
* data/skeletons/glr2.cc (YY_IGNORE_NULL_DEREFERENCE_BEGIN)
(YY_IGNORE_NULL_DEREFERENCE_BEGIN): New.
(glr_state::pred, glr_stack::yyresolveLocations): Use them.