Skip to content

Commit 00aefae

Browse files
authored
Merge pull request #5670 from tautschnig/redefinition
C front-end: report struct/union redefinition as an error
2 parents 837da38 + a6af909 commit 00aefae

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

regression/ansi-c/struct8/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
struct a;
2+
union a b;

regression/ansi-c/struct8/test.desc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE test-c++-front-end
2+
main.c
3+
4+
^EXIT=(64|1)$
5+
^SIGNAL=0$
6+
redefinition of '(struct )?a' as different kind of tag
7+
^CONVERSION ERROR$
8+
--
9+
Invariant check failed

src/ansi-c/c_typecheck_type.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,13 @@ void c_typecheck_baset::typecheck_compound_type(struct_union_typet &type)
847847
symbol_table.get_writeable_ref(s_it->first).type.swap(type);
848848
}
849849
}
850+
else if(s_it->second.type.id() != type.id())
851+
{
852+
error().source_location = type.source_location();
853+
error() << "redefinition of '" << s_it->second.pretty_name << "'"
854+
<< " as different kind of tag" << eom;
855+
throw 0;
856+
}
850857
else if(have_body)
851858
{
852859
error().source_location=type.source_location();

src/cpp/cpp_typecheck_compound_type.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ void cpp_typecheckt::typecheck_compound_type(
212212
throw 0;
213213
}
214214
}
215+
else if(symbol.type.id() != type.id())
216+
{
217+
error().source_location = type.source_location();
218+
error() << "redefinition of '" << symbol.pretty_name << "'"
219+
<< " as different kind of tag" << eom;
220+
throw 0;
221+
}
215222
}
216223
else
217224
{

0 commit comments

Comments
 (0)