[cfe-commits] r80016 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/CXX/class/class.friend/p1.cpp
John McCall
rjmccall at apple.com
Tue Aug 25 10:54:00 PDT 2009
Author: rjmccall
Date: Tue Aug 25 12:53:59 2009
New Revision: 80016
URL: http://llvm.org/viewvc/llvm-project?rev=80016&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/CXX/class/class.friend/p1.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=80016&r1=80015&r2=80016&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Aug 25 12:53:59 2009
@@ -2390,7 +2390,8 @@
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
Modified: cfe/trunk/test/CXX/class/class.friend/p1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class/class.friend/p1.cpp?rev=80016&r1=80015&r2=80016&view=diff
==============================================================================
--- cfe/trunk/test/CXX/class/class.friend/p1.cpp (original)
+++ cfe/trunk/test/CXX/class/class.friend/p1.cpp Tue Aug 25 12:53:59 2009
@@ -18,6 +18,11 @@
int myglobal;
+void global_function();
+extern "C" {
+ void global_c_function();
+}
+
class A {
class AInner {
};
@@ -29,6 +34,9 @@
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)
More information about the cfe-commits
mailing list