public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/62169] New: map iterators under _GLIBCXX_DEBUG diverge
@ 2014-08-18 12:53 terra at gnome dot org
  2014-08-18 12:56 ` [Bug libstdc++/62169] " terra at gnome dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: terra at gnome dot org @ 2014-08-18 12:53 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 62169
           Summary: map iterators under _GLIBCXX_DEBUG diverge
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: terra at gnome dot org

The two types
    std::map<int,int>::iterator
    std::map<const int,int>::iterator
are the same when compiled normally, but different under _GLIBCXX_DEBUG.

I actually don't know if the standard allows that, but if it does and the
difference is intentional, then the documentation ought to mention it.




welinder@sherwood:~> cat iterator.C
#include <iostream>
#include <map>

static int foo (const void *) { return 0; }
static int foo (std::map<int,int>::iterator *) { return 1; }

int
main ()
{
  std::cerr << foo (static_cast<std::map<const int,int>::iterator *> (0)) <<
std::endl;
  return 0;
}

welinder@sherwood:~> g++ iterator.C
welinder@sherwood:~> ./a.out 
1

welinder@sherwood:~> g++ -D_GLIBCXX_DEBUG iterator.C
welinder@sherwood:~> ./a.out 
0


welinder@sherwood:~> g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-suse-linux/4.8/lto-wrapper
Target: x86_64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info
--mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64
--enable-languages=c,c++,objc,fortran,obj-c++,java,ada
--enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.8
--enable-ssp --disable-libssp --disable-plugin
--with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux'
--disable-libgcj --disable-libmudflap --with-slibdir=/lib64 --with-system-zlib
--enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch
--enable-version-specific-runtime-libs --enable-linker-build-id
--program-suffix=-4.8 --enable-linux-futex --without-system-libunwind
--with-arch-32=i586 --with-tune=generic --build=x86_64-suse-linux
Thread model: posix
gcc version 4.8.1 20130909 [gcc-4_8-branch revision 202388] (SUSE Linux) 


(Preprocessed versions coming up, just in case.)


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

* [Bug libstdc++/62169] map iterators under _GLIBCXX_DEBUG diverge
  2014-08-18 12:53 [Bug libstdc++/62169] New: map iterators under _GLIBCXX_DEBUG diverge terra at gnome dot org
@ 2014-08-18 12:56 ` terra at gnome dot org
  2014-08-18 12:56 ` terra at gnome dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: terra at gnome dot org @ 2014-08-18 12:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from M Welinder <terra at gnome dot org> ---
Created attachment 33347
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33347&action=edit
Preprocessed source code for debug case


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

* [Bug libstdc++/62169] map iterators under _GLIBCXX_DEBUG diverge
  2014-08-18 12:53 [Bug libstdc++/62169] New: map iterators under _GLIBCXX_DEBUG diverge terra at gnome dot org
  2014-08-18 12:56 ` [Bug libstdc++/62169] " terra at gnome dot org
@ 2014-08-18 12:56 ` terra at gnome dot org
  2014-08-18 13:01 ` terra at gnome dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: terra at gnome dot org @ 2014-08-18 12:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from M Welinder <terra at gnome dot org> ---
Created attachment 33346
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33346&action=edit
Preprocessed source code for normal case


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

* [Bug libstdc++/62169] map iterators under _GLIBCXX_DEBUG diverge
  2014-08-18 12:53 [Bug libstdc++/62169] New: map iterators under _GLIBCXX_DEBUG diverge terra at gnome dot org
  2014-08-18 12:56 ` [Bug libstdc++/62169] " terra at gnome dot org
  2014-08-18 12:56 ` terra at gnome dot org
@ 2014-08-18 13:01 ` terra at gnome dot org
  2014-08-23 23:37 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: terra at gnome dot org @ 2014-08-18 13:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from M Welinder <terra at gnome dot org> ---
A similar divergence of types occurs between the types

    std::map<int,int>::iterator
    std::multimap<int,int>::iterator


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

* [Bug libstdc++/62169] map iterators under _GLIBCXX_DEBUG diverge
  2014-08-18 12:53 [Bug libstdc++/62169] New: map iterators under _GLIBCXX_DEBUG diverge terra at gnome dot org
                   ` (2 preceding siblings ...)
  2014-08-18 13:01 ` terra at gnome dot org
@ 2014-08-23 23:37 ` redi at gcc dot gnu.org
  2014-08-24  0:07 ` terra at gnome dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2014-08-23 23:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The standard allows iterators of different containers to be different, your
program is not portable of it assumes they will (or will not) be the same type.

I don't consider this a bug, and am not very motivated to even document it, but
will accept a documentation patch.


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

* [Bug libstdc++/62169] map iterators under _GLIBCXX_DEBUG diverge
  2014-08-18 12:53 [Bug libstdc++/62169] New: map iterators under _GLIBCXX_DEBUG diverge terra at gnome dot org
                   ` (3 preceding siblings ...)
  2014-08-23 23:37 ` redi at gcc dot gnu.org
@ 2014-08-24  0:07 ` terra at gnome dot org
  2014-08-24 10:35 ` redi at gcc dot gnu.org
  2014-09-19 13:20 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: terra at gnome dot org @ 2014-08-24  0:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from M Welinder <terra at gnome dot org> ---
I agree that anyone depending on map and multimap iterators to mix deserves
whatever happens as a result.  It would, however, be nice g++ would reject such
programs outright.  Currently this is accepted:

    std::map<int,int> foo;
    std::multimap<int,int>::iterator = foo.end();

You get this kind of code when someone changes the container type and uses the
compiler to point out where further fixes are needed.

Is it an option to make the iterators different for the non-debug case too?
Would that be an ABI change?


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

* [Bug libstdc++/62169] map iterators under _GLIBCXX_DEBUG diverge
  2014-08-18 12:53 [Bug libstdc++/62169] New: map iterators under _GLIBCXX_DEBUG diverge terra at gnome dot org
                   ` (4 preceding siblings ...)
  2014-08-24  0:07 ` terra at gnome dot org
@ 2014-08-24 10:35 ` redi at gcc dot gnu.org
  2014-09-19 13:20 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2014-08-24 10:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It's not an option IMHO. See http://www​.stroustrup.com/SCARY.pdf for the
benefits of the current design. Those benefits outweigh the advantage of having
non-portable code diagnosed. Debug iterators can't be SCARY because they have a
pointer back to their patent container so have to depend on the exact type.
>From gcc-bugs-return-459134-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Sun Aug 24 10:45:50 2014
Return-Path: <gcc-bugs-return-459134-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 17162 invoked by alias); 24 Aug 2014 10:45:49 -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 17111 invoked by uid 48); 24 Aug 2014 10:45:44 -0000
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/62169] map iterators under _GLIBCXX_DEBUG diverge
Date: Sun, 24 Aug 2014 10:45:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: libstdc++
X-Bugzilla-Version: 4.8.1
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: redi at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
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: <bug-62169-4-ZLQbmrPtT6@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-62169-4@http.gcc.gnu.org/bugzilla/>
References: <bug-62169-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-08/txt/msg01631.txt.bz2
Content-length: 394

https://gcc.gnu.org/bugzilla/show_bug.cgi?idb169

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #6)
> they have a pointer back to their patent container

s/patent/parent/

As for solving the problem of switching containers, use a typedef for the
container, or auto for the iterator. It doesn't need to be solved by the
compiler.


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

* [Bug libstdc++/62169] map iterators under _GLIBCXX_DEBUG diverge
  2014-08-18 12:53 [Bug libstdc++/62169] New: map iterators under _GLIBCXX_DEBUG diverge terra at gnome dot org
                   ` (5 preceding siblings ...)
  2014-08-24 10:35 ` redi at gcc dot gnu.org
@ 2014-09-19 13:20 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2014-09-19 13:20 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

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

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The cure would be worse than the disease.


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

end of thread, other threads:[~2014-09-19 13:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-18 12:53 [Bug libstdc++/62169] New: map iterators under _GLIBCXX_DEBUG diverge terra at gnome dot org
2014-08-18 12:56 ` [Bug libstdc++/62169] " terra at gnome dot org
2014-08-18 12:56 ` terra at gnome dot org
2014-08-18 13:01 ` terra at gnome dot org
2014-08-23 23:37 ` redi at gcc dot gnu.org
2014-08-24  0:07 ` terra at gnome dot org
2014-08-24 10:35 ` redi at gcc dot gnu.org
2014-09-19 13:20 ` redi 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).