public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95626] New: [concepts] incorrect ambiguous overload with constraints "A && !B" vs "!B"
@ 2020-06-10 18:29 godeffroy.valet at m4x dot org
  2020-06-10 18:52 ` [Bug c++/95626] " redi at gcc dot gnu.org
  2020-06-11  9:05 ` godeffroy.valet at m4x dot org
  0 siblings, 2 replies; 3+ messages in thread
From: godeffroy.valet at m4x dot org @ 2020-06-10 18:29 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95626
           Summary: [concepts] incorrect ambiguous overload with
                    constraints "A && !B" vs "!B"
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: godeffroy.valet at m4x dot org
  Target Milestone: ---

Created attachment 48715
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48715&action=edit
preprocessed source code

The following code fails to compile, giving an "ambiguous overload" error while
one function is clrearly more constrined than the other.

////////////////////////////////////////////////////////////////
#include<type_traits>
template<class T> concept ConceptA=std::is_same<T,int>::value;
template<class T> concept ConceptB=std::is_same<T,float>::value;

    template<class A>
    requires (!ConceptB<A> && ConceptA<A>)
    auto constexpr test__(A const& ){
    }

    template<class A>
    requires (!ConceptB<A>)
    auto constexpr test__(A const& ){
    }

int main(){
    test__(2); // error
}
////////////////////////////////////////////////////////////////

Note that the negation in "!ConceptB<A>" is required to reproduced the issue.
In particular, the following code compiles.

////////////////////////////////////////////////////////////////
#include<type_traits>
template<class T> concept ConceptA=std::is_same<T,int>::value;
template<class T> concept ConceptB=!std::is_same<T,float>::value;

    template<class A>
    requires (ConceptB<A> && ConceptA<A>)
    auto constexpr test__(A const& ){
    }

    template<class A>
    requires (ConceptB<A>)
    auto constexpr test__(A const& ){
    }

int main(){
    test__(2); // OK
}
////////////////////////////////////////////////////////////////

Command used : g++ -std=c++2a -Wall -Wextra test.cpp
Output :
geometry/algebra/definition.test.cpp: In function 'int main()':
geometry/algebra/definition.test.cpp:23:10: error: call of overloaded
'test__(int)' is ambiguous
   23 |  test__(2);
      |          ^
geometry/algebra/definition.test.cpp:10:17: note: candidate: 'constexpr auto
test__(const A&) [with A = int]'
   10 |  auto constexpr test__(A const& ){
      |                 ^~~~~~
geometry/algebra/definition.test.cpp:14:17: note: candidate: 'constexpr auto
test__(const A&) [with A = int]'
   14 |  auto constexpr test__(A const& ){
      |                 ^~~~~~

Output of gcc -v :
Utilisation des specs internes.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0/lto-wrapper
Cible : x86_64-pc-linux-gnu
Configuré avec: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --with-isl
--with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit
--enable-cet=auto --enable-checking=release --enable-clocale=gnu
--enable-default-pie --enable-default-ssp --enable-gnu-indirect-function
--enable-gnu-unique-object --enable-install-libiberty --enable-linker-build-id
--enable-lto --enable-multilib --enable-plugin --enable-shared
--enable-threads=posix --disable-libssp --disable-libstdcxx-pch
--disable-libunwind-exceptions --disable-werror
gdc_include_dir=/usr/include/dlang/gdc
Modèle de thread: posix
Algorithmes de compression LTO supportés: zlib zstd
gcc version 10.1.0 (GCC)

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

* [Bug c++/95626] [concepts] incorrect ambiguous overload with constraints "A && !B" vs "!B"
  2020-06-10 18:29 [Bug c++/95626] New: [concepts] incorrect ambiguous overload with constraints "A && !B" vs "!B" godeffroy.valet at m4x dot org
@ 2020-06-10 18:52 ` redi at gcc dot gnu.org
  2020-06-11  9:05 ` godeffroy.valet at m4x dot org
  1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2020-06-10 18:52 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This is not a bug, subsumption doesn't work for !B

To make it work you need to define a concept, as in your second example.

This is explained in the C++20 draft by the note in [temp.constr.op] p5, which
was added by https://wg21.link/p1971r0#US111

*** This bug has been marked as a duplicate of bug 92102 ***

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

* [Bug c++/95626] [concepts] incorrect ambiguous overload with constraints "A && !B" vs "!B"
  2020-06-10 18:29 [Bug c++/95626] New: [concepts] incorrect ambiguous overload with constraints "A && !B" vs "!B" godeffroy.valet at m4x dot org
  2020-06-10 18:52 ` [Bug c++/95626] " redi at gcc dot gnu.org
@ 2020-06-11  9:05 ` godeffroy.valet at m4x dot org
  1 sibling, 0 replies; 3+ messages in thread
From: godeffroy.valet at m4x dot org @ 2020-06-11  9:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Godeffroy Valet <godeffroy.valet at m4x dot org> ---
Oh, ok, thank you for the information. Strange rule...

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

end of thread, other threads:[~2020-06-11  9:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-10 18:29 [Bug c++/95626] New: [concepts] incorrect ambiguous overload with constraints "A && !B" vs "!B" godeffroy.valet at m4x dot org
2020-06-10 18:52 ` [Bug c++/95626] " redi at gcc dot gnu.org
2020-06-11  9:05 ` godeffroy.valet at m4x dot 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).