g++ warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]

109 views
Skip to first unread message

Steffen Möller

unread,
Sep 4, 2019, 8:19:05 AM9/4/19
to last-...@googlegroups.com
Dear developers of LAST,

Thank you very much for your excellent work. With the very strict
compiler settings for Debian packaging, there is a warning raised that
you may decide to address:

g++ -Wdate-time -D_FORTIFY_SOURCE=2 -DHAS_CXX_THREADS -g -O2
-fdebug-prefix-map=/home/moeller/git/med-team/last-align/last-align=.
-fstack-protector-strong -Wformat -Werror=format-security -Wall -Wextra
-Wcast-qual -Wswitch-enum -Wundef -Wcast-align -Wno-long-long -ansi
-pedantic -std=c++11 -c -o alp/njn_localmaxstatutil.o
alp/njn_localmaxstatutil.cpp
In file included from alp/njn_matrix.hpp:43,
                 from alp/njn_localmaxstatutil.hpp:39,
                 from alp/njn_localmaxstatutil.cpp:37:
alp/njn_vector.hpp: In member function ‘virtual void
Njn::Vector<T>::free2()’:
alp/njn_vector.hpp:333:7: warning: this ‘if’ clause does not guard...
[-Wmisleading-indentation]
  333 |       if (getM () > 0) delete [] d_vector_p; d_vector_p = 0;
      |       ^~
alp/njn_vector.hpp:333:46: note: ...this statement, but the latter is
misleadingly indented as if it were guarded by the ‘if’
  333 |       if (getM () > 0) delete [] d_vector_p; d_vector_p = 0;
      |                                              ^~~~~~~~~~
In file included from alp/njn_localmaxstatutil.hpp:39,
                 from alp/njn_localmaxstatutil.cpp:37:
alp/njn_matrix.hpp: In member function ‘virtual void
Njn::Matrix<T>::free2()’:
alp/njn_matrix.hpp:600:9: warning: this ‘if’ clause does not guard...
[-Wmisleading-indentation]
  600 |         if (this->getM () > 0) delete [] d_matrix_p; d_matrix_p
= 0;
      |         ^~
alp/njn_matrix.hpp:600:54: note: ...this statement, but the latter is
misleadingly indented as if it were guarded by the ‘if’
  600 |         if (this->getM () > 0) delete [] d_matrix_p; d_matrix_p
= 0;
      | ^~~~~~~~~~


These header files are included from many source files, so the warnings
are also appearing multiple times. The indentiation suggests that the
assignment of 0 is only intended when the value is not 0 and the memory
was just deallocated, when for real the assignment of 0 is also
performed when the value is 0 already - if not optimized away by the
compiler.

So, while not a functional change, it would nonetheless just look nice
to avoid that warning - it is the only warnings in the whole code base,
nice work, indeed.

With kind regards,

Steffen Möller



Frith, Martin

unread,
Sep 8, 2019, 9:08:56 PM9/8/19
to Steffen Möller, last-align
Hi Steffen,

thanks for reporting this issue.

If it was my code, I'd fix it. But it's someone else's code, which is not only in LAST but also in the ALP package. Maybe it's better not to create a divergence between these codebases... not sure.

Have a nice day,
Martin


--
You received this message because you are subscribed to the Google Groups "last-align" group.
To unsubscribe from this group and stop receiving emails from it, send an email to last-align+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/last-align/80b72844-09ba-2014-b6ef-7d753cc56ef7%40gmail.com.

Reply all
Reply to author
Forward
0 new messages