]> granicus.if.org Git - clang/commitdiff
PR12225: The requirement that literal operators be namespace-scope functions
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 10 Mar 2012 22:18:57 +0000 (22:18 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 10 Mar 2012 22:18:57 +0000 (22:18 +0000)
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

lib/Sema/SemaDeclCXX.cpp
test/CXX/over/over.oper/over.literal/p2.cpp
test/SemaCXX/literal-operators.cpp

index a5b74575b6b2e11201df33f99ba16870f708eafa..29df5c12a60d96285cb712373caa4cf1801c1fb0 100644 (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;
index d0dfde439eb191149b6c87981b0a318c7281fc79..c012104314b26d59736c9027bda5f218cd4f3797 100644 (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 *);
 };
 
index 745a433ac5cccdb2f0ecd97c162a2b25cce9070a..7f68cd393cad3c03068270557c82aa4a29642635 100644 (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);