public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/39798]  New: would like flag to disable constructors for built-in types
@ 2009-04-17 17:40 kraftche at cae dot wisc dot edu
  2009-04-20 15:28 ` [Bug c++/39798] " falk at debian dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: kraftche at cae dot wisc dot edu @ 2009-04-17 17:40 UTC (permalink / raw)
  To: gcc-bugs

In C++, the statement 'k = int()' will zero 'k'.  This somewhat inconsistent
behavior (e.g. initialize a struct with a default constructor is a no-op) is
somewhat annoying because it results in all STL containers zeroing their
contents.  I've encountered a few rare cases where this resulted in a
significant performance hit but the most annoying part is that it prevents
tools like valgrind from detecting the use uninitialized values taken from STL
containers.  It would be nice if g++ had a flag to optionally disable this
behavior (make the constructors for build-in types be no-ops.)


-- 
           Summary: would like flag to disable constructors for built-in
                    types
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kraftche at cae dot wisc dot edu


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


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

* [Bug c++/39798] would like flag to disable constructors for built-in types
  2009-04-17 17:40 [Bug c++/39798] New: would like flag to disable constructors for built-in types kraftche at cae dot wisc dot edu
@ 2009-04-20 15:28 ` falk at debian dot org
  2009-04-20 15:52 ` kraftche at cae dot wisc dot edu
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: falk at debian dot org @ 2009-04-20 15:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from falk at debian dot org  2009-04-20 15:28 -------
Removing the default constructor is a bad idea, since it would break about any
available library including the standard lib in subtle ways, and would make g++
pretty much unusable.

But apparently this isn't actually what you really want anyway, but actually
you want to be able to create STL containers with uninitialized memory. This
seems to me a pretty unusual requirement, and it could be achieved by creating
a wrapper class for int with empty constructor, so I don't think this justifies
language or library changes.



-- 


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


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

* [Bug c++/39798] would like flag to disable constructors for built-in types
  2009-04-17 17:40 [Bug c++/39798] New: would like flag to disable constructors for built-in types kraftche at cae dot wisc dot edu
  2009-04-20 15:28 ` [Bug c++/39798] " falk at debian dot org
@ 2009-04-20 15:52 ` kraftche at cae dot wisc dot edu
  2009-04-20 15:59 ` paolo dot carlini at oracle dot com
  2009-04-21 18:14 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: kraftche at cae dot wisc dot edu @ 2009-04-20 15:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from kraftche at cae dot wisc dot edu  2009-04-20 15:52 -------
Subject: Re:  would like flag to disable constructors for built-in
 types

falk at debian dot org wrote:
> ------- Comment #1 from falk at debian dot org  2009-04-20 15:28 -------
> Removing the default constructor is a bad idea, since it would break about any
> available library including the standard lib in subtle ways, and would make g++
> pretty much unusable.
> 
> But apparently this isn't actually what you really want anyway, but actually
> you want to be able to create STL containers with uninitialized memory. This
> seems to me a pretty unusual requirement, and it could be achieved by creating
> a wrapper class for int with empty constructor, so I don't think this justifies
> language or library changes.

I was asking for a flag to change the behavior of the default/builtin
constructors for intrinsic types.  That isn't quite as extreme as removing
default constructors entirely.

Yes, I had requested that behavior with the intention of creating STL
containers with uninitialized memory.  I have used other work-arounds
(wrapper classes and such) in a few instances where that was necessary for
performance reasons.  But there are other cases where a flag to change the
constructor behavior for intrinsic types would be more appropriate.  For
example, it is often the case that the zero value assigned to all container
entries is logically just as unitialized as any other arbitrary value.  When
debugging such code it would be nice if the zero-ing behavior could be
removed because it masks such errors from tools like valgrind.  Using a
work-around would unnecessarily complicate the code because it is not
necessary for correctness or performance.

Anyway, this was purely a request for a wish-list type convenience feature.
 If it is infeasible or likely to introduce other subtle errors in the
functioning of the standard library, then please close this bug with my
thanks for taking the time to read it any my apologies for any nuisance.


-- 


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


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

* [Bug c++/39798] would like flag to disable constructors for built-in types
  2009-04-17 17:40 [Bug c++/39798] New: would like flag to disable constructors for built-in types kraftche at cae dot wisc dot edu
  2009-04-20 15:28 ` [Bug c++/39798] " falk at debian dot org
  2009-04-20 15:52 ` kraftche at cae dot wisc dot edu
@ 2009-04-20 15:59 ` paolo dot carlini at oracle dot com
  2009-04-21 18:14 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-04-20 15:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from paolo dot carlini at oracle dot com  2009-04-20 15:59 -------
For the record, I essentially agree with Falk, we are talking about a basic
core language behaviour, in general we don't have switches to create different
minor dialects of C++ at will... By the way, let's not encourage the use of
"STL", an acronym obsolete since the first C++ Standard, in 1998.


-- 


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


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

* [Bug c++/39798] would like flag to disable constructors for built-in types
  2009-04-17 17:40 [Bug c++/39798] New: would like flag to disable constructors for built-in types kraftche at cae dot wisc dot edu
                   ` (2 preceding siblings ...)
  2009-04-20 15:59 ` paolo dot carlini at oracle dot com
@ 2009-04-21 18:14 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-04-21 18:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2009-04-21 18:14 -------
As mentioned this is just going to break more things than it can help.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |WONTFIX


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


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

end of thread, other threads:[~2009-04-21 18:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-17 17:40 [Bug c++/39798] New: would like flag to disable constructors for built-in types kraftche at cae dot wisc dot edu
2009-04-20 15:28 ` [Bug c++/39798] " falk at debian dot org
2009-04-20 15:52 ` kraftche at cae dot wisc dot edu
2009-04-20 15:59 ` paolo dot carlini at oracle dot com
2009-04-21 18:14 ` pinskia at gcc dot gnu dot 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).