Skip to content

[[gsl::Pointer]] does not diagnose dangling-through-function-call #111768

@pkasting

Description

@pkasting

Similar to issue #99685.

Trivial forwarding helpers defeat the compiler's ability to notice -Wdangling-gsl issues. For example:

#include <string>
#include <utility>

struct [[gsl::Pointer]] S {
  S(const std::string&);
};

template <typename T>
[[clang::always_inline]] S fwd(T&& t) {
  return S(std::forward<T>(t));
}

[[maybe_unused]] static void f() {
  [[maybe_unused]] S s1(std::string("123"));       // Marked dangling, yay!
  [[maybe_unused]] S s2(fwd(std::string("123")));  // Not marked dangling, boo :(
}

Live example: https://godbolt.org/z/T5q3zj6eo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerclang:temporal-safetyIssue/FR relating to the lifetime analysis in Clang (-Wdangling, -Wreturn-local-addr)

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions