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

fatal error: recursive template instantiation exceeded maximum depth of 256 #167

Open
sebt3 opened this issue Dec 17, 2016 · 7 comments
Open

Comments

@sebt3
Copy link

sebt3 commented Dec 17, 2016

Hi,

This is not exactly a Selene issue but a clang one. Most complier have a max depth of 1024, but clang set this way lower. and as Selene use template extensively, the 256 limit is fast to cross :

	state["p_serv"].SetObj(*p_serv,
		"addCollector",	&service::addCollector,
		"havePID",	&service::havePID,
		"getType",	&service::getType,
		"getSubType",	&service::getSubType,
		"getName",	&service::getName,
		"getID",	&service::getID,
		"setType",	&service::setType,
		"setSubType",	&service::setSubType,
		"setName",	&service::setName
	);

Trigger the error; remove a pair of argument and it compile fine.

The fix is to tell clang to behave like gcc on this with the compiler flags : "-ftemplate-depth=1024"

@sebt3
Copy link
Author

sebt3 commented Dec 17, 2016

Add this to the CMakeList.txt :

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth=1024")
endif()

@adam4813
Copy link
Contributor

adam4813 commented Jan 1, 2017

Selene is header only, so this change would need to be added to the project that includes selene. So perhaps adding this to the README would be most prudent.

@sebt3
Copy link
Author

sebt3 commented Jan 1, 2017

yet it ship with a CMakeList.txt file. This is the one that any user will have a look for his own as reference. So imho, it's the best place to document this. Well there and here in the Selene issue's lists as it's actually the 1rst place I gave a look to fix my issue :P

@adam4813
Copy link
Contributor

adam4813 commented Jan 1, 2017

Yes it is a good place to document it here.

@smt-pi
Copy link

smt-pi commented Mar 10, 2017

I've also run into this issue.

I would like to find a way to sequentially append functions to an object once it has already been registered within Selene, i.e. something equivalent to the following (using the original example code from above):

state["p_serv"].SetObj(*p_serv, "addCollector", &service::addCollector);
state["p_serv"].AppendObjMethod(*p_serv, "havePID",	&service::havePID);
...

The library is a bit beyond my current comprehension of C++ templates though. Any pointers or suggestions would be welcome, and I will try to implement.

@adam4813
Copy link
Contributor

adam4813 commented Mar 11, 2017

Couldn't you just assign it such as ["p_serv"]["addCollector"] = method; ? An object is just a table so to add new methods to an object you just add to its table.

At least that's my, limited, understanding.

@smt-pi
Copy link

smt-pi commented Mar 16, 2017

Thanks for the suggestion! That won't quite compile, but using the provided operator=(function<Ret(Args...)> fun) function will.
This may not be ideal for all scenarios, but in my case I'm defining special functions that I'm exposing to Lua anyway. I'm sure that other functions could be wrapped using std::function / std::bind if necessary.

So you can add as many methods as you want (well at least it compiles without increasing the stack depth now, whereas using the single function call it won't), by doing the following:

state["p_serv"].SetObj(*p_serv);
state["p_serv"]["addCollector"] = [&](float x) -> bool  {
...
};

state["p_serv"]["havePID"] = [&]() {
...
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants