This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]