public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114620] New: Pointer-to-member template argument which is the member of a base class is rejected
@ 2024-04-06 15:36 mital at mitalashok dot co.uk
  2024-04-09  0:33 ` [Bug c++/114620] " pinskia at gcc dot gnu.org
  2024-04-09  0:37 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: mital at mitalashok dot co.uk @ 2024-04-06 15:36 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114620
           Summary: Pointer-to-member template argument which is the
                    member of a base class is rejected
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mital at mitalashok dot co.uk
  Target Milestone: ---

The following is incorrectly rejected:

    struct Base {
        int x;
    };
    struct Derived : Base {
        int y;
    };
    template<int Derived::*> struct X;

    // error: '&Base::x' is not a valid template argument for type 'int
Derived::*'
    using T1 = X<&Derived::x>;
    //           ^~~~~~~~~~~
    // note: because it is a member of 'Base'

    constexpr int Derived::* pm = &Derived::x;
    // error: '0' is not a valid template argument for type 'int Derived::*'
    using T2 = X<pm>;
    //             ^
    // note: it must be a pointer-to-member of the form '&X::Y'

And replacing `&Derived::x` with `&Derived::y` works. The same problems happen
with pointer-to-member-functions instead of pointers to data members.

This seems similar to Bug 104678

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

* [Bug c++/114620] Pointer-to-member template argument which is the member of a base class is rejected
  2024-04-06 15:36 [Bug c++/114620] New: Pointer-to-member template argument which is the member of a base class is rejected mital at mitalashok dot co.uk
@ 2024-04-09  0:33 ` pinskia at gcc dot gnu.org
  2024-04-09  0:37 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-09  0:33 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-04-09
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The first one is rejected by EDG, clang, GCC and MSVC for similar reasons.


MSVC:
<source>(13): error C2440: 'specialization': cannot convert from 'int Base::* '
to 'int Derived::* '
<source>(13): note: Standard conversion from pointer-to-member of base to
pointer-to-member of derived is not applied for template arguments



But the constexpr version is definitely a GCC bug as it is accepted by all 3
other compilers.

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

* [Bug c++/114620] Pointer-to-member template argument which is the member of a base class is rejected
  2024-04-06 15:36 [Bug c++/114620] New: Pointer-to-member template argument which is the member of a base class is rejected mital at mitalashok dot co.uk
  2024-04-09  0:33 ` [Bug c++/114620] " pinskia at gcc dot gnu.org
@ 2024-04-09  0:37 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-09  0:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This also should be valid for C++17 +:
```
template<class M, char M::*> struct T{};
struct A{char x;};
struct B:A{  };
struct C:A{ T<B,(char B::*)&B::x> y; };
```

Note the constexpr case is only valid for C++17 + too.

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

end of thread, other threads:[~2024-04-09  0:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-06 15:36 [Bug c++/114620] New: Pointer-to-member template argument which is the member of a base class is rejected mital at mitalashok dot co.uk
2024-04-09  0:33 ` [Bug c++/114620] " pinskia at gcc dot gnu.org
2024-04-09  0:37 ` pinskia 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).