public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "godeffroy.valet at m4x dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/95626] New: [concepts] incorrect ambiguous overload with constraints "A && !B" vs "!B"
Date: Wed, 10 Jun 2020 18:29:17 +0000	[thread overview]
Message-ID: <bug-95626-4@http.gcc.gnu.org/bugzilla/> (raw)

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)

             reply	other threads:[~2020-06-10 18:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-10 18:29 godeffroy.valet at m4x dot org [this message]
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

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