From ef27d71f436fc457a04eedf9e8f02b19390a38a2 Mon Sep 17 00:00:00 2001 From: Martchus Date: Thu, 8 Nov 2018 00:38:39 +0100 Subject: [PATCH] Fix multiple definition error caused by forward declarations --- CMakeLists.txt | 2 +- generator/serializationcodegenerator.cpp | 5 +++++ generator/tests/structs.h | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f5c326..076084f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ set(META_APP_CATEGORIES "Utility;") set(META_GUI_OPTIONAL false) set(META_VERSION_MAJOR 0) set(META_VERSION_MINOR 0) -set(META_VERSION_PATCH 6) +set(META_VERSION_PATCH 7) set(META_APP_VERSION ${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}) set(META_CXX_STANDARD 17) diff --git a/generator/serializationcodegenerator.cpp b/generator/serializationcodegenerator.cpp index 5134f11..b007c69 100644 --- a/generator/serializationcodegenerator.cpp +++ b/generator/serializationcodegenerator.cpp @@ -67,6 +67,11 @@ void SerializationCodeGenerator::addDeclaration(clang::Decl *decl) SerializationCodeGenerator::IsRelevant SerializationCodeGenerator::isQualifiedNameIfRelevant( clang::CXXRecordDecl *record, const std::string &qualifiedName) const { + // skip all classes which are only forward-declared + if (!record->isCompleteDefinition()) { + return IsRelevant::No; + } + // consider all classes for which a specialization of the "AdaptedJsonSerializable" struct is available for (const auto &adaptionRecord : m_adaptionRecords) { // skip all adaption records which are only included diff --git a/generator/tests/structs.h b/generator/tests/structs.h index eb4cf33..d16d16a 100644 --- a/generator/tests/structs.h +++ b/generator/tests/structs.h @@ -37,6 +37,11 @@ private: string privateString = "not going to be serialized"; }; +// forward declarations shouldn't cause the generator to emit the code multiple times +struct TestStruct; +struct TestStruct; +struct TestStruct; + class JsonGeneratorTests; /*!