This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/33613] New: compilation inconsistency upper_bound vs lower_bound with -D_GLIBCXX_DEBUG


The following code fails to compile when -D_GLIBCXX_DEBUG is used. If
-D_GLIBCXX_DEBUG is not used, or the upper_bound call is commented out, the
code compiles fine.

////////////////////////////// test.cc begin
#include <algorithm>
struct A {};
struct B {};
bool ab(A, B);
bool ba(B, A);
void test(A* a, B b)
{
        std::lower_bound(a,a,b, ab);
        std::upper_bound(a,a,b, ba);
}
/////////////////////////////// test.cc end

Expected behaviour is that since everything compiles without the define, it
would also compile with the define, and since lower_bound call compiles even
with that, then at least both lower_bound and upper_bound would either both
fail or both compile.

The current behaviour of just upper_bound failing and only with that define is
confusing at best.

Perhaps you could add a check that the iterator sequence iterates elements of
the same type as the third parameter, or if this should not be required, make
that noncompiling case compile too.

$ g++ -v -save-temps -D_GLIBCXX_DEBUG test.cc
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2
--enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr
--enable-targets=all --disable-werror --enable-checking=release
--build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.2.1 (Debian 4.2.1-5)
 /usr/lib/gcc/i486-linux-gnu/4.2.1/cc1plus -E -quiet -v -D_GNU_SOURCE
-D_GLIBCXX_DEBUG test.cc -mtune=generic -fpch-preprocess -o test.ii
ignoring nonexistent directory "/usr/local/include/i486-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/i486-linux-gnu/4.2.1/../../../../i486-linux-gnu/include"
ignoring nonexistent directory "/usr/include/i486-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.2
 /usr/include/c++/4.2/i486-linux-gnu
 /usr/include/c++/4.2/backward
 /usr/local/include
 /usr/lib/gcc/i486-linux-gnu/4.2.1/include
 /usr/include
End of search list.
 /usr/lib/gcc/i486-linux-gnu/4.2.1/cc1plus -fpreprocessed test.ii -quiet
-dumpbase test.cc -mtune=generic -auxbase test -version -o test.s
GNU C++ version 4.2.1 (Debian 4.2.1-5) (i486-linux-gnu)
        compiled by GNU C version 4.2.1 (Debian 4.2.1-5).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 96235c4da4910435a4a1e0ded06ae124
/usr/include/c++/4.2/debug/functions.h: In function ?bool
__gnu_debug::__check_partitioned(_ForwardIterator, _ForwardIterator, const
_Tp&, _Pred) [with _ForwardIterator = A*, _Tp = B, _Pred = bool (*)(B, A)]?:
/usr/include/c++/4.2/bits/stl_algo.h:3043:   instantiated from
?_ForwardIterator std::upper_bound(_ForwardIterator, _ForwardIterator, const
_Tp&, _Compare) [with _ForwardIterator = A*, _Tp = B, _Compare = bool (*)(B,
A)]?
test.cc:9:   instantiated from here
/usr/include/c++/4.2/debug/functions.h:285: error: conversion from ?A? to
non-scalar type ?B? requested
/usr/include/c++/4.2/debug/functions.h:287: error: conversion from ?A? to
non-scalar type ?B? requested

Leo Moisio


-- 
           Summary: compilation inconsistency upper_bound vs lower_bound
                    with -D_GLIBCXX_DEBUG
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: leo dot moisio at gmail dot com
 GCC build triplet: i486-pc-linux-gnu
  GCC host triplet: i486-pc-linux-gnu
GCC target triplet: i486-pc-linux-gnu


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]