almost nobody is using the oox::AttributeList::get methods properly

Desktop / LibreOffice - Noel Grandin [collabora.co.uk] - 24 June 2022 08:40 UTC

Most of the call sites just ignore the fact that we are returning an optional value here. Which means that when an attribute is missing, they get an empty string or zero. And we seem to be fine with that.

So make a plugin that warns about calling value() on a temporay OptValue.

And add a utility method so we don't have to pay the cost of passing a default value to getString()

The need for this is driven by wanting to change to std::optional, which will throw an exception if code attempts to read an empty std::optional

Change-Id: Idb0a5ad1eac66b5caa93d6195928bad9e0b2ad70 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136283

08489c211a90 almost nobody is using the oox::AttributeList::get methods properly
compilerplugins/clang/optvalue.cxx | 66 +++++++++++++++++++
compilerplugins/clang/test/optvalue.cxx | 75 ++++++++++++++++++++++
include/oox/helper/attributelist.hxx | 3 +
oox/source/drawingml/connectorshapecontext.cxx | 12 ++--
oox/source/drawingml/customshapegeometry.cxx | 26 ++++----
oox/source/drawingml/diagram/datamodelcontext.cxx | 18 +++---
.../drawingml/diagram/diagramdefinitioncontext.cxx | 14 ++--
oox/source/drawingml/diagram/layoutnodecontext.cxx | 12 ++--
oox/source/drawingml/embeddedwavaudiofile.cxx | 4 +-
oox/source/drawingml/graphicshapecontext.cxx | 14 ++--
oox/source/drawingml/hyperlinkcontext.cxx | 8 +--
oox/source/drawingml/shapecontext.cxx | 8 +--
oox/source/drawingml/shapegroupcontext.cxx | 6 +-
oox/source/drawingml/table/tablecellcontext.cxx | 4 +-
oox/source/drawingml/table/tablecontext.cxx | 2 +-
oox/source/drawingml/table/tablerowcontext.cxx | 2 +-
oox/source/drawingml/table/tablestylecontext.cxx | 4 +-
.../table/tablestylelistfragmenthandler.cxx | 2 +-
oox/source/drawingml/textbodypropertiescontext.cxx | 2 +-
.../drawingml/textcharacterpropertiescontext.cxx | 6 +-
oox/source/drawingml/texteffectscontext.cxx | 2 +-
oox/source/drawingml/textfieldcontext.cxx | 4 +-
.../drawingml/textparagraphpropertiescontext.cxx | 12 ++--
oox/source/drawingml/textspacingcontext.cxx | 4 +-
oox/source/drawingml/texttabstoplistcontext.cxx | 2 +-
oox/source/drawingml/themeelementscontext.cxx | 4 +-
oox/source/drawingml/themefragmenthandler.cxx | 2 +-
oox/source/drawingml/transform2dcontext.cxx | 20 +++---
oox/source/helper/attributelist.cxx | 8 +++
oox/source/ppt/pptgraphicshapecontext.cxx | 6 +-
oox/source/ppt/pptshapecontext.cxx | 6 +-
oox/source/ppt/pptshapegroupcontext.cxx | 8 +--
oox/source/ppt/presPropsfragmenthandler.cxx | 4 +-
oox/source/shape/LockedCanvasContext.cxx | 4 +-
oox/source/vml/vmltextboxcontext.cxx | 4 +-
35 files changed, 265 insertions(+), 113 deletions(-)

Upstream: cgit.freedesktop.org


  • Share