From: Richard Smith Date: Fri, 9 Mar 2012 08:37:16 +0000 (+0000) Subject: Literal operator suffixes and regular names live in separate namespaces. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3a5032b89df601ab2e0c5c7e9667db2301bf10cf;p=clang Literal operator suffixes and regular names live in separate namespaces. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152395 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/DeclarationName.cpp b/lib/AST/DeclarationName.cpp index a5488e67ca..64924ad950 100644 --- a/lib/AST/DeclarationName.cpp +++ b/lib/AST/DeclarationName.cpp @@ -53,7 +53,7 @@ public: void *FETokenInfo; }; -/// CXXLiberalOperatorName - Contains the actual identifier that makes up the +/// CXXLiteralOperatorName - Contains the actual identifier that makes up the /// name. /// /// This identifier is stored here rather than directly in DeclarationName so as @@ -64,6 +64,10 @@ class CXXLiteralOperatorIdName public: IdentifierInfo *ID; + /// FETokenInfo - Extra information associated with this operator + /// name that can be used by the front end. + void *FETokenInfo; + void Profile(llvm::FoldingSetNodeID &FSID) { FSID.AddPointer(ID); } @@ -333,7 +337,7 @@ void *DeclarationName::getFETokenInfoAsVoid() const { return getAsCXXOperatorIdName()->FETokenInfo; case CXXLiteralOperatorName: - return getCXXLiteralIdentifier()->getFETokenInfo(); + return getAsCXXLiteralOperatorIdName()->FETokenInfo; default: llvm_unreachable("Declaration name has no FETokenInfo"); @@ -357,7 +361,7 @@ void DeclarationName::setFETokenInfo(void *T) { break; case CXXLiteralOperatorName: - getCXXLiteralIdentifier()->setFETokenInfo(T); + getAsCXXLiteralOperatorIdName()->FETokenInfo = T; break; default: @@ -471,6 +475,7 @@ DeclarationNameTable::getCXXLiteralOperatorName(IdentifierInfo *II) { CXXLiteralOperatorIdName *LiteralName = new (Ctx) CXXLiteralOperatorIdName; LiteralName->ExtraKindOrNumArgs = DeclarationNameExtra::CXXLiteralOperator; LiteralName->ID = II; + LiteralName->FETokenInfo = 0; LiteralNames->InsertNode(LiteralName, InsertPos); return DeclarationName(LiteralName); diff --git a/test/CXX/over/over.oper/over.literal/p2.cpp b/test/CXX/over/over.oper/over.literal/p2.cpp index fb11ca5578..d0dfde439e 100644 --- a/test/CXX/over/over.oper/over.literal/p2.cpp +++ b/test/CXX/over/over.oper/over.literal/p2.cpp @@ -25,3 +25,9 @@ void f() { extern "C++" { void operator "" _g(const char *); } + +template void operator "" _h() {} + +template<> void operator "" _h<'a', 'b', 'c'>() {} + +template void operator "" _h<'a', 'b', 'c', 'd'>(); diff --git a/test/SemaCXX/cxx11-user-defined-literals.cpp b/test/SemaCXX/cxx11-user-defined-literals.cpp index 4cfd4d382b..4bbecdb5b8 100644 --- a/test/SemaCXX/cxx11-user-defined-literals.cpp +++ b/test/SemaCXX/cxx11-user-defined-literals.cpp @@ -126,3 +126,12 @@ template constexpr unsigned operator"" _hash() { } static_assert(0x1234_hash == 0x103eff5e, ""); static_assert(hash<'0', 'x', '1', '2', '3', '4'>(0) == 0x103eff5e, ""); + +// Functions and literal suffixes go in separate namespaces. +namespace Namespace { + template int operator"" _x(); + int k = _x(); // expected-error {{undeclared identifier '_x'}} + + int _y(unsigned long long); + int k2 = 123_y; // expected-error {{no matching literal operator for call to 'operator "" _y'}} +}