Skip to content

-Wdangling-gsl only warns on initialization and not on assignment #46984

Closed as not planned
@Weverything

Description

@Weverything
Bugzilla Link 47640
Version trunk
OS Linux
CC @dwblaikie,@gribozavr,@mgehre,@zygoloid,@Xazax-hun

Extended Description

-Wdangling-gsl is a warning that catches dangling pointers. This warning catches a lot of lifetime bugs, but it only does so during initialization. Similar code that causes a dangling pointer during assignments does not get a warning.

#include
#include <string_view>
#include

std::string get_string();
std::unique_ptr get_int();

int main() {
std::string_view sv = get_string(); // Warning on initialization
sv = get_string(); // No warning on assignment

int *p = get_int().get(); // Warning on initialization
p = get_int().get(); // No warning on assignment
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaclang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerduplicateResolved as duplicate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions