www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22427] New: betterC: casting an array causes linker error in


          Issue ID: 22427
           Summary: betterC: casting an array causes linker error in
                    string comparison.
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dave287091 gmail.com

This reduced code fails to link. 
// foo.d
int main(){
    if("a" == "a")
        return 1;
    char[] p;
    auto a = cast(int[])p;
    return 0;

A linker error results:

Undefined symbols for architecture x86_64:
referenced from:
      _main in foo.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: /usr/bin/cc failed with status: 1

The undefined symbol demangles to:
pure nothrow  nogc  trusted bool core.internal.array.equality.__equals!(char,
char).__equals(scope const(char[]), scope const(char[]))

I have verified this problem happens both with dmd and ldc2. ldc2 1.24 - 1.28
has the error. Older ldc do not. Current dmd has the error, I don’t know how
far back.

Oct 18 2021