Skip to content

Clang still doesn't catch dangling case of Container of pointer-like element #111680

@usx95

Description

@usx95

These cases are not caught by clang:

https://godbolt.org/z/E3dWds9o6

#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <vector>

std::string GetString() { return "foo"; }

void Test() {
    // Bad.
    std::set<std::string_view> s = {GetString(), GetString()};
    std::vector<std::string_view> v = {GetString(), GetString()};

    // Good.
    std::optional<std::string_view> t2 = GetString();  // warning here.
}

cc: @hokein
related bug which was closed: #100526

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions