When I compiled the latest release (v1.2.0) I got some interesting warnings:
/opt/Workspace/ClangBuildAnalyzer/src/BuildEvents.cpp:55:26: warning: format ‘%i’ expects argument of type ‘int’, but argument 3 has type ‘BuildEventType’ [-Wformat=]
55 | printf("%4zi: t=%i t1=%7llu t2=%7llu par=%4i ch=%4zi det=%s\n", i, event.type, event.ts, event.ts+event.dur, event.parent.idx, event.children.size(), std::string(names[event.detailIndex].substr(0,130)).c_str());
| ~^ ~~~~~~~~~~
| | |
| int BuildEventType
/opt/Workspace/ClangBuildAnalyzer/src/BuildEvents.cpp:55:35: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 4 has type ‘int64_t’ {aka ‘long int’} [-Wformat=]
55 | printf("%4zi: t=%i t1=%7llu t2=%7llu par=%4i ch=%4zi det=%s\n", i, event.type, event.ts, event.ts+event.dur, event.parent.idx, event.children.size(), std::string(names[event.detailIndex].substr(0,130)).c_str());
| ~~~~^ ~~~~~~~~
| | |
| long long unsigned int int64_t {aka long int}
| %7lu
/opt/Workspace/ClangBuildAnalyzer/src/BuildEvents.cpp:55:44: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 5 has type ‘long int’ [-Wformat=]
55 | printf("%4zi: t=%i t1=%7llu t2=%7llu par=%4i ch=%4zi det=%s\n", i, event.type, event.ts, event.ts+event.dur, event.parent.idx, event.children.size(), std::string(names[event.detailIndex].substr(0,130)).c_str());
| ~~~~^ ~~~~~~~~~~~~~~~~~~
| | |
| long long unsigned int long int
| %7lu
How about using "{fmt}" for such formatted output? It might be overhead though to add another external library just for it.
At least warnings can be fixed if instead of inlining all args, we declare constants for all of them with types that was declared in prrintf:
const auto eventType = static_cast<int>(event.type); // %i
const auto t1 = static_cast<long long unsigned int>(event.ts); // %7llu
const auto t2 = static_cast<long long unsigned int>(event.ts+event.dur); // %7llu
const auto par = static_cast<int>(event.parent.idx); // %4i
const auto ch = static_cast<size_t>(event.children.size());
const auto det = std::string(names[event.detailIndex].substr(0,130)); // %s
printf("%4zi: t=%i t1=%7llu t2=%7llu par=%4i ch=%4zi det=%s\n", i, eventType, t1, t2, par, ch, det.c_str());
When I compiled the latest release (v1.2.0) I got some interesting warnings:
How about using "{fmt}" for such formatted output? It might be overhead though to add another external library just for it. At least warnings can be fixed if instead of inlining all args, we declare constants for all of them with types that was declared in prrintf: