Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Weverything opened this issue Sep 25, 2020 · 1 comment
Closed

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

Weverything opened this issue Sep 25, 2020 · 1 comment
Labels
bugzilla Issues migrated from bugzilla clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer duplicate Resolved as duplicate

Comments

@Weverything
Copy link
Contributor

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
}

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@usx95
Copy link
Contributor

usx95 commented Jul 24, 2024

Duplicate #63310 is fixed now.

@usx95 usx95 closed this as completed Jul 24, 2024
@EugeneZelenko EugeneZelenko added duplicate Resolved as duplicate clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer and removed clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jul 24, 2024
@EugeneZelenko EugeneZelenko closed this as not planned Won't fix, can't repro, duplicate, stale Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer duplicate Resolved as duplicate
Projects
None yet
Development

No branches or pull requests

3 participants