c: Implement C2y handling of incomplete tentative definitions [PR26581]
Before C2y, a tentative definition (file-scope, not extern, no
initializer) with internal linkage and incomplete type was undefined
behavior ("shall" outside Constraints violated). In C2y, this has
changed to a constraint violation if the type has not been completed
by the end of the translation unit, and is valid if the type has been
completed by the end of the translation unit. This change originates
from N3347 but the wording accepted into C2y was that from reflector
message 26758.
In GCC, the case of incomplete array types was a hard error with
-pedantic, rather than a pedwarn, contrary to how -pedantic is
supposed to behave; bug 26581 requested a change to allow this case
with -pedantic (i.e. the change made in C2y). For incomplete structs
and unions, GCC only diagnoses them if the type remains incomplete at
the end of the translation unit; bug 88727 (*not* fixed here) requests
the case where the type gets completed should also be diagnosed as a
quality of implementation matter (and that bug is still applicable for
pre-C2y langauge versions and -Wc23-c2y-compat).
Change the handling of arrays following C2y; the previous error
becomes a pedwarn_c23 while there is a new error at the end of the
translation unit if the type remains incomplete there in C2y mode.
There is an ambiguity in the wording in C2y for the case where the
type gets completed only in an inner scope; I've raised that in
reflector message 34118.
Bootstrapped with no regressions for x86_64-pc-linux-gnu.
PR c/26581
gcc/c/
* c-decl.cc (c_finish_incomplete_decl): Give error for tentative
definition of incomplete array for C2y with internal linkage.
(finish_decl): Do not set DO_DEFAULT based on -pedantic. Use
pedwarn_c23 for missing array sizes for internal linkage.