[PATCH] D29003: [OptDiag] Split code region out of DiagnosticInfoOptimizationBase
Matthias Braun via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 25 11:07:59 PST 2017
MatzeB added inline comments.
================
Comment at: lib/Analysis/OptimizationDiagnosticInfo.cpp:157
if (Out) {
- auto *P = &const_cast<DiagnosticInfoOptimizationBase &>(OptDiag);
+ auto *P =
+ const_cast<DiagnosticInfoOptimizationCommonBase *>(&OptDiagCommon);
----------------
anemet wrote:
> MatzeB wrote:
> > anemet wrote:
> > > MatzeB wrote:
> > > > dito.
> > > Actually, this one needs to be a pointer because << requires an lvalue so we can't pass a temporary (&P).
> > I am pretty sure this is equivalent and taking the address of a reference variable does produce a pointer that can still be used when the reference variable is out of scope (as long as the referenced object is still around which is the case here):
> > ```
> > auto &P = const_cast<DiagnosticInfoOptimizationBase&>(OptDiagBase);
> > *out << &P;
> > ```
> I am pretty it's not ;) since that is what I tried. &P is an rvalue for a pointer type so we can't take a reference of it.
>
> Here is the actual error message:
> ```
> ../lib/Analysis/OptimizationDiagnosticInfo.cpp:161:10: error: invalid operands to binary expression ('yaml::Output' and 'llvm::DiagnosticInfoOptimizationBase *')
> *Out << &P;
> ~~~~ ^ ~~
> ../include/llvm/Support/YAMLTraits.h:1473:1: note: candidate function [with T = llvm::DiagnosticInfoOptimizationBase *] not viable: no known conversion from 'llvm::DiagnosticInfoOptimizationBase *' to 'llvm::DiagnosticInfoOptimizationBase *&' for 2nd argument
> ```
> Arguably, operator<< should take a reference not a pointer. I forgot why I used a pointer here.
operator<< needs an lvalue?!? Oh well, that is for another patch to clenaup/ complain about then.
https://reviews.llvm.org/D29003
More information about the llvm-commits
mailing list