[Bug c++/67969] [concepts] bug with overloaded function when using constraints
ppalka at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Jan 31 13:51:26 GMT 2022
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.
More information about the Gcc-bugs
mailing list