public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/57779] New: vector insert fails to diagnose iterators pointing into *this in debug mode
@ 2013-07-02 16:11 vlukas at gmx dot de
  2013-07-03 19:31 ` [Bug libstdc++/57779] " paolo.carlini at oracle dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: vlukas at gmx dot de @ 2013-07-02 16:11 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 57779
           Summary: vector insert fails to diagnose iterators pointing
                    into *this in debug mode
           Product: gcc
           Version: 4.7.3
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vlukas at gmx dot de

When using the libstdc++ debug mode, some invalid iterator uses are not
diagnosed, e.g. the following program compiles and runs without aborting / any
diagnostic:
------------------------------------------------------------------
#include <vector>

int main() {
  std::vector<int> v(1, 1);
  v.insert(v.begin(), v.begin(), v.end());
}
-------------------------------------------------------------------

In the call to vector::insert, the range to insert points into the vector to
insert into. This violates the precondition as specified for sequence
containers. A similar precondition exists for sequence container assign members
and maybe others. It would be nice if this misusage could be diagnosed.

The matter is a bit more complicated because in a "insert(p, i, j)" call, i and
j may be arbitrary input iterators forming a range. Example:
-----------------------------------------------------------
#include <vector>

int main() {
  std::vector<int> v(1, 1);
  v.insert(v.begin(), v.data(), v.data() + 1);
}
------------------------------------------------------------
Here the iterators i and j are plain pointers.



The full compiler command line I used was:
-----------------------------------------------------------
c++ -Wall -Wextra -pedantic -std=c++0x -D_GLIBCXX_DEBUG
-D_GLIBCXX_DEBUG_PEDANTIC -o
container_insert_iterators_into_container.debug_enhancement
container_insert_iterators_into_container.debug_enhancement.cc -g
-fstack-protector-all -pthread
---------------------------------------------------------

The output of "c++ -v" is:
----------------------------------------------------------
Using built-in specs.
COLLECT_GCC=c++
COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-suse-linux/4.7/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.7
--enable-ssp --disable-libssp --disable-libitm --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.7 --enable-linux-futex --without-system-libunwind
--with-arch-32=i586 --with-tune=generic --build=x86_64-suse-linux
Thread model: posix
gcc version 4.7.3 (SUSE Linux)
----------------------------------------------------------


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

* [Bug libstdc++/57779] vector insert fails to diagnose iterators pointing into *this in debug mode
  2013-07-02 16:11 [Bug libstdc++/57779] New: vector insert fails to diagnose iterators pointing into *this in debug mode vlukas at gmx dot de
@ 2013-07-03 19:31 ` paolo.carlini at oracle dot com
  2013-07-05  9:54 ` paolo.carlini at oracle dot com
  2013-08-01 22:28 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-07-03 19:31 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |frs.dumont at gmail dot com

--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Maybe Francois is interested.


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

* [Bug libstdc++/57779] vector insert fails to diagnose iterators pointing into *this in debug mode
  2013-07-02 16:11 [Bug libstdc++/57779] New: vector insert fails to diagnose iterators pointing into *this in debug mode vlukas at gmx dot de
  2013-07-03 19:31 ` [Bug libstdc++/57779] " paolo.carlini at oracle dot com
@ 2013-07-05  9:54 ` paolo.carlini at oracle dot com
  2013-08-01 22:28 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-07-05  9:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Even if our implementation doesn't misbehave in those cases, a DEBUG_PEDASSERT
could be in order (like we do in, eg, basic_string::operator[])


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

* [Bug libstdc++/57779] vector insert fails to diagnose iterators pointing into *this in debug mode
  2013-07-02 16:11 [Bug libstdc++/57779] New: vector insert fails to diagnose iterators pointing into *this in debug mode vlukas at gmx dot de
  2013-07-03 19:31 ` [Bug libstdc++/57779] " paolo.carlini at oracle dot com
  2013-07-05  9:54 ` paolo.carlini at oracle dot com
@ 2013-08-01 22:28 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-08-01 22:28 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |4.9.0

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Done for 4.9.0 then.


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

end of thread, other threads:[~2013-08-01 22:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-02 16:11 [Bug libstdc++/57779] New: vector insert fails to diagnose iterators pointing into *this in debug mode vlukas at gmx dot de
2013-07-03 19:31 ` [Bug libstdc++/57779] " paolo.carlini at oracle dot com
2013-07-05  9:54 ` paolo.carlini at oracle dot com
2013-08-01 22:28 ` paolo.carlini at oracle dot com

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).