public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/67969] New: [concepts] bug with overloaded function when using constraints
@ 2015-10-14 22:12 ryan.burn at gmail dot com
  2015-10-14 22:53 ` [Bug c++/67969] " ryan.burn at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: ryan.burn at gmail dot com @ 2015-10-14 22:12 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 67969
           Summary: [concepts] bug with overloaded function when using
                    constraints
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ryan.burn at gmail dot com
  Target Milestone: ---

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

The attached code contains these two functions

template <class X> requires !Q<X>() auto func(vtype<X>, X) {}      

template <class X> requires Q<X>() auto func(vtype<X>, X) {} 

I get an ambiguous overload when trying to call it, but one should be disabled.


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

* [Bug c++/67969] [concepts] bug with overloaded function when using constraints
  2015-10-14 22:12 [Bug c++/67969] New: [concepts] bug with overloaded function when using constraints ryan.burn at gmail dot com
@ 2015-10-14 22:53 ` ryan.burn at gmail dot com
  2022-01-31 13:07 ` kirshamir at gmail dot com
  2022-01-31 13:51 ` ppalka at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: ryan.burn at gmail dot com @ 2015-10-14 22:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from ryan.burn at gmail dot com ---
Reduced further:

emplate <class, class>
class NumericArray {};

template <class>
constexpr bool match_numeric_array = false;
template <class Scalar, class Shape>
constexpr bool
    match_numeric_array<NumericArray<Scalar, Shape>> =
        true;
template <class T>
concept bool cpt_NumericArrayContainer() {
  return match_numeric_array<T>;
}

template <class X>
concept bool cpt_NumericArray() {
  return requires{requires cpt_NumericArrayContainer<X>()};
}


template <class X>
requires !cpt_NumericArray<X>() auto func(int, X) {}

template <class X>
requires cpt_NumericArray<X>() auto func(int, X) {}

int main() {
  NumericArray<double, int> v5;
  func(0, v5);
}


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

* [Bug c++/67969] [concepts] bug with overloaded function when using constraints
  2015-10-14 22:12 [Bug c++/67969] New: [concepts] bug with overloaded function when using constraints ryan.burn at gmail dot com
  2015-10-14 22:53 ` [Bug c++/67969] " ryan.burn at gmail dot com
@ 2022-01-31 13:07 ` kirshamir at gmail dot com
  2022-01-31 13:51 ` ppalka at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: kirshamir at gmail dot com @ 2022-01-31 13:07 UTC (permalink / raw)
  To: gcc-bugs

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

Amir Kirsh <kirshamir at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kirshamir at gmail dot com

--- Comment #4 from Amir Kirsh <kirshamir at gmail dot com> ---
// Bug still exists in gcc 11.2 

template<typename T>
concept SmallVar = (sizeof(T) <= sizeof(int));

void print(SmallVar auto t) {
    std::cout << t << std::endl;
}

void print(const auto& t) {
    std::cout << t << std::endl;
}

int main() {
    static_assert(SmallVar<int>); // ok
    static_assert(SmallVar<decltype(6)>); // ok
    static_assert(!SmallVar<long long>); // ok
    print("hello");
    print('a'); // gcc 11.2 sees here ambiguity
    print(6);  // gcc 11.2 sees here ambiguity
}

Code:
https://godbolt.org/z/jq8edKM3E

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

* [Bug c++/67969] [concepts] bug with overloaded function when using constraints
  2015-10-14 22:12 [Bug c++/67969] New: [concepts] bug with overloaded function when using constraints ryan.burn at gmail dot com
  2015-10-14 22:53 ` [Bug c++/67969] " ryan.burn at gmail dot com
  2022-01-31 13:07 ` kirshamir at gmail dot com
@ 2022-01-31 13:51 ` ppalka at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-01-31 13:51 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |7.0
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED
                 CC|                            |ppalka at gcc dot gnu.org

--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Amir Kirsh from comment #4)
> // Bug still exists in gcc 11.2 
> 
> template<typename T>
> concept SmallVar = (sizeof(T) <= sizeof(int));
> 
> void print(SmallVar auto t) {
>     std::cout << t << std::endl;
> }
> 
> void print(const auto& t) {
>     std::cout << t << std::endl;
> }
> 
> int main() {
>     static_assert(SmallVar<int>); // ok
>     static_assert(SmallVar<decltype(6)>); // ok
>     static_assert(!SmallVar<long long>); // ok
>     print("hello");
>     print('a'); // gcc 11.2 sees here ambiguity
>     print(6);  // gcc 11.2 sees here ambiguity
> }
> 
> Code:
> https://godbolt.org/z/jq8edKM3E

I think GCC is correct to reject those calls as ambiguous because during
partial ordering of two function templates, their constraints are considered
only if the two templates have equivalent function parameter types
(wg21.link/temp.func.order#6.2.2).  So both 'print' templates need to declare
't' consistently, e.g. https://godbolt.org/z/MMY351T9M, before constraint
subsumption can kick in as a tiebreaker.

Looks like the comment #1 testcase was fixed with r7-1159, so resolving as
fixed.

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

end of thread, other threads:[~2022-01-31 13:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-14 22:12 [Bug c++/67969] New: [concepts] bug with overloaded function when using constraints ryan.burn at gmail dot com
2015-10-14 22:53 ` [Bug c++/67969] " ryan.burn at gmail dot com
2022-01-31 13:07 ` kirshamir at gmail dot com
2022-01-31 13:51 ` ppalka 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).