This is an archive of the discontinued LLVM Phabricator instance.

Add Optional overload to DiagnosticBuilder operator <<
ClosedPublic

Authored by njames93 on Mar 5 2020, 4:02 PM.

Diff Detail

Event Timeline

njames93 created this revision.Mar 5 2020, 4:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 5 2020, 4:02 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
njames93 marked an inline comment as done.
njames93 added inline comments.
clang/include/clang/Basic/Diagnostic.h
1341

Should this be disabled on functions that pass format args to the diagnostic so it will only optionally add things FixIts, Notes, Ranges...?

What's the use case here?

What's the use case here?

Mainly syntactic sugar, If you have a function that maybe returns a FixItHint or SourceRange you can pass it directly to the DiagnosticBuilder.

What's the use case here?

Mainly syntactic sugar, If you have a function that maybe returns a FixItHint or SourceRange you can pass it directly to the DiagnosticBuilder.

This comes up with a fair amount of regularity, even just for things like printing a simple integer (consider optional attribute arguments, etc). However, it seems like we might want to express this via the format string so that we don't run into a situation where an unavailable optional argument changes the indexing in the case where it's not additional information like a source range or fixit.

I can see it being useful for fix-its and source ranges, however I have a concern about it accidentally eating arguments that were supposed to go into a format string. For that, I second Aaron's suggestion to implement an extension for format strings. If you don't want to do that far, I think adding specific overloads for optional fix-its and optional source ranges would work, and won't trigger in unexpected situations.

njames93 updated this revision to Diff 249121.Mar 9 2020, 8:55 AM
  • Removed template in favour of specific overloads

Is there any code we can cleanup as a result of adding these overloads? I would have expected to see some code changes justifying each additional overload, which would also give us test coverage for the changes.

Is there any code we can cleanup as a result of adding these overloads? I would have expected to see some code changes justifying each additional overload, which would also give us test coverage for the changes.

I planned to add usages in follow ups but I can add them here

njames93 updated this revision to Diff 249307.Mar 10 2020, 4:05 AM
  • Add usages, removed optional on arrayrefs
gribozavr2 accepted this revision.Mar 10 2020, 6:33 AM
gribozavr2 added inline comments.
clang/include/clang/Basic/Diagnostic.h
1298

s/;// (and in functions below as well)

This revision is now accepted and ready to land.Mar 10 2020, 6:33 AM
njames93 updated this revision to Diff 249361.Mar 10 2020, 6:41 AM
njames93 marked 2 inline comments as done.
  • remove unnecessary semi colons
This revision was automatically updated to reflect the committed changes.