lmi
[Top][All Lists]
Advanced

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

Re: [lmi] xmlwrapp-0.8.1 '-Wcast-qual' warning


From: Vadim Zeitlin
Subject: Re: [lmi] xmlwrapp-0.8.1 '-Wcast-qual' warning
Date: Mon, 2 Oct 2017 13:40:10 +0200

On Sun, 1 Oct 2017 15:17:10 +0000 Greg Chicares <address@hidden> wrote:

GC> Compiling xmlwrapp-0.8.1 with '-Wcast-qual' I see:
GC> 
GC> /opt/lmi/third_party/src/libxml/node.cxx: In member function ‘void 
xml::node::set_namespace(const string&)’:
GC> /opt/lmi/third_party/src/libxml/node.cxx:592:36: error: cast from type 
‘const xmlChar* {aka const unsigned char*}’ to type ‘void*’ casts away 
qualifiers [-Werror=cast-qual]
GC>                  xmlFree((void*)ns->href);
GC>                                     ^~~~
GC> 
GC> I didn't dig through the typedefs to find where that becomes const,

 This seems to have been the case since "always", at least git blame shows
that the "const" was already there in 260a68fd34302f352aa8f4c2f2901cefa3e1d2f7
dating from 1998-08-13 and I didn't waste time looking further back...

GC> but the coarse patch below does prevent the warning, so I'll add
GC> it to the lmi repository:
GC> 
GC> diff --recursive '--unified=3' original/xmlwrapp-0.8.1/src/libxml/node.cxx 
modified/xmlwrapp-0.8.1/src/libxml/node.cxx
GC> --- original/xmlwrapp-0.8.1/src/libxml/node.cxx 2016-12-11 
14:28:47.000000000 +0000
GC> +++ modified/xmlwrapp-0.8.1/src/libxml/node.cxx 2017-09-30 
21:50:56.765557364 +0000
GC> @@ -589,7 +589,7 @@
GC>          {
GC>              if ( ns->prefix == NULL )
GC>              {
GC> -                xmlFree((void*)ns->href);
GC> +                xmlFree((void*)const_cast<xmlChar*>(ns->href));
GC>                  ns->href = xmlStrdup(xmlHref);
GC>                  break;
GC>              }

 The real problem seems to be using C style cast for casting away
constness in the first place, so I'd rather replace it as shown by

https://github.com/vslavik/xmlwrapp/pull/41/commits/bb7baa18800c1c2bcb7281a1a8a435f80f59ab97

 I'll also enable the use of -Wcast-qual for xmlwrapp compilation to ensure
that no other such problems appear in the future.

 Thanks for reporting this one,
VZ


reply via email to

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