[cfe-commits] r116527 - in /cfe/trunk: lib/Sema/SemaType.cpp test/CXX/class/class.friend/p1.cpp test/CXX/dcl.decl/dcl.meaning/dcl.fct/p6.cpp
Douglas Gregor
dgregor at apple.com
Thu Oct 14 15:03:51 PDT 2010
Author: dgregor
Date: Thu Oct 14 17:03:51 2010
New Revision: 116527
URL: http://llvm.org/viewvc/llvm-project?rev=116527&view=rev
Log:
Make sure that we diagnose invalid qualifiers on friend functions.
Added:
cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p6.cpp (with props)
Modified:
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/CXX/class/class.friend/p1.cpp
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=116527&r1=116526&r2=116527&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu Oct 14 17:03:51 2010
@@ -1403,13 +1403,16 @@
const FunctionProtoType *FnTy = T->getAs<FunctionProtoType>();
assert(FnTy && "Why oh why is there not a FunctionProtoType here?");
- // C++ 8.3.5p4: A cv-qualifier-seq shall only be part of the function type
- // for a nonstatic member function, the function type to which a pointer
- // to member refers, or the top-level function type of a function typedef
- // declaration.
- bool FreeFunction = (D.getContext() != Declarator::MemberContext &&
+ // C++ 8.3.5p4:
+ // A cv-qualifier-seq shall only be part of the function type
+ // for a nonstatic member function, the function type to which a pointer
+ // to member refers, or the top-level function type of a function typedef
+ // declaration.
+ bool FreeFunction =
+ (D.getContext() != Declarator::MemberContext ||
+ D.getDeclSpec().isFriendSpecified()) &&
(!D.getCXXScopeSpec().isSet() ||
- !computeDeclContext(D.getCXXScopeSpec(), /*FIXME:*/true)->isRecord()));
+ !computeDeclContext(D.getCXXScopeSpec(), /*FIXME:*/true)->isRecord());
if (FnTy->getTypeQuals() != 0 &&
D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_typedef &&
(FreeFunction ||
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=116527&r1=116526&r2=116527&view=diff
==============================================================================
--- cfe/trunk/test/CXX/class/class.friend/p1.cpp (original)
+++ cfe/trunk/test/CXX/class/class.friend/p1.cpp Thu Oct 14 17:03:51 2010
@@ -57,7 +57,8 @@
friend A operator|(const A& l, const A& r); // okay
friend A operator|(const A& r); // expected-error {{ overloaded 'operator|' must be a binary operator (has 1 parameter) }}
- friend operator bool() const; // expected-error {{ must use a qualified name when declaring a conversion operator as a friend }}
+ friend operator bool() const; // expected-error {{ must use a qualified name when declaring a conversion operator as a friend }} \
+ // expected-error{{type qualifier is not allowed on this function}}
typedef void ftypedef();
friend ftypedef typedeffed_function; // okay (because it's not declared as a member)
Added: cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p6.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p6.cpp?rev=116527&view=auto
==============================================================================
--- cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p6.cpp (added)
+++ cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p6.cpp Thu Oct 14 17:03:51 2010
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void f() const; // expected-error{{type qualifier is not allowed on this function}}
+
+struct X {
+ void f() const;
+ friend void g() const; // expected-error{{type qualifier is not allowed on this function}}
+ static void h() const; // expected-error{{type qualifier is not allowed on this function}}
+};
+
+struct Y {
+ friend void X::f() const;
+ friend void ::f() const; // expected-error{{type qualifier is not allowed on this function}}
+};
Propchange: cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p6.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p6.cpp
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p6.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the cfe-commits
mailing list