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;
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:
When running, it outputs (0, 0), instead of what I would have thought, i.e (1, 0)
If I uncomment the line
auto pairs = ...
, then the result is changed, and the output becomes (33144464,0), although the variablepairs
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
add a comment |
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:
When running, it outputs (0, 0), instead of what I would have thought, i.e (1, 0)
If I uncomment the line
auto pairs = ...
, then the result is changed, and the output becomes (33144464,0), although the variablepairs
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
4
I suspect it’s becausevalues
has ceased to exist by the time you try to access it through the view.
– molbdnilo
Mar 22 at 22:25
add a comment |
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:
When running, it outputs (0, 0), instead of what I would have thought, i.e (1, 0)
If I uncomment the line
auto pairs = ...
, then the result is changed, and the output becomes (33144464,0), although the variablepairs
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
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:
When running, it outputs (0, 0), instead of what I would have thought, i.e (1, 0)
If I uncomment the line
auto pairs = ...
, then the result is changed, and the output becomes (33144464,0), although the variablepairs
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
c++ range-v3
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 becausevalues
has ceased to exist by the time you try to access it through the view.
– molbdnilo
Mar 22 at 22:25
add a comment |
4
I suspect it’s becausevalues
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
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered Mar 24 at 15:36
sv90sv90
30339
30339
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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