From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 70075 invoked by alias); 1 Oct 2015 13:06:04 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 69991 invoked by uid 48); 1 Oct 2015 13:05:57 -0000 From: "frankhb1989 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/67795] Wrong code generated for conditional expression with cast Date: Thu, 01 Oct 2015 13:06:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: frankhb1989 at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-10/txt/msg00039.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67795 --- Comment #8 from frankhb1989 at gmail dot com --- (In reply to Markus Trippelsdorf from comment #4) > Return by value if you want to avoid undefined behavior. No. This is not the point. For something like 'std::move' or 'std::forward', can you suggest such change? The code of the case is reduced from a function template which return 'S&&', where 'S' is a template type parameter (and 'S&&' is also in function parameter list for perfect forwarding). Simply returning object type is not acceptable in the original case because: 1. Even move construction for 'S' is not guaranteed to be zero overhead. 2.It needs one more static_cast/std::move in many places of the the client code which makes it bloat A LOT.