range-v3: strange BehaviorUndefined, unspecified and implementation-defined behaviorUndefined behavior and sequence pointsclang “hello, world!” link errors in windowsCan code that is valid in both C and C++ produce different behavior when compiled in each language?Strange definitions of TRUE and FALSE macrosHow do I write a range pipeline that uses temporary containers?Function works when not in namespace else it breaksranges of ranges to vector of vectorsWhen is a class member visible?Problem with stateful lambda - Microsoft Compiler Version 19.16.27024.1

What are the differences between credential stuffing and password spraying?

Purpose of のは in this sentence?

Using field size much larger than necessary

I need a disease

Verb "geeitet" in an old scientific text

Lie super algebra presentation of the Kähler identities

Can my company stop me from working overtime?

Do Maps have an Reliable Relationship between keySet() order and values() order?

What is the most remote airport from the center of the city it supposedly serves?

If your medical expenses exceed your income does the IRS pay you?

Can you complete the sequence?

Can there be a single technologically advanced nation, in a continent full of non-technologically advanced nations?

How should I tell my manager I'm not paying for an optional after work event I'm not going to?

Point of the the Dothraki's attack in GoT S8E3?

A mathematically illogical argument in the derivation of Hamilton's equation in Goldstein

What does a spell range of "25 ft. + 5 ft./2 levels" mean?

String won't reverse using reverse_copy

how to ban all connection to .se and .ru in the hosts.deny-file

If I readied a spell with the trigger "When I take damage", do I have to make a constitution saving throw to avoid losing Concentration?

Is this homebrew life-stealing melee cantrip unbalanced?

Hyperlink on red background

How do I tell my manager that his code review comment is wrong?

How can I get a job without pushing my family's income into a higher tax bracket?

In Avengers 1, why does Thanos need Loki?



range-v3: strange Behavior


Undefined, unspecified and implementation-defined behaviorUndefined behavior and sequence pointsclang “hello, world!” link errors in windowsCan code that is valid in both C and C++ produce different behavior when compiled in each language?Strange definitions of TRUE and FALSE macrosHow do I write a range pipeline that uses temporary containers?Function works when not in namespace else it breaksranges of ranges to vector of vectorsWhen is a class member visible?Problem with stateful lambda - Microsoft Compiler Version 19.16.27024.1






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I am trying to play with range-v3 and I encountered a problems : it does not extract values from a vector as I would have wanted.



See the code below:



  1. When running, it outputs (0, 0), instead of what I would have thought, i.e (1, 0)


  2. If I uncomment the line auto pairs = ..., then the result is changed, and the output becomes (33144464,0), although the variable pairs is unused (and the assert will fail)


#include <iostream>
#include <vector>
#include <range/v3/all.hpp>

auto foo()

auto values = std::vector<int> 1, 0 ;
// auto pairs = std::vector< std::pair<int, int> > 1, 0 , 0, 1 , 0, 0 ;

return ranges::view::for_each(values, [=](int nb)
);



int main()

ranges::for_each(foo(), [](auto v)
std::cout << v << "n";
);



This code was compiled with g++ (g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0) and clang++ (clang version 8.0.0 (tags/RELEASE_800/final)) with the following commands:



g++ foo.cpp -std=c++14 -Irange-v3/include -Wall -Wpedantic
clang++ foo.cpp -std=c++14 -Irange-v3/include -Wall -Wpedantic


I am using a fresh clone for ranges-v3, and I can reproduce this on ubuntu and OSX (with AppleClang).










share|improve this question



















  • 4





    I suspect it’s because values has ceased to exist by the time you try to access it through the view.

    – molbdnilo
    Mar 22 at 22:25

















1















I am trying to play with range-v3 and I encountered a problems : it does not extract values from a vector as I would have wanted.



See the code below:



  1. When running, it outputs (0, 0), instead of what I would have thought, i.e (1, 0)


  2. If I uncomment the line auto pairs = ..., then the result is changed, and the output becomes (33144464,0), although the variable pairs is unused (and the assert will fail)


#include <iostream>
#include <vector>
#include <range/v3/all.hpp>

auto foo()

auto values = std::vector<int> 1, 0 ;
// auto pairs = std::vector< std::pair<int, int> > 1, 0 , 0, 1 , 0, 0 ;

return ranges::view::for_each(values, [=](int nb)
);



int main()

ranges::for_each(foo(), [](auto v)
std::cout << v << "n";
);



This code was compiled with g++ (g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0) and clang++ (clang version 8.0.0 (tags/RELEASE_800/final)) with the following commands:



g++ foo.cpp -std=c++14 -Irange-v3/include -Wall -Wpedantic
clang++ foo.cpp -std=c++14 -Irange-v3/include -Wall -Wpedantic


I am using a fresh clone for ranges-v3, and I can reproduce this on ubuntu and OSX (with AppleClang).










share|improve this question



















  • 4





    I suspect it’s because values has ceased to exist by the time you try to access it through the view.

    – molbdnilo
    Mar 22 at 22:25













1












1








1


1






I am trying to play with range-v3 and I encountered a problems : it does not extract values from a vector as I would have wanted.



See the code below:



  1. When running, it outputs (0, 0), instead of what I would have thought, i.e (1, 0)


  2. If I uncomment the line auto pairs = ..., then the result is changed, and the output becomes (33144464,0), although the variable pairs is unused (and the assert will fail)


#include <iostream>
#include <vector>
#include <range/v3/all.hpp>

auto foo()

auto values = std::vector<int> 1, 0 ;
// auto pairs = std::vector< std::pair<int, int> > 1, 0 , 0, 1 , 0, 0 ;

return ranges::view::for_each(values, [=](int nb)
);



int main()

ranges::for_each(foo(), [](auto v)
std::cout << v << "n";
);



This code was compiled with g++ (g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0) and clang++ (clang version 8.0.0 (tags/RELEASE_800/final)) with the following commands:



g++ foo.cpp -std=c++14 -Irange-v3/include -Wall -Wpedantic
clang++ foo.cpp -std=c++14 -Irange-v3/include -Wall -Wpedantic


I am using a fresh clone for ranges-v3, and I can reproduce this on ubuntu and OSX (with AppleClang).










share|improve this question
















I am trying to play with range-v3 and I encountered a problems : it does not extract values from a vector as I would have wanted.



See the code below:



  1. When running, it outputs (0, 0), instead of what I would have thought, i.e (1, 0)


  2. If I uncomment the line auto pairs = ..., then the result is changed, and the output becomes (33144464,0), although the variable pairs is unused (and the assert will fail)


#include <iostream>
#include <vector>
#include <range/v3/all.hpp>

auto foo()

auto values = std::vector<int> 1, 0 ;
// auto pairs = std::vector< std::pair<int, int> > 1, 0 , 0, 1 , 0, 0 ;

return ranges::view::for_each(values, [=](int nb)
);



int main()

ranges::for_each(foo(), [](auto v)
std::cout << v << "n";
);



This code was compiled with g++ (g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0) and clang++ (clang version 8.0.0 (tags/RELEASE_800/final)) with the following commands:



g++ foo.cpp -std=c++14 -Irange-v3/include -Wall -Wpedantic
clang++ foo.cpp -std=c++14 -Irange-v3/include -Wall -Wpedantic


I am using a fresh clone for ranges-v3, and I can reproduce this on ubuntu and OSX (with AppleClang).







c++ range-v3






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 22:18







Pascal T.

















asked Mar 22 at 22:13









Pascal T.Pascal T.

2,01332529




2,01332529







  • 4





    I suspect it’s because values has ceased to exist by the time you try to access it through the view.

    – molbdnilo
    Mar 22 at 22:25












  • 4





    I suspect it’s because values has ceased to exist by the time you try to access it through the view.

    – molbdnilo
    Mar 22 at 22:25







4




4





I suspect it’s because values has ceased to exist by the time you try to access it through the view.

– molbdnilo
Mar 22 at 22:25





I suspect it’s because values has ceased to exist by the time you try to access it through the view.

– molbdnilo
Mar 22 at 22:25












1 Answer
1






active

oldest

votes


















0














There is a experimental feature coming in clang called -Wlifetime that can be used on godbolt. It gives the following warnings pointing to the return from foo.



[x86-64 clang (experimental -Wlifetime) #1] warning: returning a dangling Pointer [-Wlifetime]
[x86-64 clang (experimental -Wlifetime) #1] note: pointee 'values' left the scope here





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55308446%2frange-v3-strange-behavior%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    There is a experimental feature coming in clang called -Wlifetime that can be used on godbolt. It gives the following warnings pointing to the return from foo.



    [x86-64 clang (experimental -Wlifetime) #1] warning: returning a dangling Pointer [-Wlifetime]
    [x86-64 clang (experimental -Wlifetime) #1] note: pointee 'values' left the scope here





    share|improve this answer



























      0














      There is a experimental feature coming in clang called -Wlifetime that can be used on godbolt. It gives the following warnings pointing to the return from foo.



      [x86-64 clang (experimental -Wlifetime) #1] warning: returning a dangling Pointer [-Wlifetime]
      [x86-64 clang (experimental -Wlifetime) #1] note: pointee 'values' left the scope here





      share|improve this answer

























        0












        0








        0







        There is a experimental feature coming in clang called -Wlifetime that can be used on godbolt. It gives the following warnings pointing to the return from foo.



        [x86-64 clang (experimental -Wlifetime) #1] warning: returning a dangling Pointer [-Wlifetime]
        [x86-64 clang (experimental -Wlifetime) #1] note: pointee 'values' left the scope here





        share|improve this answer













        There is a experimental feature coming in clang called -Wlifetime that can be used on godbolt. It gives the following warnings pointing to the return from foo.



        [x86-64 clang (experimental -Wlifetime) #1] warning: returning a dangling Pointer [-Wlifetime]
        [x86-64 clang (experimental -Wlifetime) #1] note: pointee 'values' left the scope here






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 24 at 15:36









        sv90sv90

        30339




        30339





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55308446%2frange-v3-strange-behavior%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript