qpdf 9.0.0 still does not use any C++-11 features, but I'm strongly
considering requiring a C++-11 compiler starting with qpdf 10. If this is
of interest to you, please continue reading. If you are concerned about
this, please let me know with a private reply. If you're use of qpdf is
just that you build it with a reasonably current compiler (anything from
the past 4 to 5 years) or use an OS package, then this is probably of no
concern to you. If you build qpdf on lots of exotic compilers, especially
really old ones, you might care.
Most major compilers have supported this for a few years now. Current
versions of Microsoft Visual C++ and gcc support C++-14 by default without
any special flags. In preparing qpdf 9.0.0, I did a lot of work fixing up
integer conversions and arithmetic so that qpdf builds warning-free with
additional integer type warnings enabled. This is good from a security
standpoint and also reduces the (low) risk of silent data loss on very
large files. It would have been much easier to do this with c++-11 and, in
fact, I ended up re-implementing parts of <type_traits>. There would be
other benefits to supporting C++-11: migration from PointerHolder to
std::shared_ptr, use of more efficient std::unique_ptr internally in some
places, possibly using std::function and supporting lambdas as alternatives
to callback and handler classes that are common in qpdf's interface, and
lots of internal changes that just improve readability and maintainability
of the code, such as use of the "auto" keyword. Also, there have been many
times when I have avoided a change because of concerns about breaking
thread safety, and using c++ standard library threading constructs, I could
potentially solve some of those issues in a portable way. It's been at
least 5 years since most mainstream compilers had decent c++-11 support, so
I think it's reasonable to just say it's time to move. I know there are
some people out there who build qpdf with older, more limited compilers,
and I know this change would make life more difficult for those people, so
I am not taking the decision lightly.
I have a c++-11 feature test file that exercises the parts of c++-11 I want
to be able to use, and I have a branch that I have run through CI to ensure
that it works on all the platforms I build for. I am happy to share this,
or you can find it (subject to change) at
https://github.com/jberkenbilt/qpdf/blob/c%2B%2B11/libtests/cxx11.cc. This
branch also has a re-implementation of PointerHolder that uses
std::shared_ptr under the covers and is bidrectionally convertible to
std::shared_ptr. With this change, it would be possible for people to just
start using std::shared_ptr in their own code and still interoperate with
qpdf PointerHolders. A more radical possibility would be for me to actually
replace PointerHolder with std::shared_ptr everywhere in the API. For
backward compatibility, people could still include <qpdf/PointerHolder.hh>
and it would usually work with no changes to the source code. I've done
some experiments with this, and it's pretty smooth. The main places where
it breaks are that PointerHolder has an automatic constructor for bare
pointers where std::shared_ptr does not, so it breaks to just pass a raw
pointer in where a std::shared_ptr is expected, but this is easily fixed by
either wrapping the pointer in an explicit std::shared_ptr constructor or
by using std::make_shared. Also, while PointerHolder can automatically
convert to std::shared_ptr, containers of PointerHolder don't automatically
map. If you're still reading, I'm interested to know whether you think the
benefits of replacing PointerHolder with std::shared_ptr in qpdf's API are
sufficiently high to make migration to qpdf 10 require some source-level
changes, or whether we should live with PointerHolder forever. I'm on the
fence about this one. I think qpdf's interface would be improved by using
standard library smart pointers, but I have also taken pains not to break
source compatibility except when absolutely necessary, such as removing a
method that never worked right in the first place.
If you're interested in my other thoughts about C++-11, look at the section
of https://github.com/jberkenbilt/qpdf/blob/master/TODO where I discuss it.
I'm interested in any thoughts my developers might have. Either way, there
most likely won't be a qpdf 10 for some time. Unless something forces me to
break ABI, qpdf 9 should be around a while. But next time I am forced to
break ABI, or if I have to fix something that really would be much easier
using C++-11, then I will make a decision.
Still reading? Thanks!
--Jay
|