public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114165] New: &scalar+1 and array+1 rejected as template parameters
@ 2024-02-29 11:34 nabijaczleweli at nabijaczleweli dot xyz
  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
  0 siblings, 2 replies; 3+ messages in thread
From: nabijaczleweli at nabijaczleweli dot xyz @ 2024-02-29 11:34 UTC (permalink / raw)
  To: gcc-bugs

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}.

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

* [Bug c++/114165] &scalar+1 and array+1 rejected as template parameters
  2024-02-29 11:34 [Bug c++/114165] New: &scalar+1 and array+1 rejected as template parameters nabijaczleweli at nabijaczleweli dot xyz
@ 2024-03-01 18:42 ` pinskia at gcc dot gnu.org
  2024-03-01 18:49 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-01 18:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
<source>:17:32: error: '((& scalar) + 4)' is not a valid template argument for
'int*' because it is not the address of a variable

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

* [Bug c++/114165] &scalar+1 and array+1 rejected as template parameters
  2024-02-29 11:34 [Bug c++/114165] New: &scalar+1 and array+1 rejected as template parameters nabijaczleweli at nabijaczleweli dot xyz
  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
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-01 18:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reduced testcase:
```
template<int *, int *>
void withP() {}
int array[2];
int main() {
  withP<array, array+1>();
  withP<array, &array[1]>();
}
```

GCC and MSVC both reject `array+1` .
All three accept `&array[1]` though in C++20+.

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

end of thread, other threads:[~2024-03-01 18:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-29 11:34 [Bug c++/114165] New: &scalar+1 and array+1 rejected as template parameters nabijaczleweli at nabijaczleweli dot xyz
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

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).