public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "nabijaczleweli at nabijaczleweli dot xyz" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/114165] New: &scalar+1 and array+1 rejected as template parameters
Date: Thu, 29 Feb 2024 11:34:05 +0000	[thread overview]
Message-ID: <bug-114165-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 114165
           Summary: &scalar+1 and array+1 rejected as template parameters
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nabijaczleweli at nabijaczleweli dot xyz
  Target Milestone: ---

Given:
    void consoom(void(*)());

    template<int *, unsigned>
    void withN() {}

    template<int *, int *>
    void withP() {}


    static int scalar;
    static int array[1];


    int main() {
        consoom(withN<&scalar, 1>);
        consoom(withN<array,   1>);
        consoom(withP<&scalar, &scalar + 1>);
        consoom(withP<array,   array + 1>);
    }
clang trunk and gcc trunk -std=c++{11,14,17} agree that 
    <source>: In function 'int main()':
    <source>:17:12: error: no matches converting function 'withP' to type 'void
(*)()'
       17 |     consoom(withP<&scalar, &scalar + 1>);
          |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    <source>:7:6: note: candidate is: 'template<int* <anonymous>, int*
<anonymous> > void withP()'
        7 | void withP() {}
          |      ^~~~~
    <source>:18:12: error: no matches converting function 'withP' to type 'void
(*)()'
       18 |     consoom(withP<array,   array + 1>);
          |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
    <source>:7:6: note: candidate is: 'template<int* <anonymous>, int*
<anonymous> > void withP()'
        7 | void withP() {}
          |      ^~~~~
    Compiler returned: 1
or
    <source>:17:5: error: no matching function for call to 'consoom'
       17 |     consoom(withP<&scalar, &scalar + 1>);
          |     ^~~~~~~
    <source>:1:6: note: candidate function not viable: no overload of 'withP'
matching 'void (*)()' for 1st argument
        1 | void consoom(void(*)());
          |      ^       ~~~~~~~~~
    <source>:18:5: error: no matching function for call to 'consoom'
       18 |     consoom(withP<array,   array + 1>);
          |     ^~~~~~~
    <source>:1:6: note: candidate function not viable: no overload of 'withP'
matching 'void (*)()' for 1st argument
        1 | void consoom(void(*)());
          |      ^       ~~~~~~~~~
    2 errors generated.
    Compiler returned: 1

clang trunk -std=c++20 accepts the code.
GCC trunk -std=c++20 rejects the code with the same error.

https://godbolt.org/z/63xzf1MT6

Per my reading of [temp.arg.nontype].6, this is allowed in C++20 because it's
not rejected by [temp.arg.nontype].6.{1,2,3,4,5}.

             reply	other threads:[~2024-02-29 11:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-29 11:34 nabijaczleweli at nabijaczleweli dot xyz [this message]
2024-03-01 18:42 ` [Bug c++/114165] " pinskia at gcc dot gnu.org
2024-03-01 18:49 ` pinskia 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-114165-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).