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

Empty brackets in uml dumper extension #457

Open
dagophil opened this issue Jan 22, 2020 · 1 comment
Open

Empty brackets in uml dumper extension #457

dagophil opened this issue Jan 22, 2020 · 1 comment

Comments

@dagophil
Copy link

The uml dumper extension seems to write empty brackets [] for unnamed arguments. Take a look at the following object tree:

#include "di.hpp"
#include "uml_dumper.hpp"

struct MyLogger {};

struct App {
	App(MyLogger&) {}
};

int main() {
	auto const injector = boost::di::make_injector<boost::di::extension::uml_dumper>();
	auto app = injector.create<App>();
}

Expected Behavior

The uml dumper should print the following output (no empty brackets []):

@startuml uml_dumper.png
"struct App" .. "struct MyLogger"
@enduml

Actual Behavior

The uml dumper does write empty brackets:

@startuml uml_dumper.png
"struct App" .. "struct MyLogger []"
@enduml

Steps to Reproduce the Problem

Run the code from above.

Specifications

  • Version: Latest in branch cpp14 (commit cb065b2)
  • Platform: Windows, Visual Studio 2017
@dagophil
Copy link
Author

The cause of the problem seems to be this line in uml_dumper.hpp:
https://github.com/boost-experimental/di/blob/cb065b20bf846642c229485492a9e0af66ef8748/extension/include/boost/di/extension/policies/uml_dumper.hpp#L43-L44

For unnamed arguments, the code (*(name*)(0))() calls operator() of the no_name placeholder, which returns an empty string "":
https://github.com/boost-experimental/di/blob/cb065b20bf846642c229485492a9e0af66ef8748/include/boost/di.hpp#L292-L294

This means that the code in uml_dumper.hpp resolves to something like this:

char const* const n = "";
[...] << (n ? std::string(" [") + n + std::string("]") : "") << [...]

The n? checks whether n is a nullptr. I think here, one must instead check that n is not empty. One could, for example, copy n into some std::string.

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

1 participant