Fix dangling references, found by GCC 13

Lifetime extension via const-ref only applies to functions that return
by value. For those that already return by reference (such as
QList::constLast()), no extension happens and we end up with a dangling
reference.

cmakebuildconfiguration.cpp:1473:25: warning: possibly dangling reference to a temporary [-Wdangling-reference]
cmakebuildconfiguration.cpp:1473:61: note: the temporary was destroyed at the end of the full expression ‘ProjectExplorer::BuildStepList::steps() const().QList<ProjectExplorer::BuildStep*>::constLast()’

Change-Id: I3b169860d8bd41e9be6bfffd1757167b7348be9b
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
This commit is contained in:
Thiago Macieira
2023-04-18 09:54:27 -07:00
parent 0e3089314b
commit d1d893f098
4 changed files with 5 additions and 5 deletions

View File

@@ -1476,7 +1476,7 @@ CMakeBuildConfiguration::CMakeBuildConfiguration(Target *target, Id id)
// Android magic: // Android magic:
if (DeviceTypeKitAspect::deviceTypeId(k) == Android::Constants::ANDROID_DEVICE_TYPE) { if (DeviceTypeKitAspect::deviceTypeId(k) == Android::Constants::ANDROID_DEVICE_TYPE) {
buildSteps()->appendStep(Android::Constants::ANDROID_BUILD_APK_ID); buildSteps()->appendStep(Android::Constants::ANDROID_BUILD_APK_ID);
const auto &bs = buildSteps()->steps().constLast(); const auto bs = buildSteps()->steps().constLast();
cmd.addArg("-DANDROID_PLATFORM:STRING=" cmd.addArg("-DANDROID_PLATFORM:STRING="
+ bs->data(Android::Constants::AndroidNdkPlatform).toString()); + bs->data(Android::Constants::AndroidNdkPlatform).toString());
auto ndkLocation = bs->data(Android::Constants::NdkLocation).value<FilePath>(); auto ndkLocation = bs->data(Android::Constants::NdkLocation).value<FilePath>();

View File

@@ -2905,9 +2905,9 @@ void TextEditorWidget::insertCodeSnippet(const QTextCursor &cursor_arg,
d->m_document->autoIndent(cursor); d->m_document->autoIndent(cursor);
cursor.endEditBlock(); cursor.endEditBlock();
const QColor &occurrencesColor const QColor occurrencesColor
= textDocument()->fontSettings().toTextCharFormat(C_OCCURRENCES).background().color(); = textDocument()->fontSettings().toTextCharFormat(C_OCCURRENCES).background().color();
const QColor &renameColor const QColor renameColor
= textDocument()->fontSettings().toTextCharFormat(C_OCCURRENCES_RENAME).background().color(); = textDocument()->fontSettings().toTextCharFormat(C_OCCURRENCES_RENAME).background().color();
for (const CursorPart &part : cursorParts) { for (const CursorPart &part : cursorParts) {

View File

@@ -132,7 +132,7 @@ void TextMark::paintAnnotation(QPainter &painter,
const QColor &markColor = annotationColor(); const QColor &markColor = annotationColor();
const FontSettings &fontSettings = m_baseTextDocument->fontSettings(); const FontSettings &fontSettings = m_baseTextDocument->fontSettings();
const AnnotationColors &colors = AnnotationColors::getAnnotationColors( const AnnotationColors colors = AnnotationColors::getAnnotationColors(
markColor.isValid() ? markColor : painter.pen().color(), markColor.isValid() ? markColor : painter.pen().color(),
fontSettings.toTextCharFormat(C_TEXT).background().color()); fontSettings.toTextCharFormat(C_TEXT).background().color());

View File

@@ -155,7 +155,7 @@ void FunctionGraphicsItem::paint(QPainter *painter,
painter->save(); painter->save();
QRectF rect = this->rect(); QRectF rect = this->rect();
const QColor &color = brush().color(); const QColor color = brush().color();
if (option->state & QStyle::State_Selected) { if (option->state & QStyle::State_Selected) {
QLinearGradient gradient(0, 0, rect.width(), 0); QLinearGradient gradient(0, 0, rect.width(), 0);
gradient.setColorAt(0, color.darker(100)); gradient.setColorAt(0, color.darker(100));