Thread overview
Tuples in LDC - why it does this?
Jun 14, 2022
arandomonlooker
Jun 14, 2022
rikki cattermole
Jun 14, 2022
arandomonlooker
June 14, 2022

So, i have created this program that unpacks a tuple, as a form of error handling (betterC). An error started to pop-up. This is a simple program that replicates it:

import std.typecons;
import std.meta;

Tuple!(int, int, int) iAMfunction() {
    return tuple(1, 2, 3);
}
int main() {
    int a, b, c;
    AliasSeq!(a, b, c) = iAMfunction();
    return 0;
}

In DMD, this program compiles. But, in LDC this displays an error (i used Godbolt's latest versions for both compilers, and i used betterC mode for both):

/opt/compiler-explorer/ldc1.29.0/ldc2-1.29.0-linux-x86_64/bin/../import/core/internal/entrypoint.d(39): Error: only one `main` allowed. Previously found `main` at <source>(8)
ASM generation compiler returned: 1
/opt/compiler-explorer/ldc1.29.0/ldc2-1.29.0-linux-x86_64/bin/../import/core/internal/entrypoint.d(39): Error: only one `main` allowed. Previously found `main` at <source>(8)
Execution build compiler returned: 1

This error disappears when i delete the -betterC switch from the command invokation. Is this a bug? I'm not sure. That's why i ask before filing a bug report.
Thank you all in advance.

June 14, 2022
Works in both with -betterC as per spec:

```d
import std.typecons;
import std.meta;

Tuple!(int, int, int) iAMfunction() {
    return tuple(1, 2, 3);
}

extern(C) int main() {
    int a, b, c;
    AliasSeq!(a, b, c) = iAMfunction();
    return 0;
}
```
June 14, 2022
On Tuesday, 14 June 2022 at 03:15:50 UTC, rikki cattermole wrote:
>
> Works in both with -betterC as per spec:
>
> ```d
> import std.typecons;
> import std.meta;
>
> Tuple!(int, int, int) iAMfunction() {
>     return tuple(1, 2, 3);
> }
>
> extern(C) int main() {
>     int a, b, c;
>     AliasSeq!(a, b, c) = iAMfunction();
>     return 0;
> }
> ```

Thank you. I'm a newbie to the language, i make a lot of mistakes with it, as you can see.