PR12225: The requirement that literal operators be namespace-scope functions

does not imply that such functions can't be declared at block scope.

llvm-svn: 152509
This commit is contained in:
Richard Smith 2012-03-10 22:18:57 +00:00
parent 11d2e18405
commit 5731c75414
3 changed files with 4 additions and 5 deletions

View File

@ -9309,10 +9309,7 @@ bool Sema::CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl) {
/// of this literal operator function is well-formed. If so, returns
/// false; otherwise, emits appropriate diagnostics and returns true.
bool Sema::CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl) {
DeclContext *DC = FnDecl->getDeclContext();
Decl::Kind Kind = DC->getDeclKind();
if (Kind != Decl::TranslationUnit && Kind != Decl::Namespace &&
Kind != Decl::LinkageSpec) {
if (isa<CXXMethodDecl>(FnDecl)) {
Diag(FnDecl->getLocation(), diag::err_literal_operator_outside_namespace)
<< FnDecl->getDeclName();
return true;

View File

@ -13,6 +13,8 @@ using N::operator "" _b;
class C {
void operator "" _c(const char *); // expected-error {{must be in a namespace or global scope}}
static void operator "" _c(unsigned long long); // expected-error {{must be in a namespace or global scope}}
friend void operator "" _d(const char *);
};

View File

@ -13,7 +13,7 @@ namespace ns { void operator "" _ns_good (const char *); }
extern "C++" void operator "" _extern_good (const char *);
extern "C++" { void operator "" _extern_good (const char *); }
void fn () { void operator "" _fn_bad (const char *); } // expected-error {{literal operator 'operator "" _fn_bad' must be in a namespace or global scope}}
void fn () { void operator "" _fn_good (const char *); }
// One-param declarations (const char * was already checked)
void operator "" _good (char);