https://bugs.llvm.org/show_bug.cgi?id=47640

            Bug ID: 47640
           Summary: -Wdangling-gsl only warns on initialization and not on
                    assignment
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected],
                    [email protected], [email protected]

-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 <string>
#include <string_view>
#include <memory>

std::string get_string();
std::unique_ptr<int> 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
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to