Clang error: non-extern declaration of A follows extern declaration (err_non_extern_extern)
Jump to navigation
Jump to search
Text | error: non-extern declaration of A follows extern declaration |
---|---|
Type | Error |
Category | Semantic Issue |
Internal Id | err_non_extern_extern |
Internal Message | non-extern declaration of %0 follows extern declaration
|
Regular Expression | (?:error|fatal error)\: non\-extern declaration of (.*?) follows extern declaration
|
First Commit | 2011-01-31 819f61094216 Diagnose if extern local variable is followed by non-extern and vice-versa. |
Description
Example
Flags | -xc
|
|
---|---|---|
Source |
extern int v; // extern declaration of v
void f() {
extern int v; // extern redeclaration is allowed
int v; // error: non-extern declaration after an extern one
}
| |
Compiler Output |
<source>:5:7: error: non-extern declaration of 'v' follows extern declaration <source>:4:14: note: previous declaration is here |
Clang Internals (17.0.6)
Git Commit Message
Diagnose if extern local variable is followed by non-extern and vice-versa. llvm-svn: 124579
Used in Clang Sources
This section lists all occurrences of the diagnostic within the Clang's codebase. For each occurrence, an auto-extracted snipped from the source code is listed including key elements like control structures, functions, or classes. It should illustrate the conditions under which the diagnostic is activated.
clang/lib/Sema/SemaDecl.cpp (line 4666)
/// MergeVarDecl - We just parsed a variable 'New' which has the same name
/// and scope as a previous declaration 'Old'. Figure out how to resolve this
/// situation, merging decls or emitting diagnostics as appropriate.
///
/// Tentative definition rules (C99 6.9.2p2) are checked by
/// FinalizeDeclaratorGroup. Unfortunately, we can't analyze tentative
/// definitions here, since the initializer hasn't been attached.
///
void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) {
// ...
if (Old->hasLinkage() && New->isLocalVarDeclOrParm() && !New->hasExternalStorage()) {
Diag(New->getLocation(), diag::err_non_extern_extern) << New->getDeclName();
Triggered in Clang Tests
This section lists all internal Clang test cases that trigger the diagnostic.
clang/test/Sema/private-extern.c
- clang/test/Sema/private-extern.c:34:7: error: non-extern declaration of 'g8' follows extern declaration
- clang/test/Sema/private-extern.c:39:7: error: non-extern declaration of 'g9' follows extern declaration