c3c
c3c copied to clipboard
(bug?) Unexpected behaviour when using global const strings as enum associated values.
Regular case (works fine):
import std::io;
enum Example : int (String str) {
FOO = { "foo" },
}
fn void main() {
io::printfn( "%s", Example.FOO.str ); // prints `foo`
}
But the following:
import std::io;
const FOO_STR = "foo";
enum Example : int (String str) {
FOO = { FOO_STR },
}
fn void main() {
io::printfn( "%s", Example.FOO.str ); // error!
}
will print something like:
/usr/bin/ld: build/tmp/app.o:(.data.rel.ro.Example$str[Example$str]+0x0): undefined reference to `.tempglobal'
Currently it seems that the expected behaviour can be achieved by explicitly defining the type of the const thusly:
const char[] FOO_STR = "foo";
This should now work.
Can you check so we can close it?
@lerno I tried this example and it works. However, the syntax is a bit off here and not sure how it worked (unless it was a typo). A single element associated enum cannot use {} syntax, and must be assigned directly.
Can confirm this works in the latest. This is the example:
import std::io;
const FOO_STR = "foo";
enum Example : int (String str) {
FOO = FOO_STR,
}
fn int main() {
io::printfn("%s", Example.FOO.str); // foo
return 0;
}