This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Dynamically allocated array of function pointers
- From: Vladimir Reshetnikov <v dot reshetnikov at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Fri, 27 Jul 2018 20:01:28 -0700
- Subject: Dynamically allocated array of function pointers
I'm trying to understand why gcc rejects the dynamic array allocation in
the initializer of e (introducing an alias or additional parenthesization
suppress the error). Clang and MSVC happily compile this code. Does gcc
correctly reject this code?
template<typename T>
void f() {
typedef void(*arr[T::value])(); // OK
arr a = { }; // OK
void(*b[T::value])() = { }; // OK
void(**c)() = new arr { }; // OK
void(**d)() = new (void(*[(T::value)])()) { }; // OK
void(**e)() = new (void(*[T::value])()) { }; // error: capture of
non-variable 'T'
}
struct S {
static constexpr int value = 5;
};
int main() {
f<S>();
}
Tested against build 9.0.0 20180726 (experimental).
--
Thanks
Vladimir