[Bug c++/91344] New: Function pointers in templates with restrict semantics may fail to compile.
a-yee at u dot northwestern.edu
gcc-bugzilla@gcc.gnu.org
Sun Aug 4 05:11:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91344
Bug ID: 91344
Summary: Function pointers in templates with restrict semantics
may fail to compile.
Product: gcc
Version: 9.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: a-yee at u dot northwestern.edu
Target Milestone: ---
The following code compiles on Clang, MSVC, and ICC. But it fails on GCC.
https://godbolt.org/z/zHq0qi
#include <iostream>
using namespace std;
#ifdef _WIN32
#define RESTRICT __restrict
#else
#define RESTRICT __restrict__
#endif
// Works
//template <typename type> using r_ptr = type *;
// Fails
template <typename type> using r_ptr = type *RESTRICT;
template <void (*fp)(r_ptr<int> ptr)>
void foo(){
int x = 123;
fp(&x);
}
void fp(r_ptr<int> ptr){
cout << ptr[0] << endl;
}
int main(int argc, char* argv[]) {
foo<fp>();
}
But on GCC, it gives:
<source>: In function 'int main(int, char**)':
<source>:30:13: error: no matching function for call to 'foo<fp>()'
30 | foo<fp>();
| ^
<source>:19:6: note: candidate: 'template<void (* fp)(r_ptr<int>)> void foo()'
19 | void foo(){
| ^~~
<source>:19:6: note: template argument deduction/substitution failed:
<source>:30:13: error: could not convert template argument 'fp' from
'void(r_ptr<int>)' {aka 'void(int*)'} to 'void (*)(int* __restrict__)'
30 | foo<fp>();
| ^
ASM generation compiler returned: 1
<source>: In function 'int main(int, char**)':
<source>:30:13: error: no matching function for call to 'foo<fp>()'
30 | foo<fp>();
| ^
<source>:19:6: note: candidate: 'template<void (* fp)(r_ptr<int>)> void foo()'
19 | void foo(){
| ^~~
<source>:19:6: note: template argument deduction/substitution failed:
<source>:30:13: error: could not convert template argument 'fp' from
'void(r_ptr<int>)' {aka 'void(int*)'} to 'void (*)(int* __restrict__)'
30 | foo<fp>();
|
More information about the Gcc-bugs
mailing list