[llvm-bugs] [Bug 35753] New: constexpr static variable template in class fails at link-time

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Dec 26 11:30:40 PST 2017


            Bug ID: 35753
           Summary: constexpr static variable template in class fails at
           Product: clang
           Version: 4.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: emil.fresk at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

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 http://apt.llvm.org/xenial/
llvm-toolchain-xenial-5.0 main)

/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.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20171226/589cb370/attachment-0001.html>

More information about the llvm-bugs mailing list