Skip to content

C++/CLI & Inconsistent layout information in duplicated types (std._Tree_unchecked_const_iterator) #1070

@fsb4000

Description

@fsb4000

Describe the bug
the linker error in Debug X64 mode:

error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std._Tree_unchecked_const_iterator< ?? :: ?? >): (0x02000048).
1>LINK : fatal error LNK1255: link failed because of metadata errors

Command-line test case

#include <msclr\marshal_cppstd.h >
#include <map>
using namespace System;

typedef std::map<int, msclr::gcroot<cli::array<short>^>> MapIntToManaged;

int main(array<System::String^>^ args)
{
    MapIntToManaged testMap;
    for (auto& it : testMap) {}

    return 0;
}

Expected behavior
Should compile and run without error in Debug X64 mode.

Actually, it works fine in both 32 and 64 bit, Debug and Release.

Second example:
Describe the bug
the linker error in X64 mode:

Command-line test case
(link to full project: https://developercommunity.visualstudio.com/storage/attachments/97364-link20222.zip)

#include <msclr\gcroot.h>
using namespace System;


namespace nativecplusplus {
	// from native c++ project
	class __declspec(dllimport) MyServer {
		// some methods and attributes
	};
}

namespace Link2002 {

	// from native c++ project
	class __declspec(dllimport) Server {
		// some methods and attributes
	};


	// clr project
	public ref class AxisSubsetDef {
	public:
		String^ SubsetHandle;
		array<array<String^>^>^ Excepts;
		String^ Parent;
		String^ Calculation;
		unsigned int ZeroSup;
		bool Hidden;
	};

	public enum class AxisType {
		Page = 0,
		Row = 1,
		Column = 2
	};

	public ref class Connection {
		// TODO: Add your methods for this class here.
	private:
		String^ ViewDefineAxisProxy(msclr::gcroot<String^> database, msclr::gcroot<AxisType> axisId, msclr::gcroot<array<AxisSubsetDef^>^> axisdefs, size_t start, size_t limit, msclr::gcroot<array<String^>^> properties);
		String^ ViewDefineAreaProxy(msclr::gcroot<String^> database, msclr::gcroot<String^> cube, msclr::gcroot<array<String^>^> axes, msclr::gcroot<array<String^>^> properties, bool ignorehidden);
	};

}
#include <functional>
#include <string>

using namespace nativecplusplus;
using namespace Link2002;

void ViewDefineAxisCore(MyServer* server, String^ database, AxisType axisId, array<AxisSubsetDef^>^ axisdefs, size_t start, size_t limit, array<String^>^ properties, std::string* handle) {
	// do the actual work
}

String^ Connection::ViewDefineAxisProxy(msclr::gcroot<String^> database, msclr::gcroot<AxisType> axisId, msclr::gcroot<array<AxisSubsetDef^>^> axisdefs, size_t start, size_t limit, msclr::gcroot<array<String^>^> properties) {
	auto ft1 = std::bind(&ViewDefineAxisCore, nullptr, database, axisId, axisdefs, start, limit, properties, std::placeholders::_1);
	return nullptr;
}

// ---

void ViewDefineAreaCore(Server* server, String^ database, String^ cube, array<String^>^ axes, array<String^>^ properties, bool ignorehidden, std::string* handle) {
	// do the actual work
}

String^ Connection::ViewDefineAreaProxy(msclr::gcroot<String^> database, msclr::gcroot<String^> cube, msclr::gcroot<array<String^>^> axes, msclr::gcroot<array<String^>^> properties, bool ignorehidden) {
	auto ft2 = std::bind(&ViewDefineAreaCore, nullptr, database, cube, axes, properties, ignorehidden, std::placeholders::_1);
	return nullptr;
}

Expected behavior
Should work in 64 bit and 32 bit.
Confirmed. 32 bit works, 64 bit failed:

Link2022.obj : error LNK2022: сбой операции с метаданными (8013118D): Несовместимые сведения о макетах в повторяющихся типах (std._Binder<std::_Unforced,void ,std::D::ar_traits,std::allocator<char> >): (0x02000067).
LINK : fatal error LNK1255: не удалось выполнить компоновку из-за ошибок в метаданных

STL version
Microsoft Visual Studio Community 2019
Version 16.6.4

Additional context
if I comment out one of the std::bind (ft1 or ft2) then compilation works in 64 mode too.

See more: VSO-643625 / AB#643625 | DevCom-279568

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingnot reproducibleWe can’t reproduce the described behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions