How to return && object from function? [duplicate]





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}








7
















This question already has an answer here:




  • C++11 rvalues and move semantics confusion (return statement)

    6 answers




I have TTempTable class with move symantics. I wrote



TTempTable&& MyFunction() {
TTempTable tmp = f(...);
...
return std::move(tmp);
}


and got no compiler errors.



Was this correct?










share|improve this question
















marked as duplicate by Ben Voigt c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
May 28 at 0:50


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • 1





    Have a look at this rule in the C++ Core Guidelines

    – GPhilo
    May 27 at 12:56


















7
















This question already has an answer here:




  • C++11 rvalues and move semantics confusion (return statement)

    6 answers




I have TTempTable class with move symantics. I wrote



TTempTable&& MyFunction() {
TTempTable tmp = f(...);
...
return std::move(tmp);
}


and got no compiler errors.



Was this correct?










share|improve this question
















marked as duplicate by Ben Voigt c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
May 28 at 0:50


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • 1





    Have a look at this rule in the C++ Core Guidelines

    – GPhilo
    May 27 at 12:56














7












7








7


1







This question already has an answer here:




  • C++11 rvalues and move semantics confusion (return statement)

    6 answers




I have TTempTable class with move symantics. I wrote



TTempTable&& MyFunction() {
TTempTable tmp = f(...);
...
return std::move(tmp);
}


and got no compiler errors.



Was this correct?










share|improve this question

















This question already has an answer here:




  • C++11 rvalues and move semantics confusion (return statement)

    6 answers




I have TTempTable class with move symantics. I wrote



TTempTable&& MyFunction() {
TTempTable tmp = f(...);
...
return std::move(tmp);
}


and got no compiler errors.



Was this correct?





This question already has an answer here:




  • C++11 rvalues and move semantics confusion (return statement)

    6 answers








c++ return-value rvalue-reference






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 27 at 12:58









Lightness Races in Orbit

317k59 gold badges527 silver badges877 bronze badges




317k59 gold badges527 silver badges877 bronze badges










asked May 27 at 12:53









DimsDims

14.4k53 gold badges176 silver badges364 bronze badges




14.4k53 gold badges176 silver badges364 bronze badges





marked as duplicate by Ben Voigt c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
May 28 at 0:50


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











marked as duplicate by Ben Voigt c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
May 28 at 0:50


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Ben Voigt c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
May 28 at 0:50


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1





    Have a look at this rule in the C++ Core Guidelines

    – GPhilo
    May 27 at 12:56














  • 1





    Have a look at this rule in the C++ Core Guidelines

    – GPhilo
    May 27 at 12:56








1




1





Have a look at this rule in the C++ Core Guidelines

– GPhilo
May 27 at 12:56





Have a look at this rule in the C++ Core Guidelines

– GPhilo
May 27 at 12:56












1 Answer
1






active

oldest

votes


















20
















No, it is not correct.



You're returning a reference to a local variable. That reference is dangling.



Like any dangling thing, the compiler won't [always] diagnose it for you.



Return by value, and remove the std::move (it's redundant and inhibits elision).






share|improve this answer

































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    20
















    No, it is not correct.



    You're returning a reference to a local variable. That reference is dangling.



    Like any dangling thing, the compiler won't [always] diagnose it for you.



    Return by value, and remove the std::move (it's redundant and inhibits elision).






    share|improve this answer






























      20
















      No, it is not correct.



      You're returning a reference to a local variable. That reference is dangling.



      Like any dangling thing, the compiler won't [always] diagnose it for you.



      Return by value, and remove the std::move (it's redundant and inhibits elision).






      share|improve this answer




























        20














        20










        20









        No, it is not correct.



        You're returning a reference to a local variable. That reference is dangling.



        Like any dangling thing, the compiler won't [always] diagnose it for you.



        Return by value, and remove the std::move (it's redundant and inhibits elision).






        share|improve this answer













        No, it is not correct.



        You're returning a reference to a local variable. That reference is dangling.



        Like any dangling thing, the compiler won't [always] diagnose it for you.



        Return by value, and remove the std::move (it's redundant and inhibits elision).







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 27 at 12:56









        Lightness Races in OrbitLightness Races in Orbit

        317k59 gold badges527 silver badges877 bronze badges




        317k59 gold badges527 silver badges877 bronze badges




















            Popular posts from this blog

            He _____ here since 1970 . Answer needed [closed]What does “since he was so high” mean?Meaning of “catch birds for”?How do I ensure “since” takes the meaning I want?“Who cares here” meaningWhat does “right round toward” mean?the time tense (had now been detected)What does the phrase “ring around the roses” mean here?Correct usage of “visited upon”Meaning of “foiled rail sabotage bid”It was the third time I had gone to Rome or It is the third time I had been to Rome

            Bunad

            Færeyskur hestur Heimild | Tengill | Tilvísanir | LeiðsagnarvalRossið - síða um færeyska hrossið á færeyskuGott ár hjá færeyska hestinum