Implement -Wnested-externs.
[cparser] / parser.c
index 0f2dd11..38dffce 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -4114,7 +4114,7 @@ static declaration_t *internal_record_declaration(
        const symbol_t *const symbol  = declaration->symbol;
        const namespace_t     namespc = (namespace_t)declaration->namespc;
 
-       assert(declaration->symbol != NULL);
+       assert(symbol != NULL);
        declaration_t *previous_declaration = get_declaration(symbol, namespc);
 
        type_t *const orig_type = declaration->type;
@@ -4132,6 +4132,13 @@ static declaration_t *internal_record_declaration(
                check_type_of_main(declaration, &type->function);
        }
 
+       if (warning.nested_externs                             &&
+           declaration->storage_class == STORAGE_CLASS_EXTERN &&
+           scope                      != global_scope) {
+               warningf(&declaration->source_position,
+                        "nested extern declaration of '%#T'", declaration->type, symbol);
+       }
+
        assert(declaration != previous_declaration);
        if (previous_declaration != NULL
                        && previous_declaration->parent_scope == scope) {