diff options
author | Jordan Rose <jordan_rose@apple.com> | 2012-06-06 17:25:21 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2012-06-06 17:25:21 +0000 |
commit | ccf43ca05cb1540f3d95a73b7b329bf926808c7b (patch) | |
tree | f1c81126e272ce660655dd437fa5dbf9d058f303 /clang/test/PCH/empty-with-headers.c | |
parent | faa389462835ab40ed8af86eb32c44abfcf4e48a (diff) | |
download | llvm-ccf43ca05cb1540f3d95a73b7b329bf926808c7b.zip llvm-ccf43ca05cb1540f3d95a73b7b329bf926808c7b.tar.gz llvm-ccf43ca05cb1540f3d95a73b7b329bf926808c7b.tar.bz2 |
Add pedantic warning -Wempty-translation-unit (C11 6.9p1).
In standard C since C89, a 'translation-unit' is syntactically defined to have
at least one "external-declaration", which is either a decl or a function
definition. In Clang the latter gives us a declaration as well.
The tricky bit about this warning is that our predefines can contain external
declarations (__builtin_va_list and the 128-bit integer types). Therefore our
AST parser now makes sure we have at least one declaration that doesn't come
from the predefines buffer.
Also, remove bogus warning about empty source files. This doesn't catch source
files that only contain comments, and never fired anyway because of our
predefines.
PR12665 and <rdar://problem/9165548>
llvm-svn: 158085
Diffstat (limited to 'clang/test/PCH/empty-with-headers.c')
-rw-r--r-- | clang/test/PCH/empty-with-headers.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/clang/test/PCH/empty-with-headers.c b/clang/test/PCH/empty-with-headers.c new file mode 100644 index 0000000..751be1c --- /dev/null +++ b/clang/test/PCH/empty-with-headers.c @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c99 -pedantic-errors %s +// RUN: %clang_cc1 -fsyntax-only -std=c99 -emit-pch -o %t %s +// RUN: %clang_cc1 -fsyntax-only -std=c99 -pedantic-errors -include-pch %t %s + +// RUN: %clang_cc1 -fsyntax-only -std=c99 -pedantic-errors -DINCLUDED %s -verify +// This last one should warn for -Wempty-translation-unit (C99 6.9p1). + +#if defined(INCLUDED) + +// empty except for the prefix header + +#elif defined(HEADER) + +typedef int my_int; +#define INCLUDED + +#else + +#define HEADER +#include "empty-with-headers.c" +// empty except for the header + +#endif + +// This should only fire if the header is not included, +// either explicitly or as a prefix header. +// expected-error{{ISO C requires a translation unit to contain at least one declaration.}} |