Skip to content

[LifetimeSafety] False-positive for aliases to reference variable #169758

@usx95

Description

@usx95

https://godbolt.org/z/cGxozPYWj

#include <iostream>
#include <string>
#include <string_view>
#include <vector>

void foo() {
    std::vector<std::string> v;
    std::string_view view;
    for (const auto& s : v) {
        view = s; // warning: 's' does not live long enough.
    }
    (void)view; // note: later used here.
}

void bar(const std::string& s) {
    std::string_view view;
    {
        const std::string& ref = s; // 's' does not live long enough.
        view = ref;
    }
    (void)view; // later used here.
}

Metadata

Metadata

Assignees

Labels

clang:temporal-safetyIssue/FR relating to the lifetime analysis in Clang (-Wdangling, -Wreturn-local-addr)false-positiveWarning fires when it should not

Type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions