Mutli-line bug report

Is there an easy way to generate a multi-line diagnostic in the static analysis engine where one could say that a bad thing is being done *here*, but it was caused by the thing you did *here* where they can be on different lines? Thanks.

  - jim

I think the way this is usually done is by emitting two diagnostics.
See for example this error when you redefine a function:

test.cc:14:6: error: functions that differ only in their return type
cannot be overloaded
void g() {}
     ^
test.cc:12:5: note: previous definition is here
int g() {}
    ^
2 errors

Nico

Jim was talking about the static analyzer, not the compiler. The analyzer is capable of emitting diagnostics that span a path.

The analyzer actually generates diagnostics that span an entire path. What you see get emitted on the command line is only the final diagnostic, and it is there for debugging purposes. The real output of the analyzer is either via the HTML reports (via scan-build) or the plist reports (which is currently consumed by Xcode, but could easily be consumed by other clients).

Currently it is not as easy as it should be to generate full path diagnostics, but it is possible. A good example is in CFRefCount.cpp, which is the Objective-C retain/release checker. It generates diagnostics such as "retain count incremented" on one line followed by something like "leak occurred here" on another. In the UI, this is rendered as an annotated path, that shows the branches taken to trigger the issue as well as the extra diagnostics from the checker. The diagnostics are represented by PathDiagnosticEvents, which are packed inside a single PathDiagnostic. PathDiagnostics are generated by the BugReporter object in conjunction with the checker. Once they are generated, they are sent over to a PathDiagnosticClient, which renders them.