]> granicus.if.org Git - clang/commitdiff
Add null check (resolves PR16423)
authorStephen Lin <stephenwlin@gmail.com>
Sun, 23 Jun 2013 07:37:13 +0000 (07:37 +0000)
committerStephen Lin <stephenwlin@gmail.com>
Sun, 23 Jun 2013 07:37:13 +0000 (07:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184661 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseCXXInlineMethods.cpp
test/SemaCXX/friend.cpp

index 5fc4189742cf1f3460fe66e6224f16d99f9fabb5..665d9ca2045ffdcfdd8e51cf0de39aeba63c9a9f 100644 (file)
@@ -170,27 +170,26 @@ NamedDecl *Parser::ParseCXXInlineMethodDef(AccessSpecifier AS,
     }
   }
 
-
-  if (!FnD) {
+  if (FnD) {
+    // If this is a friend function, mark that it's late-parsed so that
+    // it's still known to be a definition even before we attach the
+    // parsed body.  Sema needs to treat friend function definitions
+    // differently during template instantiation, and it's possible for
+    // the containing class to be instantiated before all its member
+    // function definitions are parsed.
+    //
+    // If you remove this, you can remove the code that clears the flag
+    // after parsing the member.
+    if (D.getDeclSpec().isFriendSpecified()) {
+      getFunctionDecl(FnD)->setLateTemplateParsed(true);
+    }
+  } else {
     // If semantic analysis could not build a function declaration,
     // just throw away the late-parsed declaration.
     delete getCurrentClass().LateParsedDeclarations.back();
     getCurrentClass().LateParsedDeclarations.pop_back();
   }
 
-  // If this is a friend function, mark that it's late-parsed so that
-  // it's still known to be a definition even before we attach the
-  // parsed body.  Sema needs to treat friend function definitions
-  // differently during template instantiation, and it's possible for
-  // the containing class to be instantiated before all its member
-  // function definitions are parsed.
-  //
-  // If you remove this, you can remove the code that clears the flag
-  // after parsing the member.
-  if (D.getDeclSpec().isFriendSpecified()) {
-    getFunctionDecl(FnD)->setLateTemplateParsed(true);
-  }
-
   return FnD;
 }
 
index b401a06a7ecfe66e010f8b8f347f05836a6dd6f6..3da27e0f33f7f39f0bacb79625233fb731e79b63 100644 (file)
@@ -154,3 +154,12 @@ namespace test8 {
     friend void B::f(); // expected-error {{cannot befriend target of using declaration}}
   };
 }
+
+// PR16423
+namespace test9 {
+  class C {
+  };
+  struct A {
+    friend void C::f(int, int, int) {}  // expected-error {{no function named 'f' with type 'void (int, int, int)' was found in the specified scope}}
+  };
+}