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: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to