diff options
| author | Douglas Gregor <dgregor@apple.com> | 2009-02-24 01:23:02 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2009-02-24 01:23:02 +0000 |
| commit | e62c0a45dd54045a523b6cf1c657d3bbc9a81404 (patch) | |
| tree | 39f3dc4eef45c3157db0a8d2a809a2cebb91112a /clang/test | |
| parent | e6698847490224d4ade0a5e0f1c8784f23201c0b (diff) | |
| download | bcm5719-llvm-e62c0a45dd54045a523b6cf1c657d3bbc9a81404.tar.gz bcm5719-llvm-e62c0a45dd54045a523b6cf1c657d3bbc9a81404.zip | |
Improve merging of function declarations. Specifically:
- When we are declaring a function in local scope, we can merge with
a visible declaration from an outer scope if that declaration
refers to an entity with linkage. This behavior now works in C++
and properly ignores entities without linkage.
- Diagnose the use of "static" on a function declaration in local
scope.
- Diagnose the declaration of a static function after a non-static
declaration of the same function.
- Propagate the storage specifier to a function declaration from a
prior declaration (PR3425)
- Don't name-mangle "main"
llvm-svn: 65360
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/CodeGen/linkage-redecl.c | 11 | ||||
| -rw-r--r-- | clang/test/Sema/function-redecl.c | 30 | ||||
| -rw-r--r-- | clang/test/Sema/function.c | 5 | ||||
| -rw-r--r-- | clang/test/Sema/nested-redef.c | 2 | ||||
| -rw-r--r-- | clang/test/SemaCXX/function-redecl.cpp | 26 |
5 files changed, 73 insertions, 1 deletions
diff --git a/clang/test/CodeGen/linkage-redecl.c b/clang/test/CodeGen/linkage-redecl.c new file mode 100644 index 00000000000..df8a9939499 --- /dev/null +++ b/clang/test/CodeGen/linkage-redecl.c @@ -0,0 +1,11 @@ +// RUN: clang -emit-llvm %s -o - |grep internal + +// C99 6.2.2p3 +// PR3425 +static void f(int x); + +void g0() { + f(5); +} + +extern void f(int x) { } // still has internal linkage diff --git a/clang/test/Sema/function-redecl.c b/clang/test/Sema/function-redecl.c index 85663396cf3..4be03227227 100644 --- a/clang/test/Sema/function-redecl.c +++ b/clang/test/Sema/function-redecl.c @@ -28,3 +28,33 @@ INT g2(x) // expected-error{{conflicting types for 'g2'}} { return x; } + +void test() { + int f1; + { + void f1(double); + { + void f1(double); // expected-note{{previous declaration is here}} + { + int f1(int); // expected-error{{conflicting types for 'f1'}} + } + } + } +} + +extern void g3(int); // expected-note{{previous declaration is here}} +static void g3(int x) { } // expected-error{{static declaration of 'g3' follows non-static declaration}} + +void test2() { + extern int f2; // expected-note{{previous definition is here}} + { + void f2(int); // expected-error{{redefinition of 'f2' as different kind of symbol}} + } + + { + int f2; + { + void f2(int); // okay + } + } +} diff --git a/clang/test/Sema/function.c b/clang/test/Sema/function.c index ff78e719bb3..a1d71377960 100644 --- a/clang/test/Sema/function.c +++ b/clang/test/Sema/function.c @@ -53,3 +53,8 @@ void f0_3137() { void f1_3137() { int (*fp)(void) = g0_3137; } + +void f1static() { + static void f2static(int); // expected-error{{function declared in block scope cannot have 'static' storage class}} + register void f2register(int); // expected-error{{illegal storage class on function}} +} diff --git a/clang/test/Sema/nested-redef.c b/clang/test/Sema/nested-redef.c index b0b12805e68..0264ad4c58a 100644 --- a/clang/test/Sema/nested-redef.c +++ b/clang/test/Sema/nested-redef.c @@ -17,7 +17,7 @@ struct Z { void f2(void) { struct T t; - // FIXME: this is well-formed, but Clang breaks on it struct U u; + struct U u; } diff --git a/clang/test/SemaCXX/function-redecl.cpp b/clang/test/SemaCXX/function-redecl.cpp new file mode 100644 index 00000000000..baad312a155 --- /dev/null +++ b/clang/test/SemaCXX/function-redecl.cpp @@ -0,0 +1,26 @@ +// RUN: clang -fsyntax-only -verify %s +int foo(int); + +namespace N { + void f1() { + void foo(int); // okay + } + + // FIXME: we shouldn't even need this declaration to detect errors + // below. + void foo(int); // expected-note{{previous declaration is here}} + + void f2() { + int foo(int); // expected-error{{functions that differ only in their return type cannot be overloaded}} + + { + int foo; + { + // FIXME: should diagnose this because it's incompatible with + // N::foo. However, name lookup isn't properly "skipping" the + // "int foo" above. + float foo(int); + } + } + } +} |

