[llvm-bugs] [Bug 50380] New: class static object member is initlized twice

via llvm-bugs llvm-bugs at lists.llvm.org
Mon May 17 20:30:30 PDT 2021


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

            Bug ID: 50380
           Summary: class static object member is initlized twice
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: pangbw at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Created attachment 24862
  --> https://bugs.llvm.org/attachment.cgi?id=24862&action=edit
tar file to reproduce the issue

steps to reproduce the issue:
$ tar xvf bug.zar
$/data/bpang/clang+llvm-12.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang++ 2.cpp
3.cpp 4.cpp
/data/bpang/clang+llvm-12.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang++ 2.cpp
3.cpp 4.cpp
/data/bpang/V_X_7/TCLLVM-280/vxsim_linux-lp64 $./a.out
./a.out
1
1
2
2
maxRect top -65536
/data/bpang/V_X_7/TCLLVM-280/vxsim_linux-lp64
$/data/bpang/clang+llvm-12.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang++ 3.cpp
2.cpp 4.cpp
/data/bpang/clang+llvm-12.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang++ 3.cpp
2.cpp 4.cpp
/data/bpang/V_X_7/TCLLVM-280/vxsim_linux-lp64 $./a.out
./a.out
2
2
1
1
maxRect top 65535

We can see depending on the order of 2.cpp and 3.cpp, the result is different.

And if compile/build these files with g++, we get a linking error:
/data/bpang/V_X_7/TCLLVM-280/vxsim_linux-lp64 $g++ 3.cpp 2.cpp 4.cpp
g++ 3.cpp 2.cpp 4.cpp
/tmp/ccUMUhCb.o:(.bss._ZN6_TRectIiE7maxRectE[_ZN6_TRectIiE7maxRectE]+0x0):
multiple definition of `_TRect<int>::maxRect'
/tmp/ccTplkLE.o:(.bss+0x10): first defined here
/tmp/ccUMUhCb.o:(.bss._ZN6_TRectIiE8nullRectE[_ZN6_TRectIiE8nullRectE]+0x0):
multiple definition of `_TRect<int>::nullRect'
/tmp/ccTplkLE.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status
/data/bpang/V_X_7/TCLLVM-280/vxsim_linux-lp64 $g++ 2.cpp 3.cpp 4.cpp
g++ 2.cpp 3.cpp 4.cpp
/tmp/cc0QlF4s.o:(.bss+0x0): multiple definition of `_TRect<int>::nullRect'
/tmp/ccqmyACC.o:(.bss._ZN6_TRectIiE8nullRectE[_ZN6_TRectIiE8nullRectE]+0x0):
first defined here
/tmp/cc0QlF4s.o:(.bss+0x10): multiple definition of `_TRect<int>::maxRect'
/tmp/ccqmyACC.o:(.bss._ZN6_TRectIiE7maxRectE[_ZN6_TRectIiE7maxRectE]+0x0):
first defined here
collect2: error: ld returned 1 exit status

-- 
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/20210518/10185311/attachment-0001.html>


More information about the llvm-bugs mailing list