]> granicus.if.org Git - clang/commitdiff
c error recovery. treat an invalid redeclaration
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 5 Sep 2012 17:52:12 +0000 (17:52 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 5 Sep 2012 17:52:12 +0000 (17:52 +0000)
of a c-function for what it is. Otherwise, this func
is treated as an overloadable c-function resulting in
a crash much later. // rdar://11743706

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163224 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/Sema/invalid-decl.c

index 2582e132482b0b085cbf5796023a55986ba0a857..6fff4b15a475e1cce3b1a0e99b83b1713ee4f92b 100644 (file)
@@ -5565,6 +5565,9 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
       D.setRedeclaration(CheckFunctionDeclaration(S, NewFD, Previous,
                                                   isExplicitSpecialization));
     }
+    // Make graceful recovery from an invalid redeclaration.
+    else if (!Previous.empty())
+           D.setRedeclaration(true);
     assert((NewFD->isInvalidDecl() || !D.isRedeclaration() ||
             Previous.getResultKind() != LookupResult::FoundOverloaded) &&
            "previous declaration set still overloaded");
index 2699b254926ac8abfa184e738cfc3f0da1fa599b..b2c2aaf1a0f00c9a2e3b8d61b4cda4e07a82483d 100644 (file)
@@ -29,3 +29,12 @@ typedef struct {
 void f(StructType *buf) {
   buf->fun = 0;
 }
+
+// rdar://11743706
+static void bar(hid_t, char); // expected-error {{expected identifier}}
+
+static void bar(hid_t p, char); // expected-error {{unknown type name 'hid_t'}}
+
+void foo() {
+  (void)bar;
+}