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