How to find/search for serialization functions when Cereal finds multiple candidates?

707 views
Skip to first unread message

Jacob Lorensen

unread,
Oct 2, 2015, 6:06:55 AM10/2/15
to cereal serialization library
After a branch merge I get

../../../../external/cereal/cereal-1.1.2/include/cereal/cereal.hpp:457:9: error: static assertion failed: cereal found more than one compatible output serialization function for the provided type and archive combination.

on one of my types (QString serialization).

I have an include file with a load_minimal and save_minimal for serilizing QStrings. As far as I can see, those are the ONLY template candidates for serializing QStrings in my code.

Yet, Cereal complains. So apparently if finds more than one. But which? Where? This is mystifying. Indeed, if I comment out my load_minimal/save_minimal for QStrings, I get the opposite error message:

../../../../external/cereal/cereal-1.1.2/include/cereal/cereal.hpp:821:9: error: static assertion failed: cereal could not find any input serialization functions for the provided type and archive combination.

This mystifies me... how the **** do I find out what's gone wrong?!?? Is there any way to improve the (already very nice, I must say!) error reporting from Cereal? Any way to make it tell me *which* conflicting functions it finds in the situation?

/Jacob

Jacob Lorensen

unread,
Oct 2, 2015, 10:08:46 AM10/2/15
to cereal serialization library
Yikes! Confusion it total. If I replace my load_minimal/save_minimal pair with a load/save pair, then Cereal does not complain and the program compiles flawlessly.

w.shan...@gmail.com

unread,
Oct 2, 2015, 9:00:03 PM10/2/15
to cereal serialization library
Hard to say without seeing some code here.  You can always try commenting out the static assertion that causes compilation to fail and the compiler will try to keep going and potentially give you a better indication of where things are going wrong.

Jacob Lorensen

unread,
Oct 5, 2015, 5:46:02 AM10/5/15
to cereal serialization library
Hi

Thanks for your answer. I have tried to comment out the static_assert, and these are my findings:

1) With load/save pair the code compiled with or without the static assertion, and i works: Nodes whose value are a QString are saved and loaded.

2) With a load_minimal/save_minimal pair, commenting the static_assert makes *the*code*compile*! No compiler error messages, just plain good compilation. Unfortunately, the code when run, does not serialize any of the nodes containing my QString values. The save_minimal/load_minimal methods are never called.

So this does not leave me with much to hunt for since I have no compiler errors. Sigh; I guess that's just template programming in a nutshell.

For the moment I will live with using save/load pair (it is after all merely a XML-cosmetic issue), but I'll hopefully return later for more debugging. I am going to have a hard time creating a smaller example that demonstrates the issue, since I have no clue as to where it comes from or why it is suddenly there: My save_minimal/load_minimal worked fine till I did a rebase, so something else somewhere else in the code base changed enough to confuse Ceral.

A short background on my program:

It is a port to Qt of an older Windows/MFC based program. Hence, the serialization code has been through a number of stages:
1) Port/reverse-engineer MFC serialization (so we can read old projects)
2) Change MFC's Serialize(...) virtual functions to templated functions and MFC's >> and << operators to "&" operator
3) add in Cereal headers and hope for the best (which actually turned out really well: The same templated C++ serialize() methods now work with our own reverse-engineered MFC-serializer and with Cereal archives. Very cool indeed!

So all in all - there *is* plenty of room for the overloaded operators, namespaces and whatnot to confuse the compiler (or the programmer to be honest)


On Friday, October 2, 2015 at 12:06:55 PM UTC+2, Jacob Lorensen wrote:
Reply all
Reply to author
Forward
0 new messages