New warning (or at least I only noticed it now)

Pavel Sanda sanda at lyx.org
Mon Nov 21 22:08:58 UTC 2022


On Mon, Nov 21, 2022 at 09:07:02PM +0000, José Matos wrote:
> I hope that this helps,
> -- 
> José Abílio

> /home/jamatos/lyx/lyx.anon/src/BufferView.cpp: In member function ???bool lyx::BufferView::needsFitCursor() const???:
> /home/jamatos/lyx/lyx.anon/src/BufferView.cpp:485:47: warning: possibly dangling reference to a temporary [-Wdangling-reference]
>   485 |                 frontend::FontMetrics const & fm =
>       |                                               ^~
> 
> /home/jamatos/lyx/lyx.anon/src/BufferView.cpp:486:39: note: the temporary was destroyed at the end of the full expression ???lyx::theFontMetrics((*(const lyx::FontInfo*)(&((lyx::BufferView::Private*)((const lyx::BufferView*)this)->lyx::BufferView::d)->lyx::BufferView::Private::cursor_.lyx::Cursor::getFont().lyx::Font::fontInfo())))???
>   486 |                         theFontMetrics(d->cursor_.getFont().fontInfo());
>       |                         ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Can you try whether the attached changes anything? P

-------------- next part --------------
diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 0bbf649796..bf1af74d71 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -482,8 +482,9 @@ void BufferView::setSearchRequestCache(docstring const & text)
 bool BufferView::needsFitCursor() const
 {
 	if (cursorStatus(d->cursor_) == CUR_INSIDE) {
+		Font tmpf = d->cursor_.getFont();
 		frontend::FontMetrics const & fm =
-			theFontMetrics(d->cursor_.getFont().fontInfo());
+			theFontMetrics(tmpf.fontInfo());
 		int const asc = fm.maxAscent();
 		int const des = fm.maxDescent();
 		Point const p = getPos(d->cursor_);


More information about the lyx-devel mailing list