]> granicus.if.org Git - clang/commitdiff
Literal operator suffixes and regular names live in separate namespaces.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 9 Mar 2012 08:37:16 +0000 (08:37 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 9 Mar 2012 08:37:16 +0000 (08:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152395 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/DeclarationName.cpp
test/CXX/over/over.oper/over.literal/p2.cpp
test/SemaCXX/cxx11-user-defined-literals.cpp

index a5488e67ca234e51a56929f8e2c7088488fcd536..64924ad95095581c86b1e1750d7fafa7997ba09f 100644 (file)
@@ -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<void>();
+    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);
index fb11ca55786fa8547bbe0eb29d7182bcfe3282af..d0dfde439eb191149b6c87981b0a318c7281fc79 100644 (file)
@@ -25,3 +25,9 @@ void f() {
 extern "C++" {
   void operator "" _g(const char *);
 }
+
+template<char...> void operator "" _h() {}
+
+template<> void operator "" _h<'a', 'b', 'c'>() {}
+
+template void operator "" _h<'a', 'b', 'c', 'd'>();
index 4cfd4d382bbab971b7e1167d7121c5f1407c97de..4bbecdb5b8e4a71916941c7815f998a94ac3c4d5 100644 (file)
@@ -126,3 +126,12 @@ template<char...Cs> 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<char...> 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'}}
+}