This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Dynamically allocated array of function pointers
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: "Vladimir Reshetnikov (v dot reshetnikov at gmail dot com)" <v dot reshetnikov at gmail dot com>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Sat, 28 Jul 2018 13:10:47 +0100
- Subject: Re: Dynamically allocated array of function pointers
- References: <CABdyEv9NNJ4EKiLF49Ct08X8+j1w84QMv5fm-0XQz=dm3ON3tg@mail.gmail.com>
Please don't cross-post to this list and to gcc-help, this question is
off-topic here
On Sat, 28 Jul 2018 at 04:01, Vladimir Reshetnikov
<v.reshetnikov@gmail.com> wrote:
>
> 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