diff options
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Sema/Sema.h | 3 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 8 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 24 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaInit.h | 6 |
4 files changed, 37 insertions, 4 deletions
diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h index a284803ed6b..5333684522a 100644 --- a/clang/lib/Sema/Sema.h +++ b/clang/lib/Sema/Sema.h @@ -4076,7 +4076,8 @@ public: bool DiagnoseAssignmentResult(AssignConvertType ConvTy, SourceLocation Loc, QualType DstType, QualType SrcType, - Expr *SrcExpr, AssignmentAction Action); + Expr *SrcExpr, AssignmentAction Action, + bool *Complained = 0); /// CheckAssignmentConstraints - Perform type checking for assignment, /// argument passing, variable initialization, and function return values. diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 265f44c999a..3621f70ffcb 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -7036,7 +7036,11 @@ static void MakeObjCStringLiteralFixItHint(Sema& SemaRef, QualType DstType, bool Sema::DiagnoseAssignmentResult(AssignConvertType ConvTy, SourceLocation Loc, QualType DstType, QualType SrcType, - Expr *SrcExpr, AssignmentAction Action) { + Expr *SrcExpr, AssignmentAction Action, + bool *Complained) { + if (Complained) + *Complained = false; + // Decode the result (notice that AST's are still created for extensions). bool isInvalid = false; unsigned DiagKind; @@ -7121,6 +7125,8 @@ bool Sema::DiagnoseAssignmentResult(AssignConvertType ConvTy, Diag(Loc, DiagKind) << FirstType << SecondType << Action << SrcExpr->getSourceRange() << Hint; + if (Complained) + *Complained = true; return isInvalid; } diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 6a9efbddbdf..eae5f63efa5 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -3308,6 +3308,20 @@ static Sema::OwningExprResult CopyObject(Sema &S, move_arg(ConstructorArgs)); } +void InitializationSequence::PrintInitLocationNote(Sema &S, + const InitializedEntity &Entity) { + if (Entity.getKind() == InitializedEntity::EK_Parameter && Entity.getDecl()) { + if (Entity.getDecl()->getLocation().isInvalid()) + return; + + if (Entity.getDecl()->getDeclName()) + S.Diag(Entity.getDecl()->getLocation(), diag::note_parameter_named_here) + << Entity.getDecl()->getDeclName(); + else + S.Diag(Entity.getDecl()->getLocation(), diag::note_parameter_here); + } +} + Action::OwningExprResult InitializationSequence::Perform(Sema &S, const InitializedEntity &Entity, @@ -3474,6 +3488,7 @@ InitializationSequence::Perform(Sema &S, S.Diag(Kind.getLocation(), diag::err_reference_bind_to_vector_element) << Entity.getType().isVolatileQualified() << CurInitExpr->getSourceRange(); + PrintInitLocationNote(S, Entity); return S.ExprError(); } @@ -3695,10 +3710,16 @@ InitializationSequence::Perform(Sema &S, == Sema::Compatible) ConvTy = Sema::Compatible; + bool Complained; if (S.DiagnoseAssignmentResult(ConvTy, Kind.getLocation(), Step->Type, SourceType, - CurInitExpr, getAssignmentAction(Entity))) + CurInitExpr, + getAssignmentAction(Entity), + &Complained)) { + PrintInitLocationNote(S, Entity); return S.ExprError(); + } else if (Complained) + PrintInitLocationNote(S, Entity); CurInit.release(); CurInit = S.Owned(CurInitExpr); @@ -3972,6 +3993,7 @@ bool InitializationSequence::Diagnose(Sema &S, break; } + PrintInitLocationNote(S, Entity); return true; } diff --git a/clang/lib/Sema/SemaInit.h b/clang/lib/Sema/SemaInit.h index ba11470d24a..5f2592fb77c 100644 --- a/clang/lib/Sema/SemaInit.h +++ b/clang/lib/Sema/SemaInit.h @@ -542,7 +542,11 @@ private: /// \brief The candidate set created when initialization failed. OverloadCandidateSet FailedCandidateSet; - + + /// \brief Prints a follow-up note that highlights the location of + /// the initialized entity, if it's remote. + void PrintInitLocationNote(Sema &S, const InitializedEntity &Entity); + public: /// \brief Try to perform initialization of the given entity, creating a /// record of the steps required to perform the initialization. |

