public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "vlukas at gmx dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/57779] New: vector insert fails to diagnose iterators pointing into *this in debug mode
Date: Tue, 02 Jul 2013 16:11:00 -0000	[thread overview]
Message-ID: <bug-57779-4@http.gcc.gnu.org/bugzilla/> (raw)

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


             reply	other threads:[~2013-07-02 16:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-02 16:11 vlukas at gmx dot de [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-57779-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).