<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - constexpr static variable template in class fails at link-time"
   href="https://bugs.llvm.org/show_bug.cgi?id=35753">35753</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>constexpr static variable template in class fails at link-time
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>4.0
          </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>enhancement
          </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>emil.fresk@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Hi all,

I have been testing variable templates under C++14 and C++17, however using a
constexpr static variable template in a class gives link-errors on optimization
level 0 and 1, while at a higher level it works fine (probably when the
variable template is inlined?).
It seems as if the variable template is never created, and the compiler gives
an undefined reference error at link-time.
This error has been tested on Clang 3.8, 4.0 and 5.0.



Test setup:
Linux 4.13.0-21-generic #24~16.04.1-Ubuntu Xenial



Compile commands:
-- Failing (-O0, -O1)
clang++-3.8 -std=c++14 test.cpp -O0
clang++-3.8 -std=c++14 test.cpp -O1
clang++-4.0 -std=c++14 test.cpp -O0
clang++-4.0 -std=c++14 test.cpp -O1
clang++-5.0 -std=c++14 test.cpp -O0
clang++-5.0 -std=c++14 test.cpp -O1

-- Working (-O2 or higher)
clang++-3.8 -std=c++14 test.cpp -O2
clang++-4.0 -std=c++14 test.cpp -O2
clang++-5.0 -std=c++14 test.cpp -O2



Compiler versions:
clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
clang version 4.0.0-1ubuntu1~16.04.2 (tags/RELEASE_400/rc1)
Sadly I am on the wrong computer to get the clang-5.0 version, but it is the
current one from the PPA (deb <a href="http://apt.llvm.org/xenial/">http://apt.llvm.org/xenial/</a>
llvm-toolchain-xenial-5.0 main)



Error:
/tmp/test-cd1427.o: In function `test::test<run()::$_0>(run()::$_0&&)':
test.cpp:(.text+0x34): undefined reference to `test::make_vtable<run()::$_0>'
test.cpp:(.text+0x3f): undefined reference to `test::make_vtable<run()::$_0>'
clang: error: linker command failed with exit code 1 (use -v to see invocation)



Test code in attached test.cpp.</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>