[llvm-bugs] [Bug 41073] New: Linker error when function declared extern is defined statically in one TU and non-statically in second TU
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Mar 14 10:24:47 PDT 2019
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: unassignedclangbugs at nondot.org
Reporter: legalize at xmission.com
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
neeilans at live.com, richard-llvm at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190314/3f5ad7f8/attachment-0001.html>
More information about the llvm-bugs
mailing list