Skip to content

WebAssembly tables cannot be declared in non-global scope #143929

Open
@feedab1e

Description

@feedab1e

While a declaration like the following is accepted by the compiler:

static __externref_t table[0];

the same declaration in a namespace is not (link):

namespace foo {
    static __externref_t table1[0];
};

produces

<source>:2:26: error: WebAssembly table cannot be declared within a function
    2 |     static __externref_t table1[0];
      |                          ^
1 error generated.
Compiler returned: 1

which is a fairly strange diagnostic considering that the declaration is not in a function.

The same issue occurs when trying to declare a table as a static member of a class or inside a function (link):

struct bar {
    static __externref_t table2[0];
};
void baz() {
    static __externref_t table3[0];
}

produces

<source>:2:26: error: WebAssembly table cannot be declared within a function
    2 |     static __externref_t table2[0];
      |                          ^
<source>:5:26: error: WebAssembly table cannot be declared within a function
    5 |     static __externref_t table3[0];
      |                          ^

Even though the last diagnostic is right in that the declaration is in a function, I don't see a reason why this shouldn't be allowed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions