<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 --- - Undefined references to static const members of class templates (but not when const is omitted)"
   href="https://llvm.org/bugs/show_bug.cgi?id=26006">26006</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Undefined references to static const members of class templates (but not when const is omitted)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>sisnkemp@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=15547" name="attach_15547" title="Test program to reproduce">attachment 15547</a> <a href="attachment.cgi?id=15547&action=edit" title="Test program to reproduce">[details]</a></span>
Test program to reproduce

The below program (also attached) produces an undefined reference to
Foo::Bar<int>::m when m is declared as const. Just compile it with clang++
test.cpp. It does not compile with the latest clang from the trunk, nor with
clang 3.5.

However, when m does not have any additional qualifiers or when m is declared
as const volatile, then the program compiles, links, and runs. You can verify
this by defining QUALS as empty or as "const volatile".

GCC compiles and links the program fine.

This code was distilled from xulrunner 24.8.0.

#define QUALS    const
//#define QUALS    const volatile
//#define QUALS

class Foo {
public:
    template <typename T>
    struct Bar {
        static QUALS long m;
    };

    static QUALS long& getter() { return Bar<int>::m; }

    static int f();
};

template <typename T>
QUALS long Foo::Bar<T>::m = 1;

int Foo::f()
{
    return getter();
}

int main()
{
    return Foo::f();
}</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>