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
Why wasn't the Night King naked in S08E03?
Can Infinity Stones be retrieved more than once?
Can an isometry leave entropy invariant?
Shantae Dance Matching
Can a nothic's Weird Insight action discover secrets about a player character that the character doesn't know about themselves?
How to model the curly cable part of the phone
Why are prions in animal diets not destroyed by the digestive system?
As matter approaches a black hole, does it speed up?
Has a commercial or military jet bi-plane ever been manufactured?
Would Hubble Space Telescope improve black hole image observed by EHT if it joined array of telesopes?
String won't reverse using reverse_copy
Out of scope work duties and resignation
How does this change to the opportunity attack rule impact combat?
Why is Arya visibly scared in the library in S8E3?
What was the design of the Macintosh II's MMU replacement?
Getting a W on your transcript for grad school applications
Why do people keep telling me that I am a bad photographer?
What are the differences between credential stuffing and password spraying?
What does this colon mean? It is not labeling, it is not ternary operator
Pressure inside an infinite ocean?
Can there be a single technologically advanced nation, in a continent full of non-technologically advanced nations?
How do I overfit?
Fitch Proof Question
Does a card have a keyword if it has the same effect as said keyword?
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)
(nb == 1) );
return ranges::yield(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)
(nb == 1) );
return ranges::yield(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)
(nb == 1) );
return ranges::yield(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)
(nb == 1) );
return ranges::yield(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