<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - static char strange linker error"
   href="https://llvm.org/bugs/show_bug.cgi?id=23177">23177</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>static char strange linker error
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>release blocker
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>daniel.liverance@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>