aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-02-28 18:54:37 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-05-01 16:29:22 +0200
commit5c9b0ffbced524f4e8bdc586cf32db28a039cc83 (patch)
tree43f8c16014e7b93e3a3d11081f8c40fda439fe0e
parent79d8848e79f0640ffdbcc24ab78eb2bc0bf8d068 (diff)
downloadsparse-dev-5c9b0ffbced524f4e8bdc586cf32db28a039cc83.tar.gz
fix: warn on typedef redefinition
check_duplicates() verifies that symbols are not redefined and warns if they are. However, this function is only called at evaluation-time and then only for symbols corresponding to objects and functions. So, typedefs can be redefined without any kind of diagnostic. Fix this by calling check_duplicates() at parsing time on typedefs. Note: this is C11's semantic or GCC's C89/C99 in non-pedantic mode. Reported-by: Matthew Wilcox <willy@infradead.org> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--parse.c4
-rw-r--r--validation/typedef-redef.c1
2 files changed, 4 insertions, 1 deletions
diff --git a/parse.c b/parse.c
index bb504d21..08515c51 100644
--- a/parse.c
+++ b/parse.c
@@ -2888,6 +2888,10 @@ struct token *external_declaration(struct token *token, struct symbol_list **lis
if (decl->same_symbol) {
decl->definition = decl->same_symbol->definition;
decl->op = decl->same_symbol->op;
+ if (is_typedef) {
+ // TODO: handle -std=c89 --pedantic
+ check_duplicates(decl);
+ }
}
if (!match_op(token, ','))
diff --git a/validation/typedef-redef.c b/validation/typedef-redef.c
index b719ff9a..3a60a773 100644
--- a/validation/typedef-redef.c
+++ b/validation/typedef-redef.c
@@ -6,7 +6,6 @@ typedef long ko_t;
/*
* check-name: typedef-redef
- * check-known-to-fail
*
* check-error-start
typedef-redef.c:5:14: error: symbol 'ko_t' redeclared with different type (originally declared at typedef-redef.c:4) - different type sizes