public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jlegg at feralinteractive dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/100893] New: Template argument conversion fails for dependant constant function pointer template parameters
Date: Thu, 03 Jun 2021 13:22:22 +0000	[thread overview]
Message-ID: <bug-100893-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 100893
           Summary: Template argument conversion fails for dependant
                    constant function pointer template parameters
           Product: gcc
           Version: 11.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jlegg at feralinteractive dot com
  Target Milestone: ---

When compiling this C++ code:
void f();
struct S {using F = void (* const)();};
template <typename T, typename T::F f> void g() {}
void h() {g<S, &f>();}

GCC 11.1.1, and (much) earlier versions, reject it with:
<source>: In function 'void h()':
<source>:4:19: error: no matching function for call to 'g<S, f>()'
    4 | void h() {g<S, &f>();}
      |           ~~~~~~~~^~
<source>:3:45: note: candidate: 'template<class T, typename T::F f> void g()'
    3 | template <typename T, typename T::F f> void g() {}
      |                                             ^
<source>:3:45: note:   template argument deduction/substitution failed:
<source>:4:16: error: could not convert template argument 'f' from 'void (*)()'
to 'void (* const)()'
    4 | void h() {g<S, &f>();}
      |                ^~

My language lawyering isn't good enough to explain why, but I think the
template argument conversion should work, and the compiler should behave as it
does when the const is removed. Similar conversions seem to work if F is a
constant type but not a function pointer, or if the second template parameter
on g is not dependant on the first. MSVC and Clang also accept the example
code.

             reply	other threads:[~2021-06-03 13:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-03 13:22 jlegg at feralinteractive dot com [this message]
2021-06-03 16:14 ` [Bug c++/100893] " ppalka at gcc dot gnu.org
2021-06-04 18:10 ` cvs-commit at gcc dot gnu.org
2021-06-04 18:11 ` ppalka at gcc dot gnu.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-100893-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).