Skip to content

Commit c7ba533

Browse files
committed
Add warning when a tentative array definition is assumed to have one element.
- Also, fixed one to actually be one (instead of zero). :) llvm-svn: 69226
1 parent bc8a78d commit c7ba533

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,8 @@ def err_tentative_def_incomplete_type : Error<
944944
"tentative definition has type %0 that is never completed">;
945945
def err_tentative_def_incomplete_type_arr : Error<
946946
"tentative definition has array of type %0 that is never completed">;
947+
def warn_tentative_incomplete_array : Warning<
948+
"tentative array definition assumed to have one element">;
947949

948950
def err_realimag_invalid_type : Error<"invalid type %0 to %1 operator">;
949951
def err_typecheck_sclass_fscope : Error<

clang/lib/Sema/Sema.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,9 @@ void Sema::ActOnEndOfTranslationUnit() {
253253
VD->setInvalidDecl();
254254
else {
255255
// Set the length of the array to 1 (C99 6.9.2p5).
256-
llvm::APSInt One(Context.getTypeSize(Context.getSizeType()),
257-
true);
256+
Diag(VD->getLocation(), diag::warn_tentative_incomplete_array);
257+
llvm::APInt One(Context.getTypeSize(Context.getSizeType()),
258+
true);
258259
QualType T
259260
= Context.getConstantArrayType(ArrayT->getElementType(),
260261
One, ArrayType::Normal, 0);

clang/test/Parser/recovery.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: clang-cc -fsyntax-only -verify -pedantic -fblocks %s
22

33
// PR2241
4-
float test2241[] = {
4+
float test2241[2] = {
55
1e, // expected-error {{exponent}}
66
1ee0 // expected-error {{exponent}}
77
};

clang/test/Sema/incomplete-decl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ static struct foo g; // expected-error {{variable has incomplete type 'struct f
1111
extern void d;
1212
extern struct foo e;
1313

14-
int ary[];
14+
int ary[]; // expected-warning {{tentative array definition assumed to have one element}}
1515
struct foo bary[]; // expected-error {{array has incomplete element type 'struct foo'}}
1616

1717
void func() {
@@ -20,7 +20,7 @@ void func() {
2020
struct foo f; // expected-error {{variable has incomplete type 'struct foo'}}
2121
}
2222

23-
int h[];
23+
int h[]; // expected-warning {{tentative array definition assumed to have one element}}
2424
int (*i)[] = &h+1; // expected-error {{arithmetic on pointer to incomplete type 'int (*)[]'}}
2525

2626
struct bar j = {1}; // expected-error {{variable has incomplete type 'struct bar'}} \

0 commit comments

Comments
 (0)