* [Bug c++/61769] const reference value is changed to random by a range-for loop
2014-07-10 9:52 [Bug c++/61769] New: const reference value is changed to random by a range-for loop theemathas at hotmail dot com
@ 2014-07-10 10:01 ` theemathas at hotmail dot com
2014-07-10 10:08 ` redi at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: theemathas at hotmail dot com @ 2014-07-10 10:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61769
theemathas at hotmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |theemathas at hotmail dot com
--- Comment #1 from theemathas at hotmail dot com ---
Created attachment 33099
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33099&action=edit
"main.cpp" non-preprocessed source code
I am having some problems with uploading the "main.ii" file (apparently it is
too big because I #include 3 standard libraries). I am uploading the
non-preprocessed source code first, and I will upload the preprocessed code
ASAP.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/61769] const reference value is changed to random by a range-for loop
2014-07-10 9:52 [Bug c++/61769] New: const reference value is changed to random by a range-for loop theemathas at hotmail dot com
2014-07-10 10:01 ` [Bug c++/61769] " theemathas at hotmail dot com
@ 2014-07-10 10:08 ` redi at gcc dot gnu.org
2014-07-10 10:09 ` redi at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2014-07-10 10:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61769
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to theemathas from comment #1)
> I am having some problems with uploading the "main.ii" file (apparently it
> is too big because I #include 3 standard libraries). I am uploading the
> non-preprocessed source code first, and I will upload the preprocessed code
> ASAP.
Don't bother, the program is invalid. std::abs returns a temporary that goes
out of scope at the end of the expression, std::max returns a dangling
reference to that temporary.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/61769] const reference value is changed to random by a range-for loop
2014-07-10 9:52 [Bug c++/61769] New: const reference value is changed to random by a range-for loop theemathas at hotmail dot com
2014-07-10 10:01 ` [Bug c++/61769] " theemathas at hotmail dot com
2014-07-10 10:08 ` redi at gcc dot gnu.org
@ 2014-07-10 10:09 ` redi at gcc dot gnu.org
2014-07-10 10:15 ` theemathas at hotmail dot com
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2014-07-10 10:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61769
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
Severity|major |normal
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The for loop just causes the program to reuse the stack memory where the
std::abs return slots were, so the memory where the dangling reference points
gets modified and you see the value change.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/61769] const reference value is changed to random by a range-for loop
2014-07-10 9:52 [Bug c++/61769] New: const reference value is changed to random by a range-for loop theemathas at hotmail dot com
` (2 preceding siblings ...)
2014-07-10 10:09 ` redi at gcc dot gnu.org
@ 2014-07-10 10:15 ` theemathas at hotmail dot com
2014-07-10 10:17 ` theemathas at hotmail dot com
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: theemathas at hotmail dot com @ 2014-07-10 10:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61769
theemathas at hotmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |---
--- Comment #4 from theemathas at hotmail dot com ---
(In reply to Jonathan Wakely from comment #2)
> (In reply to theemathas from comment #1)
> > I am having some problems with uploading the "main.ii" file (apparently it
> > is too big because I #include 3 standard libraries). I am uploading the
> > non-preprocessed source code first, and I will upload the preprocessed code
> > ASAP.
>
> Don't bother, the program is invalid. std::abs returns a temporary that goes
> out of scope at the end of the expression, std::max returns a dangling
> reference to that temporary.
(In reply to Jonathan Wakely from comment #3)
> The for loop just causes the program to reuse the stack memory where the
> std::abs return slots were, so the memory where the dangling reference
> points gets modified and you see the value change.
I think my program is valid
According to http://en.cppreference.com/w/cpp/algorithm/max : std::max can
accept "const int&" as parameters
According to
http://herbsutter.com/2008/01/01/gotw-88-a-candidate-for-the-most-important-const/
: binding a temporary to a const reference "lengthens the lifetime of the
temporary to the lifetime of the reference itself"
Thus, no dangling reference.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/61769] const reference value is changed to random by a range-for loop
2014-07-10 9:52 [Bug c++/61769] New: const reference value is changed to random by a range-for loop theemathas at hotmail dot com
` (3 preceding siblings ...)
2014-07-10 10:15 ` theemathas at hotmail dot com
@ 2014-07-10 10:17 ` theemathas at hotmail dot com
2014-07-10 10:18 ` theemathas at hotmail dot com
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: theemathas at hotmail dot com @ 2014-07-10 10:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61769
theemathas at hotmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |redi at gcc dot gnu.org
Severity|normal |major
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/61769] const reference value is changed to random by a range-for loop
2014-07-10 9:52 [Bug c++/61769] New: const reference value is changed to random by a range-for loop theemathas at hotmail dot com
` (4 preceding siblings ...)
2014-07-10 10:17 ` theemathas at hotmail dot com
@ 2014-07-10 10:18 ` theemathas at hotmail dot com
2014-07-10 10:19 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: theemathas at hotmail dot com @ 2014-07-10 10:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61769
--- Comment #5 from theemathas at hotmail dot com ---
Created attachment 33100
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33100&action=edit
"main.ii.gz" preprocessed and compressed code
Since the "main.ii" file exceeds the 1000 KB limit, I'm uploading a compressed
file instead.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/61769] const reference value is changed to random by a range-for loop
2014-07-10 9:52 [Bug c++/61769] New: const reference value is changed to random by a range-for loop theemathas at hotmail dot com
` (5 preceding siblings ...)
2014-07-10 10:18 ` theemathas at hotmail dot com
@ 2014-07-10 10:19 ` redi at gcc dot gnu.org
2014-07-10 10:32 ` redi at gcc dot gnu.org
2014-07-10 10:41 ` theemathas at hotmail dot com
8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2014-07-10 10:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61769
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
Severity|major |normal
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to theemathas from comment #4)
> According to
> http://herbsutter.com/2008/01/01/gotw-88-a-candidate-for-the-most-important-
> const/ : binding a temporary to a const reference "lengthens the lifetime of
> the temporary to the lifetime of the reference itself"
You don't bind a temporary to a const-reference, you bind a const-reference to
a const-reference, so the lifetime of the temporary is not extended. The
lifetime extension behaviour is not transitive from reference to reference.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/61769] const reference value is changed to random by a range-for loop
2014-07-10 9:52 [Bug c++/61769] New: const reference value is changed to random by a range-for loop theemathas at hotmail dot com
` (6 preceding siblings ...)
2014-07-10 10:19 ` redi at gcc dot gnu.org
@ 2014-07-10 10:32 ` redi at gcc dot gnu.org
2014-07-10 10:41 ` theemathas at hotmail dot com
8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2014-07-10 10:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61769
--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
If you change it to:
const int& aa = std::abs(a);
const int& foo=std::max(aa, aa);
You'll see that the problem goes away because the value returned by std::abs
gets its lifetime extended, then std::max returns a reference to the same
object, which has not gone out of scope.
Alternatively, avoid the pointless reference:
int foo = std::max(std::abs(a), std::abs(a));
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/61769] const reference value is changed to random by a range-for loop
2014-07-10 9:52 [Bug c++/61769] New: const reference value is changed to random by a range-for loop theemathas at hotmail dot com
` (7 preceding siblings ...)
2014-07-10 10:32 ` redi at gcc dot gnu.org
@ 2014-07-10 10:41 ` theemathas at hotmail dot com
8 siblings, 0 replies; 10+ messages in thread
From: theemathas at hotmail dot com @ 2014-07-10 10:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61769
--- Comment #8 from theemathas at hotmail dot com ---
(In reply to Jonathan Wakely from comment #7)
> If you change it to:
>
> const int& aa = std::abs(a);
> const int& foo=std::max(aa, aa);
>
> You'll see that the problem goes away because the value returned by std::abs
> gets its lifetime extended, then std::max returns a reference to the same
> object, which has not gone out of scope.
>
> Alternatively, avoid the pointless reference:
>
> int foo = std::max(std::abs(a), std::abs(a));
OK... I think I understand now.
By the way, I managed to find the exact text in the standard that states that
the code is invalid:
http://stackoverflow.com/questions/2784262/does-a-const-reference-prolong-the-life-of-a-temporary
"The lifetime extension is not transitive through a function argument. §12.2/5
[class.temporary]: '...A temporary bound to a reference parameter in a function
call (§5.2.2 [expr.call]) persists until the completion of the full expression
containing the call.' "
Thank you for explaining this, though.
>From gcc-bugs-return-456040-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Jul 10 10:44:26 2014
Return-Path: <gcc-bugs-return-456040-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 9462 invoked by alias); 10 Jul 2014 10:44:25 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 9381 invoked by uid 55); 10 Jul 2014 10:44:19 -0000
From: "ebotcazou at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/53590] compiler fails to generate SIMD instruction for FP division
Date: Thu, 10 Jul 2014 10:44:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: middle-end
X-Bugzilla-Version: 4.8.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: enhancement
X-Bugzilla-Who: ebotcazou at gcc dot gnu.org
X-Bugzilla-Status: RESOLVED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: ebotcazou at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 4.8.0
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-53590-4-IwXHRfJqdi@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-53590-4@http.gcc.gnu.org/bugzilla/>
References: <bug-53590-4@http.gcc.gnu.org/bugzilla/>
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: 2014-07/txt/msg00631.txt.bz2
Content-length: 645
https://gcc.gnu.org/bugzilla/show_bug.cgi?idS590
--- Comment #15 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
Author: ebotcazou
Date: Thu Jul 10 10:43:46 2014
New Revision: 212426
URL: https://gcc.gnu.org/viewcvs?rev!2426&root=gcc&view=rev
Log:
PR middle-end/53590
* function.c (allocate_struct_function): Revert r188667 change.
Added:
branches/gcc-4_8-branch/gcc/testsuite/gnat.dg/opt39.adb
- copied unchanged from r212425, trunk/gcc/testsuite/gnat.dg/opt39.adb
Modified:
branches/gcc-4_8-branch/gcc/ChangeLog
branches/gcc-4_8-branch/gcc/function.c
branches/gcc-4_8-branch/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 10+ messages in thread