Skip to content

Commit

Permalink
Add warning when a tentative array definition is assumed to have one …
Browse files Browse the repository at this point in the history
…element.

 - Also, fixed one to actually be one (instead of zero). :)

llvm-svn: 69226
  • Loading branch information
ddunbar committed Apr 15, 2009
1 parent bc8a78d commit c7ba533
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,8 @@ def err_tentative_def_incomplete_type : Error<
"tentative definition has type %0 that is never completed">;
def err_tentative_def_incomplete_type_arr : Error<
"tentative definition has array of type %0 that is never completed">;
def warn_tentative_incomplete_array : Warning<
"tentative array definition assumed to have one element">;

def err_realimag_invalid_type : Error<"invalid type %0 to %1 operator">;
def err_typecheck_sclass_fscope : Error<
Expand Down
5 changes: 3 additions & 2 deletions clang/lib/Sema/Sema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,9 @@ void Sema::ActOnEndOfTranslationUnit() {
VD->setInvalidDecl();
else {
// Set the length of the array to 1 (C99 6.9.2p5).
llvm::APSInt One(Context.getTypeSize(Context.getSizeType()),
true);
Diag(VD->getLocation(), diag::warn_tentative_incomplete_array);
llvm::APInt One(Context.getTypeSize(Context.getSizeType()),
true);
QualType T
= Context.getConstantArrayType(ArrayT->getElementType(),
One, ArrayType::Normal, 0);
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Parser/recovery.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// RUN: clang-cc -fsyntax-only -verify -pedantic -fblocks %s

// PR2241
float test2241[] = {
float test2241[2] = {
1e, // expected-error {{exponent}}
1ee0 // expected-error {{exponent}}
};
Expand Down
4 changes: 2 additions & 2 deletions clang/test/Sema/incomplete-decl.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static struct foo g; // expected-error {{variable has incomplete type 'struct f
extern void d;
extern struct foo e;

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

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

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

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

0 comments on commit c7ba533

Please sign in to comment.