public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/49372] New: Temporaries evaluated for arguments of a default constructors of array elements not destructed properly (?)
@ 2011-06-11 13:27 schaub.johannes at googlemail dot com
  2011-06-11 13:47 ` [Bug c++/49372] " schaub.johannes at googlemail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: schaub.johannes at googlemail dot com @ 2011-06-11 13:27 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49372

           Summary: Temporaries evaluated for arguments of a default
                    constructors of array elements not destructed properly
                    (?)
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: schaub.johannes@googlemail.com


This testcase outputs a surprising result:

struct A {
  A() { std::cout << "C" << std::endl; }
  ~A() { std::cout << "D" << std::endl; }
};

struct B {
  B(A const& a = A()) { }
};

typedef B array[2];

int main() {
  array{};
}

GCC prints "CCDD". I would have expected "CDCD", as it seems that is the intent
of the wording in the spec (FDIS). The FDIS however seems to be contradicting
here, but it appears to me that GCC should better print "CDCD", so as to follow
the intent. 

Originated from
http://stackoverflow.com/questions/6315670/when-an-array-is-created-by-a-subexpression-what-happens-with-the-temporaries-th
.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/49372] Temporaries evaluated for arguments of a default constructors of array elements not destructed properly (?)
  2011-06-11 13:27 [Bug c++/49372] New: Temporaries evaluated for arguments of a default constructors of array elements not destructed properly (?) schaub.johannes at googlemail dot com
@ 2011-06-11 13:47 ` schaub.johannes at googlemail dot com
  2012-12-10 11:07 ` ktietz at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: schaub.johannes at googlemail dot com @ 2011-06-11 13:47 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49372

--- Comment #1 from Johannes Schaub <schaub.johannes at googlemail dot com> 2011-06-11 13:46:46 UTC ---
To elaborate on it, I have the following weird behavior:

- GCC4.6 outputs nothing for the program (on my linux machine). That seems
definitely wrong in any case.
- GCC4.7 "4.7.0 20110517 (experimental)", using a mingw nightly build,
generates an executable that crashes when running:

[js@HOST2 cpp]$ ~/w64/bin/i686-w64-mingw32-g++ -std=c++0x -O1 -o a.exe
main1.cpp
[js@HOST2 cpp]$ wine ./a.exe
Cwine: Unhandled page fault on read access to 0x00000000 at address (nil)
(thread 0025), starting debugger...

- The same GCC4.7 when using -O2 does not crash and print "CCDD":

[js@HOST2 cpp]$ ~/w64/bin/i686-w64-mingw32-g++ -std=c++0x -O2 -o a.exe
main1.cpp
[js@HOST2 cpp]$ wine ./a.exe
fixme:ntoskrnl:KeInitializeSpinLock stub: 0x5477a4
C
C
D
D

I don't know precisely whether this is a problem with wine or a temporary
problem with that nightly build of GCC I was using. My apologies if GCC trunk
works differently!


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/49372] Temporaries evaluated for arguments of a default constructors of array elements not destructed properly (?)
  2011-06-11 13:27 [Bug c++/49372] New: Temporaries evaluated for arguments of a default constructors of array elements not destructed properly (?) schaub.johannes at googlemail dot com
  2011-06-11 13:47 ` [Bug c++/49372] " schaub.johannes at googlemail dot com
@ 2012-12-10 11:07 ` ktietz at gcc dot gnu.org
  2012-12-10 13:15 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: ktietz at gcc dot gnu.org @ 2012-12-10 11:07 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49372

Kai Tietz <ktietz at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |ktietz at gcc dot gnu.org
         Resolution|                            |INVALID

--- Comment #2 from Kai Tietz <ktietz at gcc dot gnu.org> 2012-12-10 11:06:49 UTC ---
This testcase seems to produce for trunk, 4.7, and 4.6 the output CCDD, which
is proper as constructor of B is called by the array-constructor.
Btw you will need option -std=c++11 on trunk to get this test compile without
issues.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/49372] Temporaries evaluated for arguments of a default constructors of array elements not destructed properly (?)
  2011-06-11 13:27 [Bug c++/49372] New: Temporaries evaluated for arguments of a default constructors of array elements not destructed properly (?) schaub.johannes at googlemail dot com
  2011-06-11 13:47 ` [Bug c++/49372] " schaub.johannes at googlemail dot com
  2012-12-10 11:07 ` ktietz at gcc dot gnu.org
@ 2012-12-10 13:15 ` redi at gcc dot gnu.org
  2012-12-10 13:42 ` ktietz at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2012-12-10 13:15 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49372

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-12-10 13:14:56 UTC ---
Kai, I don't think anyone disputes that B's constructor is called, the question
is why 12.2/4 doesn't apply.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/49372] Temporaries evaluated for arguments of a default constructors of array elements not destructed properly (?)
  2011-06-11 13:27 [Bug c++/49372] New: Temporaries evaluated for arguments of a default constructors of array elements not destructed properly (?) schaub.johannes at googlemail dot com
                   ` (2 preceding siblings ...)
  2012-12-10 13:15 ` redi at gcc dot gnu.org
@ 2012-12-10 13:42 ` ktietz at gcc dot gnu.org
  2012-12-10 16:43 ` schaub.johannes at googlemail dot com
  2023-05-08 12:58 ` ppalka at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: ktietz at gcc dot gnu.org @ 2012-12-10 13:42 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49372

Kai Tietz <ktietz at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |NEW
   Last reconfirmed|                            |2012-12-10
         Resolution|INVALID                     |
     Ever Confirmed|0                           |1

--- Comment #4 from Kai Tietz <ktietz at gcc dot gnu.org> 2012-12-10 13:42:30 UTC ---
(In reply to comment #3)
> Kai, I don't think anyone disputes that B's constructor is called, the question
> is why 12.2/4 doesn't apply.

Well, we have here 5.2.2 which says "A function call is a postfix expression
followed by parentheses containing a possibly empty, comma-separated list of
expressions which constitute the arguments to the function."

But we don't have here an explicit function-call.  And an implicit call is not
an expression, hence, not a part of any full expression, and so we don't have a
sequence-point.  Not sure if specification intended it differently, but by its
current wording I would assume that current implementation is right.

But indeed 12.4 seems to be violated here.  "There are two contexts in which
temporaries are destroyed at a different point than the end of the
fullexpression.
The first context is when a default constructor is called to initialize an
element of an array. If the constructor has one or more default arguments, the
destruction of every temporary created in a default argument expression is
sequenced before the construction of the next array element, if any."

So there is an antagonism in spec.  I will reopen it.  sorry, didn't read about
12.4


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/49372] Temporaries evaluated for arguments of a default constructors of array elements not destructed properly (?)
  2011-06-11 13:27 [Bug c++/49372] New: Temporaries evaluated for arguments of a default constructors of array elements not destructed properly (?) schaub.johannes at googlemail dot com
                   ` (3 preceding siblings ...)
  2012-12-10 13:42 ` ktietz at gcc dot gnu.org
@ 2012-12-10 16:43 ` schaub.johannes at googlemail dot com
  2023-05-08 12:58 ` ppalka at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: schaub.johannes at googlemail dot com @ 2012-12-10 16:43 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49372

--- Comment #5 from Johannes Schaub <schaub.johannes at googlemail dot com> 2012-12-10 16:42:59 UTC ---
(In reply to comment #4)
> (In reply to comment #3)
> > Kai, I don't think anyone disputes that B's constructor is called, the question
> > is why 12.2/4 doesn't apply.
> 
> Well, we have here 5.2.2 which says "A function call is a postfix expression
> followed by parentheses containing a possibly empty, comma-separated list of
> expressions which constitute the arguments to the function."
> 
> But we don't have here an explicit function-call.  And an implicit call is not
> an expression, hence, not a part of any full expression, and so we don't have a
> sequence-point.  Not sure if specification intended it differently, but by its
> current wording I would assume that current implementation is right.
> 

See 1.9p10. The implicit function call is considered to be an expression.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/49372] Temporaries evaluated for arguments of a default constructors of array elements not destructed properly (?)
  2011-06-11 13:27 [Bug c++/49372] New: Temporaries evaluated for arguments of a default constructors of array elements not destructed properly (?) schaub.johannes at googlemail dot com
                   ` (4 preceding siblings ...)
  2012-12-10 16:43 ` schaub.johannes at googlemail dot com
@ 2023-05-08 12:58 ` ppalka at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-05-08 12:58 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49372

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppalka at gcc dot gnu.org
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=92385
   Target Milestone|---                         |12.0

--- Comment #6 from Patrick Palka <ppalka at gcc dot gnu.org> ---
It seems this is fixed for GCC 12+ by r12-6326-ge948436eab818c.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-05-08 12:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-11 13:27 [Bug c++/49372] New: Temporaries evaluated for arguments of a default constructors of array elements not destructed properly (?) schaub.johannes at googlemail dot com
2011-06-11 13:47 ` [Bug c++/49372] " schaub.johannes at googlemail dot com
2012-12-10 11:07 ` ktietz at gcc dot gnu.org
2012-12-10 13:15 ` redi at gcc dot gnu.org
2012-12-10 13:42 ` ktietz at gcc dot gnu.org
2012-12-10 16:43 ` schaub.johannes at googlemail dot com
2023-05-08 12:58 ` ppalka at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).