[LLVMbugs] [Bug 23838] New: multiple definitions of static variables inside functions

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Jun 12 20:01:13 PDT 2015


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

            Bug ID: 23838
           Summary: multiple definitions of static variables inside
                    functions
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: heavenandhell171 at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Clang is not generating comdats for static variables of classes with virtual
members.

$ cat > h.h
class error_category {
public:
  virtual void fn() {}
};

inline error_category& make_error_code() {
  static error_category C;
  return C;
}

$ cat > t1.cpp
#include "h.h"

int main(int argc, char **argv) {
  make_error_code();
  return 0;
}

$ cat > t2.cpp
#include "h.h"

void foo() {
  make_error_code();
}

$ clang++ -std=c++11 t1.cpp t2.cpp -target i686-windows-gnu
C:\Dev\MSys2\tmp\test2-135e49.o:(.data+0x0): multiple definition of
`make_error_code()::C'
C:\Dev\MSys2\tmp\test-bf4e7c.o:(.data+0x0): first defined here
clang++.exe: error: linker command failed with exit code 1 (use -v to see
invocation)

I'm targeting Mingw here, but it doesn't work when targeting MSVC either.
Removing virtual from 'void fn()' makes clang work.

-- 
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/20150613/282574eb/attachment.html>


More information about the llvm-bugs mailing list