https://llvm.org/bugs/show_bug.cgi?id=23177

            Bug ID: 23177
           Summary: static char strange linker error
           Product: lld
           Version: unspecified
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: All Bugs
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

I'm using Xcode on Apple LLVM version 6.1.0 (clang-602.0.49) based on LLVM
3.6.0svn
There is a strange linker error with the following code:

#include <stdio.h>
#include <map>

class Foo
{
public:
    static const char Something = 0;
};

std::map<char, int> test_fail;

int main(int argc, const char * argv[])
{
    if (Foo::Something == 0)
    {
        char bar = Foo::Something;

        printf("Foo::Something = %d\n", bar);

        printf("Foo::Something = %d\n", Foo::Something);

        test_fail[Foo::Something] = 0;
    }

    return 0;
}


This program fails to link on the symbol Foo::Something in _main, and it's odd
because it only fails to link when using it with the std::map.
If you comment out "test_fail[Foo::Something] = 0;" it successfully links.

It will also link if you change:
static const char Something = 0; 
to:
static const unsigned char Something = 0; 

It will also link if you change:
std::map<char, int> test_fail;
to:
std::map<unsigned char, int> test_fail;

It will also compile if you cast the Foo::Something in the map usage like:
test_fail[(char)Foo::Something] = 0;
test_fail[(unsigned char)Foo::Something] = 0;
both will fix the linker error.


I believe this is a bug in the linker.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to