public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104867] New: Base class matching ignores type of `auto` template parameter
@ 2022-03-10 16:56 pdimov at gmail dot com
  2022-03-11 14:40 ` [Bug c++/104867] " ppalka at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: pdimov at gmail dot com @ 2022-03-10 16:56 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104867
           Summary: Base class matching ignores type of `auto` template
                    parameter
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pdimov at gmail dot com
  Target Milestone: ---

The following program

```
enum class Foo
{
    A1
};

enum class Bar
{
    B1
};

template <auto EnumVal> struct enum_
{
};

template<class...> struct list {};

struct enum_type_map: list<enum_<Foo::A1>, int>, list<enum_<Bar::B1>, double>
{};

template<class V> V f( list<enum_<Bar::B1>, V> const& )
{
    return {};
}

int main()
{
    f( enum_type_map() );
}
```

yields

```
<source>: In function 'int main()':
<source>:26:6: error: no matching function for call to 'f(enum_type_map)'
   26 |     f( enum_type_map() );
      |     ~^~~~~~~~~~~~~~~~~~~
<source>:19:21: note: candidate: 'template<class V> V f(const
list<enum_<Bar::B1>, V>&)'
   19 | template<class V> V f( list<enum_<Bar::B1>, V> const& )
      |                     ^
<source>:19:21: note:   template argument deduction/substitution failed:
<source>:26:6: note:   'const list<enum_<Bar::B1>, V>' is an ambiguous base
class of 'enum_type_map'
   26 |     f( enum_type_map() );
      |     ~^~~~~~~~~~~~~~~~~~~
```

which is caused by `A1` and `B1` having the same value 0, even though their
types differ. (https://godbolt.org/z/3854zrY7x)

Clang successfully compiles the code (https://godbolt.org/z/eKEdf1zdo).

This is a distilled version of a bug report against `mp_map_find` from Mp11:
https://github.com/boostorg/mp11/issues/72

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

* [Bug c++/104867] Base class matching ignores type of `auto` template parameter
  2022-03-10 16:56 [Bug c++/104867] New: Base class matching ignores type of `auto` template parameter pdimov at gmail dot com
@ 2022-03-11 14:40 ` ppalka at gcc dot gnu.org
  2023-12-13 20:57 ` cvs-commit at gcc dot gnu.org
  2023-12-16 17:15 ` ppalka at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-03-11 14:40 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppalka at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2022-03-11
     Ever confirmed|0                           |1

--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Confirmed, this never worked.

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

* [Bug c++/104867] Base class matching ignores type of `auto` template parameter
  2022-03-10 16:56 [Bug c++/104867] New: Base class matching ignores type of `auto` template parameter pdimov at gmail dot com
  2022-03-11 14:40 ` [Bug c++/104867] " ppalka at gcc dot gnu.org
@ 2023-12-13 20:57 ` cvs-commit at gcc dot gnu.org
  2023-12-16 17:15 ` ppalka at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-12-13 20:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:35ba3add7d0a9fc6ce955ba8ad82b0413e86ad7d

commit r14-6520-g35ba3add7d0a9fc6ce955ba8ad82b0413e86ad7d
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Dec 13 15:55:14 2023 -0500

    c++: unifying constants vs their type [PR99186, PR104867]

    When unifying constants we need to treat constants of different types
    but same value as different in light of auto template parameters since
    otherwise e.g. A<1> will unify with A<1u> (where A's template-head is
    template<auto>).  This patch fixes this in a minimal way; it seems we
    could get away with just using template_args_equal here, as we do in the
    default case, or even just cp_tree_equal since the CONVERT_EXPR_P loop
    seems to be dead code, but that's a simplification we could consider
    during next stage 1.

            PR c++/99186
            PR c++/104867

    gcc/cp/ChangeLog:

            * pt.cc (unify) <case INTEGER_CST>: Compare types as well.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp1z/nontype-auto23.C: New test.
            * g++.dg/cpp1z/nontype-auto24.C: New test.

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

* [Bug c++/104867] Base class matching ignores type of `auto` template parameter
  2022-03-10 16:56 [Bug c++/104867] New: Base class matching ignores type of `auto` template parameter pdimov at gmail dot com
  2022-03-11 14:40 ` [Bug c++/104867] " ppalka at gcc dot gnu.org
  2023-12-13 20:57 ` cvs-commit at gcc dot gnu.org
@ 2023-12-16 17:15 ` ppalka at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-12-16 17:15 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
   Target Milestone|---                         |14.0
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org
         Resolution|---                         |FIXED

--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 14

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

end of thread, other threads:[~2023-12-16 17:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-10 16:56 [Bug c++/104867] New: Base class matching ignores type of `auto` template parameter pdimov at gmail dot com
2022-03-11 14:40 ` [Bug c++/104867] " ppalka at gcc dot gnu.org
2023-12-13 20:57 ` cvs-commit at gcc dot gnu.org
2023-12-16 17:15 ` 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).