c-decl.c
365 KB
-
Fix type of extern array declared in inner scope with outer initialization shadowed (PR c/88584). · fbe83e6b
As reported in bug 88584, if you have a file-scope array with external linkage, initialized at file scope, and that array is shadowed at block scope, and is declared again with external linkage and an incomplete type in an inner scope, it is wrongly given a complete type in that inner scope when the correct C semantics give it an incomplete type (only the visible declarations contribute to the type in a given scope). In general, issues with the types of external linkage declarations being different in different scopes were addressed by my fixes for bug 13801, for GCC 4.0. In this case, however, the code in pushdecl dealing with giving declarations the right type in each scope works fine, and the type is subsequently modified by complete_array_type called from finish_decl: finish_decl is trying to complete an array type based on an initializer, but that's only correct for the original initialization at file scope, not for such a declaration in an inner scope (it's harmless but unnecessary in the case where the original declaration is still visible in the inner scope). Thus, this patch changes finish_decl to stop this logic applying for such an external declaration in an inner scope. (An erroneous attempt to include an initializer for an extern variable in an inner scope is diagnosed elsewhere.) This is a regression from GCC 3.4, which properly rejected the code in question (quite likely by accident). Bootstrapped with no regressions on x86_64-pc-linux-gnu. gcc/c: PR c/88584 * c-decl.c (finish_decl): Do not complete array types for arrays with external linkage not at file scope. gcc/testsuite: PR c/88584 * gcc.dg/redecl-18.c: New test. From-SVN: r268571
Joseph Myers committed