[Clang] Extend mixed internal/external linkage diagnostic to function declarations
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
PR #193567 added a diagnostic (err_internal_extern_mismatch) for C identifiers declared with both internal and external linkage in the same translation unit (N3410 / C11 §6.2.2 UB). The current implementation only covers variable declarations via MergeVarDecl. A check is needed in `MergeFunctionDecl` for function declarations as well.
Example:
```c
static void foo(void); // internal linkage
void bar(void) {
int foo; // no linkage, shadows static function
{
extern void foo(void); // gets external linkage due to shadow
// → 'foo' has both internal and external linkage
}
}
```
**GCC (trunk, `-std=c2x`):** `error: function previously declared 'static' redeclared 'extern'`
**Clang (trunk):** no diagnostic related to the issue
https://godbolt.org/z/vGWj8nha7
Implementation Idea
`MergeFunctionDecl` does not take a `LookupResult &Previous` parameter (unlike `MergeVarDecl`), so `Previous.isShadowed()` is not available. a fix may be implemented with following:
- **Adding `LookupResult &Previous` as a parameter** to `MergeFunctionDecl`
Related
- PR #193567 -- original implementation for variable declarations
- [N3410](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3410.pdf) -- C2y makes this a constraint violation (previously UB in C11 §6.2.2p7)
Contributor guide
Assessment
This issue has not been assessed yet.