Bug 19612 – Wrong(?) code compiles

Status
RESOLVED
Resolution
INVALID
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-01-24T18:39:39Z
Last change time
2023-04-25T09:46:16Z
Assigned to
No Owner
Creator
Victor Porton

Comments

Comment #0 by porton — 2019-01-24T18:39:39Z
DMD v2.080.1 does compile the following code: --- module test; extern int xx(char v); int xx(char v) { return 0; } void main() { } --- In my opinion, it should not compile, because the function is both requested to be linked from an outside library and is implemented in the object file itself. This is a contradiction. However, I may misunderstand.
Comment #1 by porton — 2019-01-24T18:43:35Z
Hm, it compiles in C with GCC 8.2.0-7ubuntu1 (after removal the module declaration), too. Weird.
Comment #2 by dfj1esp02 — 2019-01-25T08:53:54Z
C uses this idiom to maintain compatibility between function declarations in the header file and function definitions in the implementation file. When implementation includes the header, the compiler checks that declarations match definitions and can report a warning if they don't. Well, extern just allows to declare a function, and provide implementation elsewhere, not restricted where.