Merge pull request #197 from greg-king5/static
Handle almost-duplicate C declarations that have different linkages.
This commit is contained in:
@@ -126,19 +126,19 @@ void DumpSymEntry (FILE* F, const SymEntry* E)
|
|||||||
/* Print the assembler name if we have one */
|
/* Print the assembler name if we have one */
|
||||||
if (E->AsmName) {
|
if (E->AsmName) {
|
||||||
fprintf (F, " AsmName: %s\n", E->AsmName);
|
fprintf (F, " AsmName: %s\n", E->AsmName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print the flags */
|
/* Print the flags */
|
||||||
SymFlags = E->Flags;
|
SymFlags = E->Flags;
|
||||||
fprintf (F, " Flags: ");
|
fprintf (F, " Flags:");
|
||||||
for (I = 0; I < sizeof (Flags) / sizeof (Flags[0]) && SymFlags != 0; ++I) {
|
for (I = 0; I < sizeof (Flags) / sizeof (Flags[0]) && SymFlags != 0; ++I) {
|
||||||
if ((SymFlags & Flags[I].Val) == Flags[I].Val) {
|
if ((SymFlags & Flags[I].Val) == Flags[I].Val) {
|
||||||
SymFlags &= ~Flags[I].Val;
|
SymFlags &= ~Flags[I].Val;
|
||||||
fprintf (F, "%s ", Flags[I].Name);
|
fprintf (F, " %s", Flags[I].Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (SymFlags != 0) {
|
if (SymFlags != 0) {
|
||||||
fprintf (F, "%04X", SymFlags);
|
fprintf (F, " 0x%05X", SymFlags);
|
||||||
}
|
}
|
||||||
fprintf (F, "\n");
|
fprintf (F, "\n");
|
||||||
|
|
||||||
|
|||||||
@@ -813,6 +813,25 @@ SymEntry* AddGlobalSym (const char* Name, const Type* T, unsigned Flags)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If a static declaration follows a non-static declaration, then
|
||||||
|
** warn about the conflict. (It will compile a public declaration.)
|
||||||
|
*/
|
||||||
|
if ((Flags & SC_EXTERN) == 0 && (Entry->Flags & SC_EXTERN) != 0) {
|
||||||
|
Warning ("static declaration follows non-static declaration of `%s'.", Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* An extern declaration must not change the current linkage. */
|
||||||
|
if (IsFunc || (Flags & (SC_EXTERN | SC_DEF)) == SC_EXTERN) {
|
||||||
|
Flags &= ~SC_EXTERN;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If a public declaration follows a static declaration, then
|
||||||
|
** warn about the conflict. (It will compile a public declaration.)
|
||||||
|
*/
|
||||||
|
if ((Flags & SC_EXTERN) != 0 && (Entry->Flags & SC_EXTERN) == 0) {
|
||||||
|
Warning ("public declaration follows static declaration of `%s'.", Name);
|
||||||
|
}
|
||||||
|
|
||||||
/* Add the new flags */
|
/* Add the new flags */
|
||||||
Entry->Flags |= Flags;
|
Entry->Flags |= Flags;
|
||||||
|
|
||||||
|
|||||||
20
test/err/static-2.c
Normal file
20
test/err/static-2.c
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
!!DESCRIPTION!! global non-static and static conflicts
|
||||||
|
!!ORIGIN!! cc65 regression tests
|
||||||
|
!!LICENCE!! Public Domain
|
||||||
|
!!AUTHOR!! Greg King
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
see: https://github.com/cc65/cc65/issues/191
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma warn(error, on)
|
||||||
|
|
||||||
|
int n;
|
||||||
|
static int n; /* should give an error */
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
return n;
|
||||||
|
}
|
||||||
20
test/err/static-3.c
Normal file
20
test/err/static-3.c
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
!!DESCRIPTION!! global non-static and static conflicts
|
||||||
|
!!ORIGIN!! cc65 regression tests
|
||||||
|
!!LICENCE!! Public Domain
|
||||||
|
!!AUTHOR!! Greg King
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
see: https://github.com/cc65/cc65/issues/191
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma warn(error, on)
|
||||||
|
|
||||||
|
extern int n;
|
||||||
|
static int n; /* should give an error */
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
return n;
|
||||||
|
}
|
||||||
20
test/err/static-4.c
Normal file
20
test/err/static-4.c
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
!!DESCRIPTION!! global non-static and static conflicts
|
||||||
|
!!ORIGIN!! cc65 regression tests
|
||||||
|
!!LICENCE!! Public Domain
|
||||||
|
!!AUTHOR!! Greg King
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
see: https://github.com/cc65/cc65/issues/191
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma warn(error, on)
|
||||||
|
|
||||||
|
static int n;
|
||||||
|
int n; /* should give an error */
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
return n;
|
||||||
|
}
|
||||||
20
test/val/static-1.c
Normal file
20
test/val/static-1.c
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
!!DESCRIPTION!! global non-static and static conflicts
|
||||||
|
!!ORIGIN!! cc65 regression tests
|
||||||
|
!!LICENCE!! Public Domain
|
||||||
|
!!AUTHOR!! Greg King
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
see: https://github.com/cc65/cc65/issues/191
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma warn(error, on)
|
||||||
|
|
||||||
|
static int n = 0;
|
||||||
|
extern int n; /* should not give an error */
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
return n;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user