public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/96303] New: Ambiguous overload for operator!= for std::__debug::bitset compiled with -std=c++20 and -pedantic.
@ 2020-07-23 19:01 matt.lawson at precisionplanting dot com
  2020-07-23 19:18 ` [Bug libstdc++/96303] [10/11 Regression] " redi at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: matt.lawson at precisionplanting dot com @ 2020-07-23 19:01 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96303
           Summary: Ambiguous overload for operator!= for
                    std::__debug::bitset compiled with -std=c++20 and
                    -pedantic.
           Product: gcc
           Version: 10.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: matt.lawson at precisionplanting dot com
  Target Milestone: ---

Hello,

In gcc/g++ 10.1.1, the following code produces an ambiguous overload for
std::__debug::bitset's operator!= when compiled with -D _GLIBCXX_DEBUG
-std=c++20 -pedantic (see bottom for full -v -save-temps output):


#include <bitset>

int main()
{
  std::bitset<5> x, y;
  return x != y;
}


When compiling without _GLIBCXX_DEBUG defined, the non-debug bitset does not
produce the same error.  Likewise, it does not produce error when compiling
with gcc/g++ 9, a previous C++ standard, or without -pedantic.  

It seems the non-debug bitset was updated for P1614R2 (commit
596676d66cab21e5ed85669e737af5b62f067d57), but the debug bitset was not, so the
fix may be as simple as applying the same changes to the debug bitset.

Thanks


Full -f -save-temps output:

g++ -v -save-temps  ~/Desktop/debug_bitset.cpp -o ~/Desktop/debug_bitset.o -D
_GLIBCXX_DEBUG -std=c++20 -Wall -Wextra -pedantic -fpermissive
-fno-strict-aliasing -fwrapv 
Using built-in specs.
COLLECT_GCC=/usr/bin/g++
COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-suse-linux/10/lto-wrapper
OFFLOAD_TARGET_NAMES=hsa:nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
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++,ada,go,d
--enable-offload-targets=hsa,nvptx-none=/usr/nvptx-none,amdgcn-amdhsa=/usr/amdgcn-amdhsa,
--without-cuda-driver --enable-checking=release --disable-werror
--with-gxx-include-dir=/usr/include/c++/10 --enable-ssp --disable-libssp
--disable-libvtv --disable-cet --disable-libcc1 --enable-plugin
--with-bugurl=https://bugs.opensuse.org/ --with-pkgversion='SUSE Linux'
--with-slibdir=/lib64 --with-system-zlib --enable-libstdcxx-allocator=new
--disable-libstdcxx-pch --enable-libphobos
--enable-version-specific-runtime-libs --with-gcc-major-version-only
--enable-linker-build-id --enable-linux-futex --enable-gnu-indirect-function
--program-suffix=-10 --without-system-libunwind --enable-multilib
--with-arch-32=x86-64 --with-tune=generic
--with-build-config=bootstrap-lto-lean --enable-link-mutex
--build=x86_64-suse-linux --host=x86_64-suse-linux
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.1.1 20200625 [revision c91e43e9363bd119a695d64505f96539fa451bf2]
(SUSE Linux) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-o'
'/home/mlawson/Desktop/debug_bitset.o' '-D' '_GLIBCXX_DEBUG' '-std=c++2a'
'-Wall' '-Wextra' '-Wpedantic' '-fpermissive' '-fno-strict-aliasing' '-fwrapv'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib64/gcc/x86_64-suse-linux/10/cc1plus -E -quiet -v -D_GNU_SOURCE -D
_GLIBCXX_DEBUG /home/mlawson/Desktop/debug_bitset.cpp -mtune=generic
-march=x86-64 -std=c++2a -Wall -Wextra -Wpedantic -fpermissive
-fno-strict-aliasing -fwrapv -fpch-preprocess -o debug_bitset.ii
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/10
 /usr/include/c++/10/x86_64-suse-linux
 /usr/include/c++/10/backward
 /usr/lib64/gcc/x86_64-suse-linux/10/include
 /usr/local/include
 /usr/lib64/gcc/x86_64-suse-linux/10/include-fixed
 /usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/include
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-o'
'/home/mlawson/Desktop/debug_bitset.o' '-D' '_GLIBCXX_DEBUG' '-std=c++2a'
'-Wall' '-Wextra' '-Wpedantic' '-fpermissive' '-fno-strict-aliasing' '-fwrapv'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib64/gcc/x86_64-suse-linux/10/cc1plus -fpreprocessed debug_bitset.ii
-quiet -dumpbase debug_bitset.cpp -mtune=generic -march=x86-64 -auxbase
debug_bitset -Wall -Wextra -Wpedantic -std=c++2a -version -fpermissive
-fno-strict-aliasing -fwrapv -o debug_bitset.s
GNU C++17 (SUSE Linux) version 10.1.1 20200625 [revision
c91e43e9363bd119a695d64505f96539fa451bf2] (x86_64-suse-linux)
        compiled by GNU C version 10.1.1 20200625 [revision
c91e43e9363bd119a695d64505f96539fa451bf2], GMP version 6.2.0, MPFR version
4.0.2-p6, MPC version 1.1.0, isl version isl-0.22.1-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++17 (SUSE Linux) version 10.1.1 20200625 [revision
c91e43e9363bd119a695d64505f96539fa451bf2] (x86_64-suse-linux)
        compiled by GNU C version 10.1.1 20200625 [revision
c91e43e9363bd119a695d64505f96539fa451bf2], GMP version 6.2.0, MPFR version
4.0.2-p6, MPC version 1.1.0, isl version isl-0.22.1-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 00000000000000000000000000000000
In file included from /usr/include/c++/10/bitset:1595,
                 from /home/mlawson/Desktop/debug_bitset.cpp:1:
/usr/include/c++/10/debug/bitset: In instantiation of ‘bool
std::__debug::bitset<_Nb>::operator!=(const std::__debug::bitset<_Nb>&) const
[with long unsigned int _Nb = 5]’:
/home/mlawson/Desktop/debug_bitset.cpp:6:15:   required from here
/usr/include/c++/10/debug/bitset:360:26: error: ambiguous overload for
‘operator!=’ (operand types are ‘const _Base’ {aka ‘const
std::__cxx1998::bitset<5>’} and ‘const std::__debug::bitset<5>’)
  360 |       { return _M_base() != __rhs; }
      |                ~~~~~~~~~~^~~~~~~~
/usr/include/c++/10/debug/bitset:355:7: note: candidate: ‘bool
std::__debug::bitset<_Nb>::operator==(const std::__debug::bitset<_Nb>&) const
[with long unsigned int _Nb = 5]’ (reversed)
  355 |       operator==(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
In file included from /home/mlawson/Desktop/debug_bitset.cpp:1:
/usr/include/c++/10/bitset:1306:7: note: candidate: ‘bool
std::__cxx1998::bitset<_Nb>::operator==(const std::__cxx1998::bitset<_Nb>&)
const [with long unsigned int _Nb = 5]’ (rewritten)
 1306 |       operator==(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~

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

* [Bug libstdc++/96303] [10/11 Regression] Ambiguous overload for operator!= for std::__debug::bitset compiled with -std=c++20 and -pedantic.
  2020-07-23 19:01 [Bug libstdc++/96303] New: Ambiguous overload for operator!= for std::__debug::bitset compiled with -std=c++20 and -pedantic matt.lawson at precisionplanting dot com
@ 2020-07-23 19:18 ` redi at gcc dot gnu.org
  2020-08-07 19:29 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2020-07-23 19:18 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org
   Last reconfirmed|                            |2020-07-23
             Status|UNCONFIRMED                 |ASSIGNED
      Known to work|                            |9.3.0
      Known to fail|                            |10.2.0, 11.0
            Summary|Ambiguous overload for      |[10/11 Regression]
                   |operator!= for              |Ambiguous overload for
                   |std::__debug::bitset        |operator!= for
                   |compiled with -std=c++20    |std::__debug::bitset
                   |and -pedantic.              |compiled with -std=c++20
                   |                            |and -pedantic.
   Target Milestone|---                         |10.3
           Keywords|                            |rejects-valid

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Yes I didn't realise the debug bitset defines its own rel ops. I wonder if it
really needs them at all.

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

* [Bug libstdc++/96303] [10/11 Regression] Ambiguous overload for operator!= for std::__debug::bitset compiled with -std=c++20 and -pedantic.
  2020-07-23 19:01 [Bug libstdc++/96303] New: Ambiguous overload for operator!= for std::__debug::bitset compiled with -std=c++20 and -pedantic matt.lawson at precisionplanting dot com
  2020-07-23 19:18 ` [Bug libstdc++/96303] [10/11 Regression] " redi at gcc dot gnu.org
@ 2020-08-07 19:29 ` cvs-commit at gcc dot gnu.org
  2020-08-07 19:46 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-08-07 19:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:de1e3b8795e507c3cfa5b62984272628ca62a9bd

commit r11-2611-gde1e3b8795e507c3cfa5b62984272628ca62a9bd
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Aug 7 20:29:11 2020 +0100

    libstdc++: Fix ambiguous comparisons in __gnu_debug::bitset [PR 96303]

    With -pedantic the debug mode bitset has an ambiguous equality
    comparison operator, because it tries to compare the non-debug base to
    the debug object. The base object can be converted to another debug
    bitset, making the same operator== a candidate again.

    The fix is to do the comparison on both base objects, so the operator
    for the derived type isn't a candidate.

    For the inequality operator the same change should be done, but that
    operator can be removed entirely for C++20 because it can be synthesized
    by the compiler.

    I don't think either equality or inequality operators are really needed,
    because the public _GLIBCXX_STD_C::bitset base class cam always be
    compared using its own comparison operators. I'm not changing that here
    though.

    libstdc++-v3/ChangeLog:

            PR libstdc++/96303
            * include/debug/bitset (bitset::operator==): Call _M_base() on
            right operand.
            (bitset::operator!=): Likewise, but don't define it at all when
            default comparisons are supported by the compiler.
            * testsuite/23_containers/bitset/operations/96303.cc: New test.

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

* [Bug libstdc++/96303] [10/11 Regression] Ambiguous overload for operator!= for std::__debug::bitset compiled with -std=c++20 and -pedantic.
  2020-07-23 19:01 [Bug libstdc++/96303] New: Ambiguous overload for operator!= for std::__debug::bitset compiled with -std=c++20 and -pedantic matt.lawson at precisionplanting dot com
  2020-07-23 19:18 ` [Bug libstdc++/96303] [10/11 Regression] " redi at gcc dot gnu.org
  2020-08-07 19:29 ` cvs-commit at gcc dot gnu.org
@ 2020-08-07 19:46 ` cvs-commit at gcc dot gnu.org
  2020-08-07 19:46 ` redi at gcc dot gnu.org
  2020-08-27 12:37 ` redi at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-08-07 19:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:7e26e4fbd4ee618dd991c6bbf3c5403aa90d2192

commit r10-8592-g7e26e4fbd4ee618dd991c6bbf3c5403aa90d2192
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Aug 7 20:29:11 2020 +0100

    libstdc++: Fix ambiguous comparisons in __gnu_debug::bitset [PR 96303]

    With -pedantic the debug mode bitset has an ambiguous equality
    comparison operator, because it tries to compare the non-debug base to
    the debug object. The base object can be converted to another debug
    bitset, making the same operator== a candidate again.

    The fix is to do the comparison on both base objects, so the operator
    for the derived type isn't a candidate.

    For the inequality operator the same change should be done, but that
    operator can be removed entirely for C++20 because it can be synthesized
    by the compiler.

    I don't think either equality or inequality operators are really needed,
    because the public _GLIBCXX_STD_C::bitset base class cam always be
    compared using its own comparison operators. I'm not changing that here
    though.

    libstdc++-v3/ChangeLog:

            PR libstdc++/96303
            * include/debug/bitset (bitset::operator==): Call _M_base() on
            right operand.
            (bitset::operator!=): Likewise, but don't define it at all when
            default comparisons are supported by the compiler.
            * testsuite/23_containers/bitset/operations/96303.cc: New test.

    (cherry picked from commit de1e3b8795e507c3cfa5b62984272628ca62a9bd)

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

* [Bug libstdc++/96303] [10/11 Regression] Ambiguous overload for operator!= for std::__debug::bitset compiled with -std=c++20 and -pedantic.
  2020-07-23 19:01 [Bug libstdc++/96303] New: Ambiguous overload for operator!= for std::__debug::bitset compiled with -std=c++20 and -pedantic matt.lawson at precisionplanting dot com
                   ` (2 preceding siblings ...)
  2020-08-07 19:46 ` cvs-commit at gcc dot gnu.org
@ 2020-08-07 19:46 ` redi at gcc dot gnu.org
  2020-08-27 12:37 ` redi at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2020-08-07 19:46 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for 10.3, thanks for the report.

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

* [Bug libstdc++/96303] [10/11 Regression] Ambiguous overload for operator!= for std::__debug::bitset compiled with -std=c++20 and -pedantic.
  2020-07-23 19:01 [Bug libstdc++/96303] New: Ambiguous overload for operator!= for std::__debug::bitset compiled with -std=c++20 and -pedantic matt.lawson at precisionplanting dot com
                   ` (3 preceding siblings ...)
  2020-08-07 19:46 ` redi at gcc dot gnu.org
@ 2020-08-27 12:37 ` redi at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2020-08-27 12:37 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jeanmichael.celerier@gmail.
                   |                            |com

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
*** Bug 96816 has been marked as a duplicate of this bug. ***

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

end of thread, other threads:[~2020-08-27 12:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-23 19:01 [Bug libstdc++/96303] New: Ambiguous overload for operator!= for std::__debug::bitset compiled with -std=c++20 and -pedantic matt.lawson at precisionplanting dot com
2020-07-23 19:18 ` [Bug libstdc++/96303] [10/11 Regression] " redi at gcc dot gnu.org
2020-08-07 19:29 ` cvs-commit at gcc dot gnu.org
2020-08-07 19:46 ` cvs-commit at gcc dot gnu.org
2020-08-07 19:46 ` redi at gcc dot gnu.org
2020-08-27 12:37 ` 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).