Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Reference to temporary local variable not detected #91

Open
DoDoENT opened this issue Feb 10, 2020 · 1 comment
Open

Reference to temporary local variable not detected #91

DoDoENT opened this issue Feb 10, 2020 · 1 comment

Comments

@DoDoENT
Copy link

DoDoENT commented Feb 10, 2020

Consider this example:

#include <iostream>
#include <type_traits>
#include <vector>

class VectorHolder {
private:
    std::vector< int > vec_;
public:
    VectorHolder( std::vector< int > && vec ): vec_( std::move( vec ) ) {}
    auto const & vec() const { return vec_; }
};

template< typename ... T >
auto packToVector( T ... args ) requires ( std::is_same_v< T, int > && ... ) {
    return VectorHolder{ std::vector< int >{ args... } };
}

int main() {
    for ( auto i : packToVector( 1, 2, 3, 4, 5 ).vec() ) {
        std::cout << i << ' ';
    }
    return 0;
}

Should this bug be auto-detectable by -Wlifetime? Or it is required to annotate vec method with [[ gsl::post( lifetime, { this } ) ]] (AFAIK, this attribute is still not supported).

@Xazax-hun
Copy link
Collaborator

Unfortunately, members are partially supported at this point. Once it is fully implemented, I think this specific example should work without annotations. Thanks for reporting this!

The gsl::post annotation is also only partially supported at this point. Unfortunately, I have hard time to find time working on this lately.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants