From: Richard Smith Date: Sat, 10 Mar 2012 22:18:57 +0000 (+0000) Subject: PR12225: The requirement that literal operators be namespace-scope functions X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e5658f0ab2a6f8fea258adb64edbb8485bb21dee;p=clang PR12225: The requirement that literal operators be namespace-scope functions does not imply that such functions can't be declared at block scope. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152509 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index a5b74575b6..29df5c12a6 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -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(FnDecl)) { Diag(FnDecl->getLocation(), diag::err_literal_operator_outside_namespace) << FnDecl->getDeclName(); return true; diff --git a/test/CXX/over/over.oper/over.literal/p2.cpp b/test/CXX/over/over.oper/over.literal/p2.cpp index d0dfde439e..c012104314 100644 --- a/test/CXX/over/over.oper/over.literal/p2.cpp +++ b/test/CXX/over/over.oper/over.literal/p2.cpp @@ -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 *); }; diff --git a/test/SemaCXX/literal-operators.cpp b/test/SemaCXX/literal-operators.cpp index 745a433ac5..7f68cd393c 100644 --- a/test/SemaCXX/literal-operators.cpp +++ b/test/SemaCXX/literal-operators.cpp @@ -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);