summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2009-08-25 17:53:59 +0000
committerJohn McCall <rjmccall@apple.com>2009-08-25 17:53:59 +0000
commit1dfa9a9872a713d59f8cf702f0ab7295a8fecb50 (patch)
tree14bcb3c7e5cee97c5bd410cd4ddac4f8b230baac
parentf1beef9f48d864fabc723b12c722cddeff8f33c0 (diff)
downloadbcm5719-llvm-1dfa9a9872a713d59f8cf702f0ab7295a8fecb50.tar.gz
bcm5719-llvm-1dfa9a9872a713d59f8cf702f0ab7295a8fecb50.zip
Modify an assert to capture the restriction on friend declarations more
accurately. Prevents the assert from triggering incorrectly when friending functions first declared in extern "C" contexts. Fixes bug 4757. llvm-svn: 80016
-rw-r--r--clang/lib/Sema/SemaDecl.cpp3
-rw-r--r--clang/test/CXX/class/class.friend/p1.cpp8
2 files changed, 10 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ee6238c56c4..61f0ce808a7 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2390,7 +2390,8 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
FunctionDecl *NewFD;
if (isFriend) {
// DC is the namespace in which the function is being declared.
- assert(DC->isFileContext() || D.getCXXScopeSpec().isSet());
+ assert((DC->isFileContext() || PrevDecl) && "previously-undeclared "
+ "friend function being created in a non-namespace context");
// C++ [class.friend]p5
// A function can be defined in a friend declaration of a
diff --git a/clang/test/CXX/class/class.friend/p1.cpp b/clang/test/CXX/class/class.friend/p1.cpp
index 80afe3e7a50..1b2c4dfcd4d 100644
--- a/clang/test/CXX/class/class.friend/p1.cpp
+++ b/clang/test/CXX/class/class.friend/p1.cpp
@@ -18,6 +18,11 @@ struct Derived : public Base {
int myglobal;
+void global_function();
+extern "C" {
+ void global_c_function();
+}
+
class A {
class AInner {
};
@@ -29,6 +34,9 @@ class A {
friend int myoperation(float); // okay
friend int myglobal; // expected-error {{ friends can only be classes or functions }}
+ friend void global_function();
+ friend void global_c_function();
+
void a_member();
friend void A::a_member(); // expected-error {{ friends cannot be members of the declaring class }}
friend void a_member(); // okay (because we ignore class scopes when looking up friends)
OpenPOWER on IntegriCloud