From 8b433edc4e0b163b66f6c743bfcfea56a2e81be6 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 10 Aug 2015 17:55:31 +0200 Subject: added checks to prevent the self assignment --- SourceLocation.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/SourceLocation.h b/SourceLocation.h index 35e3c031..b8b57b60 100644 --- a/SourceLocation.h +++ b/SourceLocation.h @@ -41,8 +41,21 @@ struct SourceLocation SourceLocation(): start(-1), end(-1) { } SourceLocation(SourceLocation const& _other): - start(_other.start), end(_other.end), sourceName(_other.sourceName) {} - SourceLocation& operator=(SourceLocation const& _other) { start = _other.start; end = _other.end; sourceName = _other.sourceName; return *this;} + start(_other.start), + end(_other.end), + sourceName(_other.sourceName) + {} + + SourceLocation& operator=(SourceLocation const& _other) + { + if (&_other == this) + return *this; + + start = _other.start; + end = _other.end; + sourceName = _other.sourceName; + return *this; + } bool operator==(SourceLocation const& _other) const { return start == _other.start && end == _other.end;} bool operator!=(SourceLocation const& _other) const { return !operator==(_other); } -- cgit