<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/143929>143929</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
WebAssembly tables cannot be declared in non-global scope
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
feedab1e
</td>
</tr>
</table>
<pre>
While a declaration like the following is accepted by the compiler:
```cpp
static __externref_t table[0];
```
the same declaration in a namespace is not ([link](https://gcc.godbolt.org/z/qWbcfTj6E)):
```cpp
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](https://gcc.godbolt.org/z/WW4oP37G6)):
```cpp
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.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMlU9v4zYQxT8NfRnEoEn9iQ46KNm46K2HBXwM-GckcZciVZKK6_30BWUHG2eTbVr0sIIMG7Y5_M2b90QRoxkcYkvKO1J-2ogljT60PaIWcocb6fWpPYzGIgjQqKwIIhnvwJqvCGlE6L21_mjcACaCUArnhBrkaf1R-Wk2FgPhHaEdqej5VvNMaBeTSEbB4yP-lTC4gP1jgiSkRVLeUVJ-Ivzu5SpCu1wzigmvUIwDAU5MGGehMGM4n4CwW1LeWeO-5krsdkxpjpmD7QnbD0ptB6-lt2nrw0DY_hth-z8PUvWfv1QPhDX5fov6-0a990DqjAjvt7K77qV-o6k5eL0ojK--Jvw--iUoJPyB8I7lV0V4BxiCz4rCAWUXI07Sns6bgRIu9y6fBUINR5PGVaF-cSrrlXkBgAGp7z8MDuuVV7x7kfKB0G53xoMBHQaRUG8J7e4vNoCAaQkOdabfver3OBo1riaCXphgTxBTEG5A0EYMzscMqryLRmPIfkujSKvLrsxwnv5VxxmB0O7zs3lMjAuCV2oJEY4jOkjhtFb0z7qBuCgqMs9FpQkniQF8DwKUFTGCD2BWoBe7_SfnHQ6F_4PXv1U_cV5MYVEJpAjPtgP4yQDZ28578kaDFN8yJWs-VIn_UOnXMfC_0eDDJn5FXv7P5OU_RI-_Q32BeyHxw1M27-iXYVyTYEVML-NiIgQzjGse3ovLNSG7h99B5w91gojZ2AFF9A6OY36mmwhx9IvV539IBJGf_6i3G91y3fBGbLDd1UVTF1VBq83YqrpqkPZ1xRnvOVLa90gbzQrNWSMl25iWUVbSasd2VUFpteVFWUpUt6JmqqiZIAXFSRi7tfZpyqnZrBFudwVvWLOxQqKN6xHGmMPjOeCEsXyihTYvupHLEElBrYkpfi-TTLLY_jDM-NY0jQPn3c1gvRQWovIzbpZg21fxNmlc5Fb5ibB93ufydjMH_wVVImy_0kXC9hf8p5b9HQAA__9ChVYv">