The latest C++ API is in review right now - feel free to add your comments! Note that it contains multiple commits, some of which undo/modify earlier ones.
I think it’s safe to use the current C++ API (in release 9.1.11, SWI-cpp2.h)
I haven’t had the chance to review the code, but I know with the previous version the biggest bug-causing issue was unwanted implicit type conversion. Can you affirm that these don’t exist in the new API?
I also found implicit type conversions (and the casts) to be a problem, so I did what I could to minimize the issue. It’s not 100% safe – that would require making some changes to SWI-Prolog.h, which would require massive changes throughout the code … I did some exploratory changes (e.g. changing atom_t to a struct containing a uintptr_t) but it looks like several months of work (at least!) to do this and, it’s not clear what effect these changes would have on some compiler optimisations, so additional work would be needed to verify that the various compilers would behave as expected.
As an example of the safer API, there are a number of constructors for PlTerm (PlTerm_atom, PlTerm_var, PlTerm_integer, etc.) that avoid implicit conversions. I’ve also added [[deprecated]] annotations for the cast operators (and a few other operators and methods).
SWI-cpp2-plx.h has been added, to make the functions in SWI-Prolog.h and SWI-Stream.h less error-prone, by wrapping the functions with code thatches for exceptions and throws an appropriate PlException. In most cases, you won’t need to use these directly; they’re used by the methods in `SWI-cpp2.h.
If you sync to SWI-Prolog 9.1.9 or later, you should get everything except the blob support (which is awaiting review).