Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CEREAL_REGISTER_POLYMORPHIC_RELATION fails to register relation under VS2015 #356

Closed
ChrisBFX opened this issue Nov 7, 2016 · 6 comments

Comments

@ChrisBFX
Copy link

ChrisBFX commented Nov 7, 2016

I get the "Trying to save a registered polymorphic type with an unregistered polymorphic cast. " exception when I want to serialize a base-class which has multiple derived classes, even when the relations are registered via CEREAL_REGISTER_POLYMORPHIC_RELATION.
It seems like PolymorphicVirtualCaster() doesn't registers all relations.

I also tested the develop branch which has the same behavior. (it works fine under gcc 4.9 though).

For testing I added:

CEREAL_REGISTER_TYPE(Base)
struct YourType2 : public YourType
{
	

	template<class Archive>
	void save(Archive & ar) const
	{
		std::cout << "Saving YourType2" << std::endl;
	}

	template<class Archive>
	void load(Archive & ar)
	{
		std::cout << "Loading YourType2" << std::endl;
	}
};

CEREAL_REGISTER_TYPE(YourType2)
CEREAL_REGISTER_POLYMORPHIC_RELATION(YourType, YourType2)


struct YourType3 : public YourType
{
	

	template<class Archive>
	void save(Archive & ar) const
	{
		std::cout << "Saving YourType3" << std::endl;
	}

	template<class Archive>
	void load(Archive & ar)
	{
		std::cout << "Loading YourType3" << std::endl;
	}
};

CEREAL_REGISTER_TYPE(YourType3)
CEREAL_REGISTER_POLYMORPHIC_RELATION(YourType, YourType3) 

to the rtti test, and saved instances of YourType2 and YourType3.

@AzothAmmo
Copy link
Contributor

You only see this behavior with MSVC 2015? I can't reproduce this with any version of clang or gcc under linux.

@ChrisBFX
Copy link
Author

ChrisBFX commented Nov 9, 2016

Yes, and the fun thing is it even works in MSVC2013.

@AzothAmmo
Copy link
Contributor

Quick update on this: I'll be able to make better progress on MSVC issues soon since we'll be dropping the boost requirement for building the unit tests, which was delaying a few things.

@AzothAmmo AzothAmmo added this to the v1.2.2 milestone Jan 27, 2017
@AzothAmmo
Copy link
Contributor

Blocking the next immediate release (1.2.2) until this is fixed.

@AzothAmmo
Copy link
Contributor

I've identified the cause of this error and will patch it soon. It should have actually been an error for other compilers as well, but we lucked out in the ordering of static initialization.

AzothAmmo added a commit that referenced this issue Feb 12, 2017
relates #356, still need final testing on MSVC
@AzothAmmo
Copy link
Contributor

Appveyor is still running but so far this looks good, I'm closing as fixed - let me know if the issue persists. I'll push this out as the next release within a few days.

headupinclouds added a commit to headupinclouds/cereal that referenced this issue Aug 15, 2017
commit aa891a4
Author: Shane Grant <[email protected]>
Date:   Mon Jun 26 13:42:08 2017 -0700

    Resolves USCiLab#414

commit fcef0da
Author: Shane Grant <[email protected]>
Date:   Fri May 5 11:37:12 2017 -0700

    Fix shadowing issue for USCiLab#401, recent osx compile issue re: USCiLab#354

commit 950aca4
Merge: ad90557 35a36af
Author: Shane Grant <[email protected]>
Date:   Fri May 5 11:09:34 2017 -0700

    Merge branch 'hoensr-xml-no-size-attributes' into develop

commit 35a36af
Author: Shane Grant <[email protected]>
Date:   Fri May 5 10:54:25 2017 -0700

    Standardize interface for options (xml)
    see USCiLab#401

commit ad90557
Merge: f031131 2ab15f7
Author: Shane Grant <[email protected]>
Date:   Wed May 3 11:39:02 2017 -0700

    Merge branch 'develop' of github.com:USCiLab/cereal into develop

commit f031131
Author: Shane Grant <[email protected]>
Date:   Wed May 3 11:38:35 2017 -0700

    modifications for g47 and comment out memory intensive testing

commit c4dcc8d
Merge: 68f56ee 676d329
Author: Shane Grant <[email protected]>
Date:   Wed May 3 11:11:08 2017 -0700

    Merge branch 'issue_354' into develop

    still needs more work but this is an improvement for now
    see USCiLab#354

commit 52b03d5
Author: Robin Hoens <[email protected]>
Date:   Mon Apr 10 17:13:39 2017 +0200

    Add option to turn off the size=dynamic attributes of lists

commit 2ab15f7
Merge: 68f56ee 7723503
Author: Shane Grant <[email protected]>
Date:   Tue Apr 11 16:17:51 2017 -0700

    Merge pull request USCiLab#397 from albertziegenhagel/issue_396

    Add remove_reference to determine whether template argument to BinaryData is const

commit 7723503
Author: Albert Ziegenhagel <[email protected]>
Date:   Tue Apr 11 10:32:55 2017 +0200

    Add remove_reference to determine whether template argument to BinaryData is const

commit 68f56ee
Author: Shane Grant <[email protected]>
Date:   Mon Apr 10 11:22:38 2017 -0700

    Remove undefined behavior, see USCiLab#390

commit 676d329
Author: Shane Grant <[email protected]>
Date:   Wed Feb 22 14:43:31 2017 -0800

    adventures in microoptimization USCiLab#354

commit 546fd9b
Author: Shane Grant <[email protected]>
Date:   Sun Feb 19 16:25:32 2017 -0800

    tinkering on USCiLab#354

commit 8b8f581
Author: Shane Grant <[email protected]>
Date:   Wed Feb 15 13:39:42 2017 -0800

    Fix macro for double comparison in unit test
    relates USCiLab#338

commit 51cbda5
Merge: 70c4420 e38d6fe
Author: Shane Grant <[email protected]>
Date:   Sun Feb 12 14:06:58 2017 -0800

    Merge branch 'develop' for release 1.2.2

commit e38d6fe
Author: Shane Grant <[email protected]>
Date:   Sun Feb 12 13:46:25 2017 -0800

    fix update doc script

commit 70c4420
Author: Shane Grant <[email protected]>
Date:   Sun Feb 12 00:25:30 2017 -0800

    Update README.md

    add appveyor badge

commit 2590f21
Author: Shane Grant <[email protected]>
Date:   Sat Feb 11 23:47:00 2017 -0800

    Properly use multimap for lookup in poly casting
    relates USCiLab#356, still need final testing on MSVC

commit a917374
Author: Shane Grant <[email protected]>
Date:   Wed Feb 8 10:47:02 2017 -0800

    size_type now specified by macro CEREAL_SIZE_TYPE
    resolves USCiLab#379

commit ee17db5
Merge: b827b95 f577fc4
Author: Shane Grant <[email protected]>
Date:   Mon Feb 6 22:51:29 2017 -0800

    Merge branch 'develop' of github.com:USCiLab/cereal into develop

commit b827b95
Author: Shane Grant <[email protected]>
Date:   Mon Feb 6 22:50:56 2017 -0800

    Fixes need for special MSVC case, see USCiLab#373

commit f577fc4
Author: Shane Grant <[email protected]>
Date:   Sun Feb 5 22:13:08 2017 -0800

    Turn on warnings as errors for MSVC, warning level to 3
    Can't do level 4 warnings yet - need to make an upstream change to doctest

commit fb6606d
Author: Shane Grant <[email protected]>
Date:   Sun Feb 5 18:13:37 2017 -0800

    Do not build coverage or valgrind for MSVC

commit a2d5a15
Merge: 4a92e29 e4d543d
Author: Shane Grant <[email protected]>
Date:   Fri Jan 27 10:29:51 2017 -0800

    Merge branch 'tusharpm-develop' into develop

    see USCiLab#373

    Still need to address why windows needed a modifcation to polymorphic test to compile

commit e4d543d
Author: Tushar Maheshwari <[email protected]>
Date:   Thu Jan 26 16:53:47 2017 +0530

    Fix merge issues

commit 2261fee
Author: Tushar Maheshwari <[email protected]>
Date:   Sun Dec 18 17:32:04 2016 +0530

    Pull requests to not increment build numbers

commit 4ff4db8
Author: Tushar Maheshwari <[email protected]>
Date:   Sun Dec 11 20:03:02 2016 +0530

    boost new version

commit 655696a
Author: Tushar Maheshwari <[email protected]>
Date:   Sun Dec 11 15:42:00 2016 +0530

    AppVeyor integration

commit df44243
Author: Tushar Maheshwari <[email protected]>
Date:   Sun Dec 11 01:01:10 2016 +0530

    Enable cross-platform portability test

    CMake fix 32-bit executable with generator Win64

commit 0a908bc
Author: Tushar Maheshwari <[email protected]>
Date:   Sat Dec 10 17:27:28 2016 +0530

    Make tests pass with Windows

commit 4a92e29
Author: Shane Grant <[email protected]>
Date:   Wed Jan 25 11:04:24 2017 -0800

    no longer need boost test in travis

commit a8e9963
Merge: 75e50ee 1d67d44
Author: Shane Grant <[email protected]>
Date:   Wed Jan 25 10:56:38 2017 -0800

    Merge branch 'develop_doctest' into develop

    see USCiLab#139

commit 75e50ee
Author: Shane Grant <[email protected]>
Date:   Mon Nov 28 13:48:46 2016 -0800

    remove old code from sandbox relates USCiLab#363

commit 507f97d
Author: Shane Grant <[email protected]>
Date:   Mon Nov 28 11:53:56 2016 -0800

    add -Wold-style-casts see USCiLab#363

commit f69ad7c
Author: Shane Grant <[email protected]>
Date:   Mon Nov 28 11:50:23 2016 -0800

    tab to space

commit d21b0c0
Merge: 29829c1 e63f08f
Author: Shane Grant <[email protected]>
Date:   Mon Nov 28 11:47:53 2016 -0800

    Merge branch 'laudrup-master' into develop
    see USCiLab#363

commit e63f08f
Author: Shane Grant <[email protected]>
Date:   Mon Nov 28 11:47:24 2016 -0800

    minor adjustments to casts, see comments on USCiLab#363

commit 29829c1
Merge: 9978e0c ad92746
Author: Shane Grant <[email protected]>
Date:   Mon Nov 28 10:41:27 2016 -0800

    Merge branch 'FlexCoreLib-doxygen_access_from_extern' into develop

    see USCiLab#365

commit ad92746
Author: Shane Grant <[email protected]>
Date:   Mon Nov 28 10:41:02 2016 -0800

    comment out obsolete doxygen

commit 9978e0c
Merge: 1edc5c6 6e71766
Author: Shane Grant <[email protected]>
Date:   Mon Nov 28 10:37:17 2016 -0800

    Merge pull request USCiLab#366 from headupinclouds/pr.is_loading.is_saving

    Add is_loading and is_saving values to cereal::{Input,Output}Archive

commit 1edc5c6
Merge: 72d7936 6086234
Author: Shane Grant <[email protected]>
Date:   Mon Nov 28 10:35:24 2016 -0800

    Merge pull request USCiLab#367 from tusharpm/develop

    Travis configuration updates

commit 6086234
Author: Tushar Maheshwari <[email protected]>
Date:   Sun Nov 27 13:57:26 2016 +0530

    Travis configuration updates
    - Switch to trusty container-based infrastructure for linux systems
    - Add a job to test with clang compiler (skips portability test)
    - Add a job to test on macOS with Xcode8

commit 6e71766
Author: David Hirvonen <[email protected]>
Date:   Sat Nov 26 12:31:56 2016 -0500

    Remove spurious character

commit 9376ca6
Author: Kasper Laudrup <[email protected]>
Date:   Wed Nov 23 01:34:53 2016 +0100

    Don't use C style casts

    Change C style casts to C++ static casts.

    This makes the code compile with the -Wold-style-cast warning enabled

commit 1d67d44
Author: Shane Grant <[email protected]>
Date:   Fri Nov 4 16:07:00 2016 -0700

    Removed boost_test as a requirement
    -Now build 32 bit unit tests if portability testing is enabled
    -No more boost+clang issues over std::string abi
    see USCiLab#139, USCiLab#123

commit 66528b6
Author: Shane Grant <[email protected]>
Date:   Fri Nov 4 15:51:57 2016 -0700

    last? conversions for USCiLab#139

commit 978b3b5
Author: Shane Grant <[email protected]>
Date:   Fri Nov 4 12:11:51 2016 -0700

    typo fix in comment USCiLab#139

commit 13ae560
Author: Shane Grant <[email protected]>
Date:   Fri Nov 4 12:10:24 2016 -0700

    more USCiLab#139

commit 07818f4
Author: Shane Grant <[email protected]>
Date:   Fri Nov 4 12:00:16 2016 -0700

    more USCiLab#139

commit b5e500d
Author: Shane Grant <[email protected]>
Date:   Wed Nov 2 16:32:35 2016 -0700

    more USCiLab#139

commit a6e59d7
Author: Shane Grant <[email protected]>
Date:   Wed Nov 2 13:38:33 2016 -0700

    more for USCiLab#139

commit cd46374
Author: Shane Grant <[email protected]>
Date:   Wed Nov 2 12:20:22 2016 -0700

    more converted for USCiLab#139

commit 38e1548
Author: Shane Grant <[email protected]>
Date:   Tue Nov 1 11:59:40 2016 -0700

    headers USCiLab#139

commit 15c7339
Author: Shane Grant <[email protected]>
Date:   Tue Nov 1 11:59:02 2016 -0700

    more conversions USCiLab#139

commit 928cd36
Author: Shane Grant <[email protected]>
Date:   Tue Nov 1 11:41:28 2016 -0700

    more conversions to CHECK_EQ
    see USCiLab#139

commit 0a262ec
Author: Shane Grant <[email protected]>
Date:   Tue Nov 1 11:36:22 2016 -0700

    More tests split, switch to CHECk_EQ over CHECK
    see USCiLab#139

commit 671999e
Author: Shane Grant <[email protected]>
Date:   Fri Oct 28 14:28:37 2016 -0700

    Initial progress on removing boost test and moving to doctest to better support modules

    relates USCiLab#123

commit a066808
Author: Caspar Kielwein <[email protected]>
Date:   Sun Oct 2 16:09:04 2016 +0200

    Add cereal.doxytags as tagfile to allow external projects to link to cereal documentation.

commit 3fb59db
Author: Caspar Kielwein <[email protected]>
Date:   Sun Oct 2 15:53:28 2016 +0200

    Build doxygen documentation with separate CMakeLists.

    Extracted CMakelists.txt to doc subdirectory.
    Changed paths in doxyfile.in and CMakeLists accordingly.
    added doc as subdirectory in main CMakeLists.txt.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants