This is an archive of the discontinued LLVM Phabricator instance.

Make [Sema]DiagnosticBuilder move-only, instead of having a sneaky mutating copy ctor.
Needs ReviewPublic

Authored by dblaikie on Aug 18 2015, 6:28 PM.

Details

Reviewers
rsmith
Summary

While there wasn't much use of "return Diag(...) << x" outside Sema (one
each in ARCMigrate, Lex, Parse, and 5 in ClangTidy - which were all just
changed to use named local variables, then stream, then return), in Sema
there were quite a few uses. So this extends Sema::Diag to be a variadic
template allowing the extra parameters to be passed directly rather than
via streaming on the resulting temporary expression.

Diff Detail

Event Timeline

dblaikie updated this revision to Diff 32490.Aug 18 2015, 6:28 PM
dblaikie retitled this revision from to Make [Sema]DiagnosticBuilder move-only, instead of having a sneaky mutating copy ctor..
dblaikie updated this object.
dblaikie added a reviewer: rsmith.
dblaikie added a subscriber: cfe-commits.
rsmith added inline comments.Aug 18 2015, 6:35 PM
include/clang/Basic/Diagnostic.h
935–936

Comment is out of date.

include/clang/Sema/Sema.h
1082–1096

If we only need to support value category preservation for SemaDiagnosticBuilder, can we duplicate this template for the SemaDiagnosticBuilder &&operator<<(SemaDiagnosticBuilder &&Diag, const T &Value) case?

lib/Parse/Parser.cpp
163–172

This one might be more readable as

DiagnosticBuilder DB = std::move(Spelling ? ... : ...);

Thoughts?

dblaikie updated this revision to Diff 32495.Aug 18 2015, 8:28 PM
dblaikie marked 2 inline comments as done.

Addressed Richard's code review feedback

include/clang/Basic/Diagnostic.h
935–936

Updated the wording a bit - the scare quotes and somewhat-vague "neuter" seemed unhelpful. Hopefully my rephrasing is an improvement, but I can restore the old or alternate wording if you prefer.

include/clang/Sema/Sema.h
1082–1096

Ah, good idea - that seems to totally work and removes the need for all the mechanical changes. (the handful of non-Sema diag cleanups in a few places (including clang-tidy) remain)

lib/Parse/Parser.cpp
163–172

Tried a few things here (move inside or outside the conditional operator) and none of it works. op<< takes its first arg by const ref (so that it can successfully take a temporary) and then returns it by const ref too - so we'd have to cast away constness before we could move from it.

Thoughts? Alternative approaches?