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

Multi tool use
Multi tool use





.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




















            LMKVh69
            SnfJpXv

            Popular posts from this blog

            Bruad Bilen | Luke uk diar | NawigatsjuunCommonskategorii: BruadCommonskategorii: RunstükenWikiquote: Bruad

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

            Chléb Obsah Etymologie | Pojmy při krájení bochníku nebo pecnu chleba | Receptura a druhy | Typy českého chleba | Kvalita chleba v České republice | Cena chleba | Konzumace | Postup výroby | Odkazy | Navigační menuDostupné onlineKdo si mastí kapsu na chlebu? Pekaři to nejsouVývoj spotřebitelských cen – Český statistický úřadDostupné onlineJak se co dělá: Chleba4008364-08669