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

            Bug ID: 41073
           Summary: Linker error when function declared extern is defined
                    statically in one TU and non-statically in second TU
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangb...@nondot.org
          Reporter: legal...@xmission.com
                CC: htmldevelo...@gmail.com, llvm-bugs@lists.llvm.org,
                    neeil...@live.com, richard-l...@metafoo.co.uk

Created attachment 21598
  --> https://bugs.llvm.org/attachment.cgi?id=21598&action=edit
Reproducing case

See the attached code.  Reproduce with:

clang++ a.cpp b.cpp

Synopsis:

tmp.h declares extern void f();
a.cpp defines static void f() {}
b.cpp defines void f() {}

You get a linker error about multiply defined symbols.  However, this error
does not occur with gcc.  Gcc gives you an error (without -fpermissive) that
the function was declared extern and then defined static:

$ g++ a.cpp b.cpp
a.cpp: In function ‘void f()’:
a.cpp:2:15: error: ‘void f()’ was declared ‘extern’ and later ‘static’
[-fpermissive]
 static void f() {}
               ^
In file included from a.cpp:1:0:
tmp.h:1:13: note: previous declaration of ‘void f()’
 extern void f();
             ^

This is what I would expect from clang.  If I use -fpermissive with gcc, I
later get the multiply defined symbol error:

$ g++ -fpermissive a.cpp b.cpp
a.cpp: In function ‘void f()’:
a.cpp:2:15: warning: ‘void f()’ was declared ‘extern’ and later ‘static’
[-fpermissive]
 static void f() {}
               ^
In file included from a.cpp:1:0:
tmp.h:1:13: note: previous declaration of ‘void f()’
 extern void f();
             ^
/tmp/ccpDYwDv.o: In function `f()':
b.cpp:(.text+0x0): multiple definition of `f()'
/tmp/ccRPylP4.o:a.cpp:(.text+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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to