public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Re: [C++-11] User defined literals
@ 2011-10-12 21:12 3dw4rd
  2011-10-15 23:13 ` Jason Merrill
  2011-10-16  7:59 ` Jason Merrill
  0 siblings, 2 replies; 36+ messages in thread
From: 3dw4rd @ 2011-10-12 21:12 UTC (permalink / raw)
  To: jason; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 482 bytes --]

Greetings,

Here is a new patch and ChangeLog entry.

some error messages are streamlined and/or corrected.  I'm trying to use the language in the standard - it seems useful in this case.
Duplicate errors are removed (moved some checking higher up in the logic, used peek_token, etc.).
I fixed a rejects valid in overloading due to overzealous conflict checking between raw operators and operator templates.

The thing bootstraps and regtests on x86_64-redhat-linux.

Have fun,

Ed

[-- Attachment #2: patch28 --]
[-- Type: application/octet-stream, Size: 75265 bytes --]

Index: gcc/c-family/c-common.c
===================================================================
--- gcc/c-family/c-common.c	(revision 179317)
+++ gcc/c-family/c-common.c	(working copy)
@@ -9919,4 +9919,17 @@
   MARK_TS_TYPED (EXCESS_PRECISION_EXPR);
 }
 
+/* Build a user-defined numeric literal out of an integer constant type VALUE
+   with identifier SUFFIX.  */
+
+tree
+build_userdef_literal (tree suffix_id, tree value, tree num_string)
+{
+  tree literal = make_node (USERDEF_LITERAL);
+  USERDEF_LITERAL_SUFFIX_ID (literal) = suffix_id;
+  USERDEF_LITERAL_VALUE (literal) = value;
+  USERDEF_LITERAL_NUM_STRING (literal) = num_string;
+  return literal;
+}
+
 #include "gt-c-family-c-common.h"
Index: gcc/c-family/c-lex.c
===================================================================
--- gcc/c-family/c-lex.c	(revision 179317)
+++ gcc/c-family/c-lex.c	(working copy)
@@ -44,8 +44,8 @@
 int pending_lang_change; /* If we need to switch languages - C++ only */
 int c_header_level;	 /* depth in C headers - C++ only */
 
-static tree interpret_integer (const cpp_token *, unsigned int);
-static tree interpret_float (const cpp_token *, unsigned int);
+static tree interpret_integer (const cpp_token *, unsigned int, const char *);
+static tree interpret_float (const cpp_token *, unsigned int, const char *);
 static tree interpret_fixed (const cpp_token *, unsigned int);
 static enum integer_type_kind narrowest_unsigned_type
 	(unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned int);
@@ -314,7 +314,8 @@
 
     case CPP_NUMBER:
       {
-	unsigned int flags = cpp_classify_number (parse_in, tok);
+	const char *suffix = NULL;
+	unsigned int flags = cpp_classify_number (parse_in, tok, &suffix);
 
 	switch (flags & CPP_N_CATEGORY)
 	  {
@@ -328,16 +329,27 @@
 	       Set PURE_ZERO to pass this information to the C++ parser.  */
 	    if (tok->val.str.len == 1 && *tok->val.str.text == '0')
 	      add_flags = PURE_ZERO;
-	    *value = interpret_integer (tok, flags);
+	    *value = interpret_integer (tok, flags, suffix);
 	    break;
 
 	  case CPP_N_FLOATING:
-	    *value = interpret_float (tok, flags);
+	    *value = interpret_float (tok, flags, suffix);
 	    break;
 
 	  default:
 	    gcc_unreachable ();
 	  }
+
+	if (flags & CPP_N_USERDEF)
+	  {
+	    tree num_string = build_string (tok->val.str.len - strlen (suffix),
+					    (const char *) tok->val.str.text);
+	    TREE_TYPE (num_string) = char_array_type_node;
+	    num_string = fix_string_type (num_string);
+	    tree literal = build_userdef_literal (get_identifier (suffix),
+						  *value, num_string);
+	    *value = literal;
+	  }
       }
       break;
 
@@ -415,6 +427,22 @@
       }
       goto retry;
 
+    case CPP_CHAR_USERDEF:
+    case CPP_WCHAR_USERDEF:
+    case CPP_CHAR16_USERDEF:
+    case CPP_CHAR32_USERDEF:
+      {
+	tree literal;
+	cpp_token temp_tok = *tok;
+	const char *suffix = cpp_get_userdef_suffix (tok);
+	temp_tok.val.str.len -= strlen (suffix);
+	temp_tok.type = cpp_userdef_char_remove_type (type);
+	literal = build_userdef_literal (get_identifier (suffix),
+					 lex_charconst (&temp_tok), NULL_TREE);
+	*value = literal;
+      }
+      break;
+
     case CPP_CHAR:
     case CPP_WCHAR:
     case CPP_CHAR16:
@@ -422,6 +450,22 @@
       *value = lex_charconst (tok);
       break;
 
+    case CPP_STRING_USERDEF:
+    case CPP_WSTRING_USERDEF:
+    case CPP_STRING16_USERDEF:
+    case CPP_STRING32_USERDEF:
+    case CPP_UTF8STRING_USERDEF:
+      {
+	tree literal, string;
+	const char *suffix = cpp_get_userdef_suffix (tok);
+	string = build_string (tok->val.str.len - strlen (suffix),
+			       (const char *) tok->val.str.text);
+	literal = build_userdef_literal (get_identifier (suffix),
+					 string, NULL_TREE);
+	*value = literal;
+      }
+      break;
+
     case CPP_STRING:
     case CPP_WSTRING:
     case CPP_STRING16:
@@ -536,9 +580,11 @@
   return itk_none;
 }
 
-/* Interpret TOKEN, an integer with FLAGS as classified by cpplib.  */
+/* Interpret TOKEN, an integer with FLAGS as classified by cpplib.
+   For C++0X SUFFIX may contain a user-defined literal suffix.  */
 static tree
-interpret_integer (const cpp_token *token, unsigned int flags)
+interpret_integer (const cpp_token *token, unsigned int flags,
+		   const char *suffix)
 {
   tree value, type;
   enum integer_type_kind itk;
@@ -621,9 +667,10 @@
 }
 
 /* Interpret TOKEN, a floating point number with FLAGS as classified
-   by cpplib.  */
+   by cpplib.  For C++0X SUFFIX may contain a user-defined literal suffix.  */
 static tree
-interpret_float (const cpp_token *token, unsigned int flags)
+interpret_float (const cpp_token *token, unsigned int flags,
+		 const char *suffix)
 {
   tree type;
   tree const_type;
@@ -702,7 +749,9 @@
      has any suffixes, cut them off; REAL_VALUE_ATOF/ REAL_VALUE_HTOF
      can't handle them.  */
   copylen = token->val.str.len;
-  if (flags & CPP_N_DFLOAT)
+  if (flags & CPP_N_USERDEF)
+    copylen -= strlen (suffix);
+  else if (flags & CPP_N_DFLOAT)
     copylen -= 2;
   else
     {
Index: gcc/c-family/c-common.h
===================================================================
--- gcc/c-family/c-common.h	(revision 179317)
+++ gcc/c-family/c-common.h	(working copy)
@@ -1067,4 +1067,27 @@
   return NULL;
 }
 
+/* A suffix-identifier value doublet that represents user-defined literals
+   for C++-0x.  */
+struct GTY(()) tree_userdef_literal {
+  struct tree_base base;
+  tree suffix_id;
+  tree value;
+  tree num_string;
+};
+
+#define USERDEF_LITERAL_SUFFIX_ID(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->suffix_id)
+
+#define USERDEF_LITERAL_VALUE(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->value)
+
+#define USERDEF_LITERAL_NUM_STRING(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->num_string)
+
+#define USERDEF_LITERAL_TYPE(NODE) \
+  (TREE_TYPE (USERDEF_LITERAL_VALUE (NODE)))
+
+extern tree build_userdef_literal (tree suffix_id, tree value, tree num_string);
+
 #endif /* ! GCC_C_COMMON_H */
Index: gcc/c-family/c-common.def
===================================================================
--- gcc/c-family/c-common.def	(revision 179317)
+++ gcc/c-family/c-common.def	(working copy)
@@ -47,6 +47,12 @@
    evaluated.  */
 DEFTREECODE (EXCESS_PRECISION_EXPR, "excess_precision_expr", tcc_expression, 1)
 
+/* Used to represent a user-defined literal.
+   The operands are an IDENTIFIER for the suffix, the VALUE of the literal,
+   and for numeric literals the original string representation of the
+   number.  */
+DEFTREECODE (USERDEF_LITERAL, "userdef_literal", tcc_exceptional, 3)
+
 /*
 Local variables:
 mode:c
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C	(revision 0)
@@ -0,0 +1,4 @@
+// { dg-options -std=c++0x }
+
+template<char...>
+  int operator"" _xyz(unsigned long long);	// { dg-error "has invalid argument list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit_system_header
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit_system_header	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit_system_header	(revision 0)
@@ -0,0 +1,6 @@
+
+#pragma GCC system_header
+
+char
+operator"" stdsuffix(char __c)
+{ return __c/2; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C	(revision 0)
@@ -0,0 +1,42 @@
+// { dg-options "-std=c++0x" }
+
+//  Can't have *both* literal operator template and raw literal operator.
+
+int
+operator"" _abc(const char*)
+  {
+    return 42;
+  }
+
+template<char...>
+  int
+  operator"" _abc() // { dg-error "literal operator template|conflicts with raw literal operator" }
+  {
+    return 13;
+  }
+
+template<char...>
+  int
+  operator"" _def()
+  {
+    return 12;
+  }
+
+int
+operator"" _def(const char*) // { dg-error "raw literal operator|conflicts with literal operator template" }
+  {
+    return 43;
+  }
+
+int
+operator"" _ghi(long double)
+  {
+    return 42;
+  }
+
+template<char...>
+  int
+  operator"" _ghi() // OK
+  {
+    return 13;
+  }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C	(revision 0)
@@ -0,0 +1,43 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test simple operator declaration and definition in namespaces.
+
+#include <cmath>
+#include <limits>
+
+namespace Long
+{
+  long double operator"" _LL(long double);
+}
+
+namespace Short
+{
+  short
+  operator"" _SS(long double x)
+  { return std::fmod(x, static_cast<long double>(std::numeric_limits<short>::max())); }
+}
+
+void
+test1()
+{
+  long double x = Long::operator "" _LL(1.2L);
+
+  using namespace Short;
+  short s = operator"" _SS(1.2L);
+  short s2 = 1.2_SS;
+}
+
+int
+main()
+{
+  test1();
+}
+
+namespace Long
+{
+  long double
+  operator"" _LL(long double x)
+  { return x + 2.0L; }
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C	(revision 0)
@@ -0,0 +1,15 @@
+// { dg-options -std=c++0x }
+
+class Foo
+{
+public:
+  Foo() { }
+  int operator"" _Bar(char32_t);  // { dg-error "must be a non-member function" }
+};
+
+int i = operator"" _Bar(U'x');  // { dg-error "was not declared in this scope" }
+int j = U'x'_Bar;  // { dg-error "unable to find user-defined character literal operator" }
+
+int
+Foo::operator"" _Bar(char32_t)  // { dg-error "must be a non-member function" }
+{ return 42; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C	(revision 0)
@@ -0,0 +1,38 @@
+// { dg-options -std=c++0x }
+
+#include <cstddef>
+
+class Foo { };
+
+Foo
+operator"" _Foo(int *);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(unsigned long int);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(double);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const float *, std::size_t);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const wchar_t *, int);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const char16_t *);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(char...);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(unsigned long long int, char);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const char *, std::size_t, int);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(long double &);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(std::size_t, const char16_t *);	// { dg-error "has invalid argument list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C	(revision 0)
@@ -0,0 +1,17 @@
+// { dg-options "-std=c++98" }
+
+#include <cstddef>
+
+int
+operator"" _mm(long double m)	// { dg-warning "user-defined literals only available with" }
+{ return int(1000.0L * m); }
+
+int in = 0.0254_mm;	// { dg-error "invalid suffix" }
+
+int
+operator"" _Q(const char *, std::size_t)	// { dg-warning "user-defined literals only available with" }
+{ return 42; }
+
+int x = "Hello"_Q;	// { dg-error "invalid conversion from" }
+
+// { dg-error "expected" "" { target *-*-* } 15 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C	(revision 0)
@@ -0,0 +1,5 @@
+// { dg-options -std=c++0x }
+
+#include <string>
+
+std::string operator"" 5X(const char*, std::size_t);	// { dg-error "expected suffix identifier" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+constexpr unsigned long long
+operator"" _grow(unsigned long long n)
+{ return 2 * n; }
+
+double buffer[25_grow];
Index: gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C	(revision 0)
@@ -0,0 +1,49 @@
+// { dg-options -std=c++0x }
+
+//  Test that the standard suffixes shadow any user-defined suffixes of the same name.
+long double
+operator"" L(long double x)  // { dg-warning "floating point suffix|shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ULL(unsigned long long int k)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return k; }
+
+long double
+operator"" l(long double x)  // { dg-warning "floating point suffix|shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ull(unsigned long long int k)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return k; }
+
+//  Namespaces are no hiding place.
+namespace Long
+{
+
+long double
+operator"" L(long double x)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ULL(unsigned long long int k)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return k; }
+
+long double
+operator"" l(long double x)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ull(unsigned long long int k)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return k; }
+
+}
+
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 5 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 9 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 13 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 17 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 25 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 29 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 33 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 37 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test warning on declaration without leading underscore.
+
+long double operator"" nounder(long double); // { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" }
+
+template<char...>
+  int operator"" nounder(); // { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C	(revision 0)
@@ -0,0 +1,12 @@
+// { dg-options -std=c++0x }
+
+class Foo { };
+
+template<wchar_t...>
+  Foo operator"" _Foo(); // { dg-error "literal operator template|has invalid parameter list" }
+
+template<char>
+  Foo operator"" _Bar(); // { dg-error "literal operator template|has invalid parameter list" }
+
+template<typename... Type>
+  Foo operator"" _Bar(); // { dg-error "literal operator template|has invalid parameter list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-general.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-general.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-general.C	(revision 0)
@@ -0,0 +1,52 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test simple operator declaration and definition.
+
+#include <cstring>
+#include <string>
+#include <complex>
+#include <cassert>
+
+long double operator"" _v(long double);
+std::string operator"" _w(const char16_t*, size_t);
+unsigned operator"" _w(const char*);
+
+std::complex<double>
+operator"" _i(long double y)
+{ return std::complex<double>(0.0L, y); }
+
+void
+test1()
+{
+  long double x = operator"" _v(1.2L);
+  assert(x == 2.2L);
+
+  std::string s = operator"" _w(u"one", 3);
+  assert(s == "boo");
+
+  unsigned u = operator"" _w("Hello, World!");
+  assert(u == 13U);
+
+  std::complex<double> i = operator"" _i(2.0);
+  assert(i == std::complex<double>(0.0, 2.0));
+}
+
+int
+main()
+{
+  test1();
+}
+
+long double
+operator"" _v(long double x)
+{ return x + 1.0L; }
+
+std::string
+operator"" _w(const char16_t*, size_t)
+{ return std::string("boo"); }
+
+unsigned
+operator"" _w(const char* str)
+{ return strlen(str); }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C	(revision 0)
@@ -0,0 +1,3 @@
+// { dg-options -std=c++0x }
+
+#include "udlit_system_header"
Index: gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C	(revision 0)
@@ -0,0 +1,15 @@
+// { dg-options -std=c++0x }
+
+#include <string>
+
+std::string operator"" _i18n(const char*, std::size_t);
+
+std::string vogon_poem = R"V0G0N(
+                O freddled gruntbuggly thy micturations are to me
+                    As plured gabbleblochits on a lurgid bee.
+                 Groop, I implore thee my foonting turlingdromes.   
+              And hooptiously drangle me with crinkly bindlewurdles,
+  Or I will rend thee in the gobberwarts with my blurlecruncheon, see if I don't.
+
+                    (by Prostetnic Vogon Jeltz; see p. 56/57)
+)V0G0N"_i18n;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test error on non-function declaration.
+
+double operator"" _baddecl; // { dg-error "as non-function" }
+
+template<char...>
+  int operator"" _badtmpldecl; // { dg-error "as non-function" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-addr.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-addr.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-addr.C	(revision 0)
@@ -0,0 +1,10 @@
+// { dg-options "-std=c++0x" }
+
+#include <cstddef>
+
+bool operator"" _yn(const char*, size_t);
+
+typedef bool (*pfunk)(const char*, size_t);
+pfunk p = &operator"" _yn;
+
+bool tf = p("Hello,\0 World!", 14);
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C	(revision 0)
@@ -0,0 +1,4 @@
+// { dg-options -std=c++0x }
+
+template<char...>
+  int operator"" _abc();
Index: gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C	(revision 0)
@@ -0,0 +1,8 @@
+// { dg-options -std=c++0x }
+
+extern "C" {
+
+int
+operator"" _badclinkage(unsigned long long);	// { dg-error "operator with C linkage" }
+
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-template.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-template.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-template.C	(revision 0)
@@ -0,0 +1,51 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test template operator declaration and definition.
+
+#include <cassert>
+
+template<char...>
+  int operator"" _abc();
+
+template<>
+  int
+  operator"" _abc<>()
+  { return -1; }
+
+template<>
+  int
+  operator"" _abc<'L','U','E'>()
+  { return 42; }
+
+template<>
+  int
+  operator"" _abc<'6','6','6'>()
+  { return 21; }
+
+int
+test1()
+{
+  int i = operator"" _abc<'1','2','3'>();
+  assert(i == 45);
+  int universal_meaning = operator"" _abc<'L','U','E'>();
+  assert(universal_meaning == 42);
+  int b = operator"" _abc<'6','6','6'>();
+  int z = operator"" _abc<>();
+  assert(z == -1);
+  int j = 123_abc;
+  assert(j == i);
+  int jb = 666_abc;
+  assert(jb == b);
+}
+
+int
+main()
+{
+  test1();
+}
+
+template<char... Chars>
+  int operator"" _abc()
+  { return 42 + sizeof...(Chars); }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-args.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-args.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-args.C	(revision 0)
@@ -0,0 +1,38 @@
+// { dg-options -std=c++0x }
+
+#include <cstddef>
+
+class Foo { };
+
+Foo
+operator"" _Foo(const char *);
+
+Foo
+operator"" _Foo(unsigned long long int);
+
+Foo
+operator"" _Foo(long double);
+
+Foo
+operator"" _Foo(char);
+
+Foo
+operator"" _Foo(wchar_t);
+
+Foo
+operator"" _Foo(char16_t);
+
+Foo
+operator"" _Foo(char32_t);
+
+Foo
+operator"" _Foo(const char *, std::size_t);
+
+Foo
+operator"" _Foo(const wchar_t *, std::size_t);
+
+Foo
+operator"" _Foo(const char16_t *, std::size_t);
+
+Foo
+operator"" _Foo(const char32_t *, std::size_t);
Index: gcc/testsuite/g++.dg/cpp0x/udlit-declare-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-declare-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-declare-neg.C	(revision 0)
@@ -0,0 +1,15 @@
+// { dg-options "-std=c++0x" }
+
+//  Check that undeclared literal operator calls and literals give appropriate errors.
+
+int i = operator"" _Bar('x');  // { dg-error "was not declared in this scope" }
+int j = 'x'_Bar;  // { dg-error "unable to find user-defined character literal operator" }
+
+int ii = operator"" _BarCharStr("Howdy, Pardner!");  // { dg-error "was not declared in this scope" }
+int jj = "Howdy, Pardner!"_BarCharStr;  // { dg-error "unable to find user-defined string literal operator" }
+
+unsigned long long iULL = operator"" _BarULL(666ULL);  // { dg-error "was not declared in this scope" }
+unsigned long long jULL = 666_BarULL;  // { dg-error "unable to find user-defined numeric literal operator" }
+
+long double iLD = operator"" _BarLD(666.0L);  // { dg-error "was not declared in this scope" }
+long double jLD = 666.0_BarLD;  // { dg-error "unable to find user-defined numeric literal operator" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C	(revision 0)
@@ -0,0 +1,5 @@
+// { dg-options -std=c++0x }
+
+char32_t
+operator"" (char32_t C)	// { dg-error "expected suffix identifier" }
+{ return C; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test error on non-empty string after 'operator' keyword.
+
+double operator"hi" _badword(long double); // { dg-error "expected empty string after" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nospace-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nospace-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nospace-neg.C	(revision 0)
@@ -0,0 +1,3 @@
+// { dg-options "-std=c++0x" }
+
+float operator ""_abc(const char*); // { dg-error "missing space between|and suffix identifier" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-inline.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-inline.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-inline.C	(revision 0)
@@ -0,0 +1,22 @@
+// { dg-options "-std=c++0x" }
+
+//  Literal operators can be inline.
+
+inline int
+operator"" _thing1(char cc)
+{ return 42 * cc; }
+
+int operator"" _thing2(char cc);
+
+class Foo
+{
+  int
+  friend operator"" _thing2(char cc)
+  { return 42 * cc; }
+};
+
+int i = operator"" _thing1('x');
+int j = 'x'_thing1;
+
+int iF = operator"" _thing2('x');
+int jF = 'x'_thing2;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+extern "C"_badlinkage {	// { dg-error "expected unqualified-id before" }
+
+int foo();
+
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-friend.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-friend.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-friend.C	(revision 0)
@@ -0,0 +1,28 @@
+// { dg-options -std=c++0x }
+
+long double
+operator"" _Hertz(long double);
+
+class Foo
+{
+public:
+  Foo() { }
+
+  friend Foo operator"" _Bar(char);
+
+  friend long double
+  operator"" _Hertz(long double omega)
+  { return omega / 6.28318530717958648; }
+};
+
+Foo
+operator"" _Bar(char)
+{ return Foo(); }
+
+Foo f1 = operator"" _Bar('x');
+
+Foo f2 = 'x'_Bar;
+
+long double fm1 = operator"" _Hertz(552.92L);
+
+long double fm2 = 552.92_Hertz;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+#include <string>
+
+std::string operator"" _xxx(const char*, size_t);
+
+std::string operator"" _yyy(const char*, size_t);
+
+std::string concat = "Hello, "_xxx "World!"_yyy;	// { dg-error "inconsistent user-defined literal suffixes" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options -std=c++0x }
+
+class Foo { };
+
+template<char...>
+  Foo operator"" _Foo();
Index: gcc/testsuite/g++.dg/cpp0x/udlit-concat.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-concat.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-concat.C	(revision 0)
@@ -0,0 +1,24 @@
+// { dg-options "-std=c++0x" }
+
+#include <string>
+
+std::string operator"" _www(const char*, size_t);
+
+std::string concat01 = "Hello, " "World!"_www;
+
+std::string concat10 = "Hello, "_www "World!";
+
+std::string concat11 = "Hello, "_www "World!"_www;
+
+
+class Tachyon { };
+
+Tachyon operator"" _fast(const char*, size_t);
+
+int operator"" _fast(const char32_t*, size_t);
+
+int speedy01 = "Hello, " U"World!"_fast;
+
+int speedy10 = "Hello, "_fast U"World!";
+
+int speedy11 = "Hello, "_fast U"World!"_fast;
Index: gcc/cp/typeck.c
===================================================================
--- gcc/cp/typeck.c	(revision 179317)
+++ gcc/cp/typeck.c	(working copy)
@@ -8324,3 +8324,127 @@
   return 1;
 }
 
+
+/* Return true if a user-defined literal operator has one of the allowed
+   argument types.  */
+
+bool
+check_raw_literal_operator (const_tree decl)
+{
+  tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
+  tree argtype;
+  int arity;
+  bool maybe_raw_p = false;
+  tree const_char_ptr_type_node
+       = build_pointer_type (build_type_variant (char_type_node, 1, 0));
+
+  /* Count the number and type of arguments and check for ellipsis.  */
+  for (argtype = argtypes, arity = 0;
+       argtype && argtype != void_list_node;
+       ++arity, argtype = TREE_CHAIN (argtype))
+    {
+      tree t = TREE_VALUE (argtype);
+
+      if (same_type_p (t, const_char_ptr_type_node))
+	maybe_raw_p = true;
+    }
+  if (!argtype)
+    return false; /* Found ellipsis.  */
+
+  if (!maybe_raw_p || arity != 1)
+    return false;
+
+  return true;
+}
+
+
+/* Return true if a user-defined literal operator has one of the allowed
+   argument types.  */
+
+bool
+check_literal_operator_args (const_tree decl,
+			     bool *long_long_unsigned_p, bool *long_double_p)
+{
+  tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
+  if (processing_template_decl)
+    return (argtypes == NULL_TREE
+	    || same_type_p (TREE_VALUE (argtypes), void_type_node));
+  else
+    {
+      tree argtype;
+      int arity;
+      int max_arity = 2;
+      bool found_string_p = false;
+      bool maybe_raw_p = false;
+      bool found_size_p = false;
+      tree const_char_ptr_type_node
+	   = build_pointer_type (build_type_variant (char_type_node, 1, 0));
+      tree const_wchar_ptr_type_node
+	   = build_pointer_type (build_type_variant (wchar_type_node, 1, 0));
+      tree const_char16_ptr_type_node
+	   = build_pointer_type (build_type_variant (char16_type_node, 1, 0));
+      tree const_char32_ptr_type_node
+	   = build_pointer_type (build_type_variant (char32_type_node, 1, 0));
+
+      *long_long_unsigned_p = false;
+      *long_double_p = false;
+
+      /* Count the number and type of arguments and check for ellipsis.  */
+      for (argtype = argtypes, arity = 0;
+	   argtype && argtype != void_list_node;
+	   argtype = TREE_CHAIN (argtype))
+	{
+	  tree t = TREE_VALUE (argtype);
+	  ++arity;
+
+	  if (same_type_p (t, const_char_ptr_type_node))
+	    {
+	      found_string_p = true;
+	      maybe_raw_p = true;
+	    }
+	  else if (same_type_p (t, const_wchar_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, const_char16_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, const_char32_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, size_type_node))
+	    {
+	      if (!found_string_p)
+		return false;
+	      found_size_p = true;
+	    }
+	  else if (same_type_p (t, long_long_unsigned_type_node))
+	    {
+	      max_arity = 1;
+	      *long_long_unsigned_p = true;
+	    }
+	  else if (same_type_p (t, long_double_type_node))
+	    {
+	      max_arity = 1;
+	      *long_double_p = true;
+	    }
+	  else if (same_type_p (t, char_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, wchar_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, char16_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, char32_type_node))
+	    max_arity = 1;
+	  else
+	    return false;
+	}
+      if (!argtype)
+	return false; /* Found ellipsis.  */
+
+      if (arity > max_arity)
+	return false;
+
+      if (found_string_p && !maybe_raw_p && !found_size_p)
+	return false;
+
+      return true;
+    }
+}
+
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 179317)
+++ gcc/cp/decl.c	(working copy)
@@ -1203,6 +1203,21 @@
       || TREE_TYPE (olddecl) == error_mark_node)
     return error_mark_node;
 
+  if (UDLIT_OPER_P (DECL_NAME (newdecl))
+      && UDLIT_OPER_P (DECL_NAME (olddecl)))
+    {
+      if (TREE_CODE (newdecl) == TEMPLATE_DECL
+	  && TREE_CODE (olddecl) != TEMPLATE_DECL
+	  && check_raw_literal_operator (olddecl))
+	error ("literal operator template %q+D conflicts with"
+	       " raw literal operator %qD", newdecl, olddecl);
+      else if (TREE_CODE (newdecl) != TEMPLATE_DECL
+	       && TREE_CODE (olddecl) == TEMPLATE_DECL
+	       && check_raw_literal_operator (newdecl))
+	error ("raw literal operator %q+D conflicts with"
+	       " literal operator template %qD", newdecl, olddecl);
+    }
+
   if (DECL_P (olddecl)
       && TREE_CODE (newdecl) == FUNCTION_DECL
       && TREE_CODE (olddecl) == FUNCTION_DECL
@@ -7333,7 +7348,48 @@
   if (IDENTIFIER_OPNAME_P (DECL_NAME (decl))
       && !grok_op_properties (decl, /*complain=*/true))
     return NULL_TREE;
+  else if (UDLIT_OPER_P (DECL_NAME (decl)))
+    {
+      bool long_long_unsigned_p;
+      bool long_double_p;
+      const char *suffix = NULL;
+      /* [over.literal]/6: Literal operators shall not have C linkage. */
+      if (DECL_LANGUAGE(decl) == lang_c)
+	{
+	  error ("literal operator with C linkage");
+	  return NULL_TREE;
+	}
 
+      if (DECL_NAMESPACE_SCOPE_P (decl))
+	{
+	  if (!check_literal_operator_args (decl, &long_long_unsigned_p,
+					    &long_double_p))
+	    {
+	      error ("%qD has invalid argument list", decl);
+	      return NULL_TREE;
+	    }
+
+	  suffix = UDLIT_OP_SUFFIX (DECL_NAME (decl));
+	  if (long_long_unsigned_p)
+	    {
+	      if (cpp_interpret_int_suffix (suffix, strlen (suffix)))
+		warning (0, "integer suffix %<%s%>"
+			    " shadowed by implementation", suffix);
+	    }
+	  else if (long_double_p)
+	    {
+	      if (cpp_interpret_float_suffix (suffix, strlen (suffix)))
+		warning (0, "floating point suffix %<%s%>"
+			    " shadowed by implementation", suffix);
+	    }
+	}
+      else
+	{
+	  error ("%qD must be a non-member function", decl);
+	  return NULL_TREE;
+	}
+    }
+
   if (funcdef_flag)
     /* Make the init_value nonzero so pushdecl knows this is not
        tentative.  error_mark_node is replaced later with the BLOCK.  */
@@ -8518,6 +8574,15 @@
       error ("declaration of %qD as non-function", dname);
       return error_mark_node;
     }
+ 
+  if (dname
+      && TREE_CODE (dname) == IDENTIFIER_NODE
+      && UDLIT_OPER_P (dname)
+      && innermost_code != cdk_function)
+    {
+      error ("declaration of %qD as non-function", dname);
+      return error_mark_node;
+    }
 
   if (dname && IDENTIFIER_OPNAME_P (dname))
     {
@@ -13734,6 +13799,7 @@
     case TRAIT_EXPR:		return TS_CP_TRAIT_EXPR;
     case LAMBDA_EXPR:		return TS_CP_LAMBDA_EXPR;
     case TEMPLATE_INFO:		return TS_CP_TEMPLATE_INFO;
+    case USERDEF_LITERAL:	return TS_CP_USERDEF_LITERAL;
     default:			return TS_CP_GENERIC;
     }
 }
Index: gcc/cp/error.c
===================================================================
--- gcc/cp/error.c	(revision 179317)
+++ gcc/cp/error.c	(working copy)
@@ -1534,6 +1534,8 @@
     }
   else if (name && IDENTIFIER_OPNAME_P (name))
     pp_cxx_tree_identifier (cxx_pp, name);
+  else if (name && UDLIT_OPER_P (name))
+    pp_cxx_tree_identifier (cxx_pp, name);
   else
     dump_decl (name, flags);
 
@@ -1756,6 +1758,10 @@
       pp_constant (cxx_pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (cxx_pp, t);
+      break;
+
     case THROW_EXPR:
       /* While waiting for caret diagnostics, avoid printing
 	 __cxa_allocate_exception, __cxa_throw, and the like.  */
@@ -3231,7 +3237,7 @@
 	pedwarn (input_location, OPT_pedantic,
 		 "inline namespaces "
 		 "only available with -std=c++0x or -std=gnu++0x");
-	break;	
+	break;
       case CPP0X_OVERRIDE_CONTROLS:
 	pedwarn (input_location, 0,
 		 "override controls (override/final) "
@@ -3242,8 +3248,13 @@
 		 "non-static data member initializers "
 		 "only available with -std=c++0x or -std=gnu++0x");
         break;
+      case CPP0X_USER_DEFINED_LITERALS:
+	pedwarn (input_location, 0,
+		 "user-defined literals "
+		 "only available with -std=c++0x or -std=gnu++0x");
+	break;
       default:
-	gcc_unreachable();
+	gcc_unreachable ();
       }
 }
 
Index: gcc/cp/cxx-pretty-print.c
===================================================================
--- gcc/cp/cxx-pretty-print.c	(revision 179317)
+++ gcc/cp/cxx-pretty-print.c	(working copy)
@@ -367,6 +367,17 @@
     pp_cxx_unqualified_id (pp, t);
 }
 
+/* user-defined literal:
+      literal ud-suffix  */
+
+void
+pp_cxx_userdef_literal (cxx_pretty_printer *pp, tree t)
+{
+  pp_cxx_constant (pp, USERDEF_LITERAL_VALUE (t));
+  pp_cxx_id_expression (pp, USERDEF_LITERAL_SUFFIX_ID (t));
+}
+
+
 /* primary-expression:
      literal
      this
@@ -413,6 +424,10 @@
       pp_cxx_constant (pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (pp, t);
+      break;
+
     case BASELINK:
       t = BASELINK_FUNCTIONS (t);
     case VAR_DECL:
@@ -1023,6 +1038,10 @@
       pp_cxx_constant (pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (pp, t);
+      break;
+
     case RESULT_DECL:
       pp_cxx_unqualified_id (pp, t);
       break;
Index: gcc/cp/semantics.c
===================================================================
--- gcc/cp/semantics.c	(revision 179317)
+++ gcc/cp/semantics.c	(working copy)
@@ -7748,6 +7748,7 @@
     case TEMPLATE_PARM_INDEX:
     case TRAIT_EXPR:
     case IDENTIFIER_NODE:
+    case USERDEF_LITERAL:
       /* We can see a FIELD_DECL in a pointer-to-member expression.  */
     case FIELD_DECL:
     case PARM_DECL:
Index: gcc/cp/cxx-pretty-print.h
===================================================================
--- gcc/cp/cxx-pretty-print.h	(revision 179317)
+++ gcc/cp/cxx-pretty-print.h	(working copy)
@@ -74,5 +74,7 @@
 void pp_cxx_trait_expression (cxx_pretty_printer *, tree);
 void pp_cxx_va_arg_expression (cxx_pretty_printer *, tree);
 void pp_cxx_offsetof_expression (cxx_pretty_printer *, tree);
+void pp_cxx_userdef_literal (cxx_pretty_printer *, tree);
 
+
 #endif /* GCC_CXX_PRETTY_PRINT_H */
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 179317)
+++ gcc/cp/parser.c	(working copy)
@@ -210,6 +210,8 @@
   (cp_lexer *);
 static void cp_lexer_rollback_tokens
   (cp_lexer *);
+static tree cp_literal_operator_id
+  (const char *);
 #ifdef ENABLE_CHECKING
 static void cp_lexer_print_token
   (FILE *, cp_token *);
@@ -501,20 +503,20 @@
 	}
       else
 	{
-          if (warn_cxx0x_compat
-              && C_RID_CODE (token->u.value) >= RID_FIRST_CXX0X
-              && C_RID_CODE (token->u.value) <= RID_LAST_CXX0X)
-            {
-              /* Warn about the C++0x keyword (but still treat it as
-                 an identifier).  */
-              warning (OPT_Wc__0x_compat, 
-                       "identifier %qE will become a keyword in C++0x",
-                       token->u.value);
+	  if (warn_cxx0x_compat
+	      && C_RID_CODE (token->u.value) >= RID_FIRST_CXX0X
+	      && C_RID_CODE (token->u.value) <= RID_LAST_CXX0X)
+	    {
+	      /* Warn about the C++0x keyword (but still treat it as
+		 an identifier).  */
+	      warning (OPT_Wc__0x_compat, 
+		       "identifier %qE will become a keyword in C++0x",
+		       token->u.value);
 
-              /* Clear out the C_RID_CODE so we don't warn about this
-                 particular identifier-turned-keyword again.  */
-              C_SET_RID_CODE (token->u.value, RID_MAX);
-            }
+	      /* Clear out the C_RID_CODE so we don't warn about this
+		 particular identifier-turned-keyword again.  */
+	      C_SET_RID_CODE (token->u.value, RID_MAX);
+	    }
 
 	  token->ambiguous_p = false;
 	  token->keyword = RID_MAX;
@@ -1531,6 +1533,12 @@
   (cp_parser *);
 static tree cp_parser_string_literal
   (cp_parser *, bool, bool);
+static tree cp_parser_userdef_char_literal
+  (cp_parser *);
+static tree cp_parser_userdef_string_literal
+  (cp_token *);
+static tree cp_parser_userdef_numeric_literal
+  (cp_parser *);
 
 /* Basic concepts [gram.basic]  */
 
@@ -2039,6 +2047,8 @@
   (cp_parser *);
 static bool cp_parser_allow_gnu_extensions_p
   (cp_parser *);
+static bool cp_parser_is_pure_string_literal
+  (cp_token *);
 static bool cp_parser_is_string_literal
   (cp_token *);
 static bool cp_parser_is_keyword
@@ -2059,7 +2069,7 @@
 /* Returns nonzero if TOKEN is a string literal.  */
 
 static bool
-cp_parser_is_string_literal (cp_token* token)
+cp_parser_is_pure_string_literal (cp_token* token)
 {
   return (token->type == CPP_STRING ||
 	  token->type == CPP_STRING16 ||
@@ -2068,6 +2078,20 @@
 	  token->type == CPP_UTF8STRING);
 }
 
+/* Returns nonzero if TOKEN is a string literal
+   of a user-defined string literal.  */
+
+static bool
+cp_parser_is_string_literal (cp_token* token)
+{
+  return (cp_parser_is_pure_string_literal (token) ||
+	  token->type == CPP_STRING_USERDEF ||
+	  token->type == CPP_STRING16_USERDEF ||
+	  token->type == CPP_STRING32_USERDEF ||
+	  token->type == CPP_WSTRING_USERDEF ||
+	  token->type == CPP_UTF8STRING_USERDEF);
+}
+
 /* Returns nonzero if TOKEN is the indicated KEYWORD.  */
 
 static bool
@@ -3107,7 +3131,11 @@
   struct obstack str_ob;
   cpp_string str, istr, *strs;
   cp_token *tok;
-  enum cpp_ttype type;
+  enum cpp_ttype type, curr_type;
+  int have_suffix_p = 0;
+  tree string_tree;
+  tree suffix_id = NULL_TREE;
+  bool curr_tok_is_userdef_p = false;
 
   tok = cp_lexer_peek_token (parser->lexer);
   if (!cp_parser_is_string_literal (tok))
@@ -3116,7 +3144,18 @@
       return error_mark_node;
     }
 
-  type = tok->type;
+  if (cpp_userdef_string_p (tok->type))
+    {
+      string_tree = USERDEF_LITERAL_VALUE (tok->u.value);
+      curr_type = cpp_userdef_string_remove_type (tok->type);
+      curr_tok_is_userdef_p = true;
+    }
+  else
+    {
+      string_tree = tok->u.value;
+      curr_type = tok->type;
+    }
+  type = curr_type;
 
   /* Try to avoid the overhead of creating and destroying an obstack
      for the common case of just one string.  */
@@ -3125,10 +3164,19 @@
     {
       cp_lexer_consume_token (parser->lexer);
 
-      str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value);
-      str.len = TREE_STRING_LENGTH (tok->u.value);
+      str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree);
+      str.len = TREE_STRING_LENGTH (string_tree);
       count = 1;
 
+      if (curr_tok_is_userdef_p)
+	{
+	  suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value);
+	  have_suffix_p = 1;
+	  curr_type = cpp_userdef_string_remove_type (tok->type);
+	}
+      else
+	curr_type = tok->type;
+
       strs = &str;
     }
   else
@@ -3140,14 +3188,35 @@
 	{
 	  cp_lexer_consume_token (parser->lexer);
 	  count++;
-	  str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value);
-	  str.len = TREE_STRING_LENGTH (tok->u.value);
+	  str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree);
+	  str.len = TREE_STRING_LENGTH (string_tree);
 
-	  if (type != tok->type)
+	  if (curr_tok_is_userdef_p)
 	    {
+	      tree curr_suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value);
+	      if (have_suffix_p == 0)
+		{
+		  suffix_id = curr_suffix_id;
+		  have_suffix_p = 1;
+		}
+	      else if (have_suffix_p == 1
+		       && curr_suffix_id != suffix_id)
+		{
+		  error ("inconsistent user-defined literal suffixes"
+			 " %qD and %qD in string literal",
+			 suffix_id, curr_suffix_id);
+		  have_suffix_p = -1;
+		}
+	      curr_type = cpp_userdef_string_remove_type (tok->type);
+	    }
+	  else
+	    curr_type = tok->type;
+
+	  if (type != curr_type)
+	    {
 	      if (type == CPP_STRING)
-		type = tok->type;
-	      else if (tok->type != CPP_STRING)
+		type = curr_type;
+	      else if (curr_type != CPP_STRING)
 		error_at (tok->location,
 			  "unsupported non-standard concatenation "
 			  "of string literals");
@@ -3156,6 +3225,18 @@
 	  obstack_grow (&str_ob, &str, sizeof (cpp_string));
 
 	  tok = cp_lexer_peek_token (parser->lexer);
+	  if (cpp_userdef_string_p (tok->type))
+	    {
+	      string_tree = USERDEF_LITERAL_VALUE (tok->u.value);
+	      curr_type = cpp_userdef_string_remove_type (tok->type);
+	      curr_tok_is_userdef_p = true;
+	    }
+	  else
+	    {
+	      string_tree = tok->u.value;
+	      curr_type = tok->type;
+	      curr_tok_is_userdef_p = false;
+	    }
 	}
       while (cp_parser_is_string_literal (tok));
 
@@ -3193,6 +3274,13 @@
 	}
 
       value = fix_string_type (value);
+
+      if (have_suffix_p)
+	{
+	  tree literal = build_userdef_literal (suffix_id, value, NULL_TREE);
+	  tok->u.value = literal;
+	  return cp_parser_userdef_string_literal (tok);
+	}
     }
   else
     /* cpp_interpret_string has issued an error.  */
@@ -3204,7 +3292,184 @@
   return value;
 }
 
+/* Parse a user-defined char constant.  Returns a call to a user-defined
+   literal operator taking the character as an argument.  */
 
+static tree
+cp_parser_userdef_char_literal (cp_parser *parser)
+{
+  cp_token *token = NULL;
+  tree literal, suffix_id, value;
+  tree name, decl;
+  tree result;
+  VEC(tree,gc) *vec;
+
+  token = cp_lexer_consume_token (parser->lexer);
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  value = USERDEF_LITERAL_VALUE (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  vec = make_tree_vector ();
+  VEC_safe_push (tree, gc, vec, value);
+  decl = lookup_function_nonclass (name, vec, /*block_p=*/false);
+  if (!decl || decl == error_mark_node)
+    {
+      error ("unable to find user-defined character literal operator %qD",
+	     name);
+      release_tree_vector (vec);
+      return error_mark_node;
+    }
+  result = finish_call_expr (decl, &vec, false, true, tf_warning_or_error);
+  release_tree_vector (vec);
+
+  return result;
+}
+
+/* A subroutine of cp_parser_userdef_numeric_literal to
+   create a char... template parameter pack from a string node.  */
+
+static tree
+make_char_string_pack (tree value)
+{
+  tree parmvec;
+  tree argpack = make_node (NONTYPE_ARGUMENT_PACK);
+  const char *str = TREE_STRING_POINTER (value);
+  int i, len = TREE_STRING_LENGTH (value);
+  /*  Do I need to stuff THIS into a tree? */
+  tree argvec = make_tree_vec (1);
+
+  /* Fill in PARMVEC with all of the parameters.  */
+  parmvec = make_tree_vec (len);
+  for (i = 0; i < len; ++i)
+    TREE_VEC_ELT (parmvec, i) = build_int_cst (char_type_node, str[i]);
+
+  /* Build the argument packs.  */
+  SET_ARGUMENT_PACK_ARGS (argpack, parmvec);
+  TREE_TYPE (argpack) = char_type_node;
+
+  /*  Do I need to stuff THIS into a tree? */
+  TREE_VEC_ELT (argvec, 0) = argpack;
+
+  return argvec;
+}
+
+/* Parse a user-defined numeric constant.  returns a call to a user-defined
+   literal operator.  */
+static tree
+cp_parser_userdef_numeric_literal (cp_parser *parser)
+{
+  cp_token *token = NULL;
+  tree literal, suffix_id, value, num_string;
+  tree name, decl;
+  tree result = error_mark_node;
+  VEC(tree,gc) *args;
+
+  token = cp_lexer_consume_token (parser->lexer);
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  value = USERDEF_LITERAL_VALUE (literal);
+  num_string = USERDEF_LITERAL_NUM_STRING (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  /* Try to find the literal operator by finishing the call expression
+     with the numeric argument.  */
+  args = make_tree_vector ();
+  VEC_safe_push (tree, gc, args, value);
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl && decl != error_mark_node)
+    {
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  /* If the numeric argument didn't work, look for a raw literal
+     operator taking a const char* argument consisting of the number
+     in string format.  */
+  args = make_tree_vector ();
+  VEC_safe_push (tree, gc, args, num_string);
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl && decl != error_mark_node)
+    {
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  /* If the raw literal didn't work, look for a non-type template
+     function with parameter pack char....  Call the function with
+     template parameter characters representing the number.  */
+  args = make_tree_vector ();
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl && decl != error_mark_node)
+    {
+      tree tmpl_args = make_char_string_pack (num_string);
+      decl = lookup_template_function (decl, tmpl_args);
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  if (result == error_mark_node)
+    error ("unable to find user-defined numeric literal operator %qD", name);
+
+  return result;
+}
+
+/* Parse a user-defined string constant.  Returns a call to a user-defined
+   literal operator taking a character pointer and the length of the string
+   as arguments.  */
+static tree
+cp_parser_userdef_string_literal (cp_token *token)
+{
+  tree literal, suffix_id, value;
+  tree name, decl;
+  tree result;
+  VEC(tree,gc) *vec;
+  int len;
+
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+  value = USERDEF_LITERAL_VALUE (literal);
+  len = TREE_STRING_LENGTH (value) - 1;
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  vec = make_tree_vector ();
+  VEC_safe_push (tree, gc, vec, value);
+  VEC_safe_push (tree, gc, vec, build_int_cst (size_type_node, len));
+  decl = lookup_function_nonclass (name, vec, /*block_p=*/false);
+  if (!decl || decl == error_mark_node)
+    {
+      error ("unable to find user-defined string literal operator %qD", name);
+      release_tree_vector (vec);
+      return error_mark_node;
+    }
+  result = finish_call_expr (decl, &vec, false, true, tf_warning_or_error);
+  release_tree_vector (vec);
+
+  return result;
+}
+
+
 /* Basic concepts [gram.basic]  */
 
 /* Parse a translation-unit.
@@ -3347,12 +3612,16 @@
 	   character-literal
 	   floating-literal
 	   string-literal
-	   boolean-literal  */
+	   boolean-literal
+	   pointer-literal
+	   user-defined-literal  */
     case CPP_CHAR:
     case CPP_CHAR16:
     case CPP_CHAR32:
     case CPP_WCHAR:
     case CPP_NUMBER:
+      if (TREE_CODE (token->u.value) == USERDEF_LITERAL)
+	return cp_parser_userdef_numeric_literal (parser);
       token = cp_lexer_consume_token (parser->lexer);
       if (TREE_CODE (token->u.value) == FIXED_CST)
 	{
@@ -3406,11 +3675,22 @@
 	}
       return token->u.value;
 
+    case CPP_CHAR_USERDEF:
+    case CPP_CHAR16_USERDEF:
+    case CPP_CHAR32_USERDEF:
+    case CPP_WCHAR_USERDEF:
+      return cp_parser_userdef_char_literal (parser);
+
     case CPP_STRING:
     case CPP_STRING16:
     case CPP_STRING32:
     case CPP_WSTRING:
     case CPP_UTF8STRING:
+    case CPP_STRING_USERDEF:
+    case CPP_STRING16_USERDEF:
+    case CPP_STRING32_USERDEF:
+    case CPP_WSTRING_USERDEF:
+    case CPP_UTF8STRING_USERDEF:
       /* ??? Should wide strings be allowed when parser->translate_strings_p
 	 is false (i.e. in attributes)?  If not, we can kill the third
 	 argument to cp_parser_string_literal.  */
@@ -4246,6 +4526,14 @@
 	  /* If that didn't work, try a conversion-function-id.  */
 	  if (!cp_parser_parse_definitely (parser))
 	    id = cp_parser_conversion_function_id (parser);
+	  else if (UDLIT_OPER_P (id))
+	    {
+	      /* 17.6.3.3.5  */
+	      const char *name = UDLIT_OP_SUFFIX (id);
+	      if (name[0] != '_' && !in_system_header)
+		warning (0, "literal operator suffixes not preceded by %<_%>"
+			    " are reserved for future standardization");
+	    }
 
 	  return id;
 	}
@@ -4888,7 +5176,7 @@
 	/* Restore the saved message.  */
 	parser->type_definition_forbidden_message = saved_message;
 	/* `typeid' may not appear in an integral constant expression.  */
-	if (cp_parser_non_integral_constant_expression(parser, NIC_TYPEID))
+	if (cp_parser_non_integral_constant_expression (parser, NIC_TYPEID))
 	  return error_mark_node;
       }
       break;
@@ -9471,7 +9759,7 @@
   /* If the next token is `extern' and the following token is a string
      literal, then we have a linkage specification.  */
   if (token1.keyword == RID_EXTERN
-      && cp_parser_is_string_literal (&token2))
+      && cp_parser_is_pure_string_literal (&token2))
     cp_parser_linkage_specification (parser);
   /* If the next token is `template', then we have either a template
      declaration, an explicit instantiation, or an explicit
@@ -10902,6 +11190,22 @@
   return cp_parser_operator (parser);
 }
 
+/* Return an identifier node for a user-defined literal operator.
+   The suffix identifier is chained to the operator name identifier.  */
+
+static tree
+cp_literal_operator_id (const char* name)
+{
+  tree identifier;
+  char *buffer = XNEWVEC (char, strlen (UDLIT_OP_ANSI_PREFIX)
+			      + strlen (name) + 10);
+  sprintf (buffer, UDLIT_OP_ANSI_FORMAT, name);
+  identifier = get_identifier (buffer);
+  /*IDENTIFIER_UDLIT_OPNAME_P (identifier) = 1; If we get a flag someday. */
+
+  return identifier;
+}
+
 /* Parse an operator.
 
    operator:
@@ -11121,6 +11425,37 @@
       cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE);
       return ansi_opname (ARRAY_REF);
 
+    case CPP_STRING:
+      if (cxx_dialect == cxx98)
+	maybe_warn_cpp0x (CPP0X_USER_DEFINED_LITERALS);
+      if (TREE_STRING_LENGTH (token->u.value) > 2)
+	{
+	  error ("expected empty string after %<operator%> keyword");
+	  return error_mark_node;
+	}
+      /* Consume the string.  */
+      cp_lexer_consume_token (parser->lexer);
+      /* Look for the suffix identifier.  */
+      token = cp_lexer_peek_token (parser->lexer);
+      if (token->type == CPP_NAME)
+	{
+	  id = cp_parser_identifier (parser);
+	  if (id != error_mark_node)
+	    {
+	      const char *name = IDENTIFIER_POINTER (id);
+	      return cp_literal_operator_id (name);
+	    }
+	}
+      else
+	{
+	  error ("expected suffix identifier");
+	  return error_mark_node;
+	}
+
+    case CPP_STRING_USERDEF:
+      error ("missing space between %<\"\"%> and suffix identifier");
+      return error_mark_node;
+
     default:
       /* Anything else is an error.  */
       break;
@@ -20304,6 +20639,32 @@
   /* Finish up.  */
   finish_template_decl (parameter_list);
 
+  /* Check the template arguments for a literal operator template.  */
+  if (decl
+      && (TREE_CODE (decl) == FUNCTION_DECL || DECL_FUNCTION_TEMPLATE_P (decl))
+      && UDLIT_OPER_P (DECL_NAME (decl)))
+    {
+      bool ok = true;
+      if (parameter_list == NULL_TREE)
+	ok = false;
+      else
+	{
+	  int num_parms = TREE_VEC_LENGTH (parameter_list);
+	  if (num_parms != 1)
+	    ok = false;
+	  else
+	    {
+	      tree parm_list = TREE_VEC_ELT (parameter_list, 0);
+	      tree parm = INNERMOST_TEMPLATE_PARMS (parm_list);
+	      if (TREE_TYPE (parm) != char_type_node
+		  || !TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (parm)))
+		ok = false;
+	    }
+	}
+      if (!ok)
+	error ("literal operator template %qD has invalid parameter list",
+	       decl);
+    }
   /* Register member declarations.  */
   if (member_p && !friend_p && decl && !DECL_CLASS_TEMPLATE_P (decl))
     finish_member_declaration (decl);
@@ -22605,7 +22966,8 @@
   /* If the next token is `extern' and the following token is a string
      literal, then we have a linkage specification.  */
   if (token->keyword == RID_EXTERN
-      && cp_parser_is_string_literal (cp_lexer_peek_nth_token (parser->lexer, 2)))
+      && cp_parser_is_pure_string_literal
+	 (cp_lexer_peek_nth_token (parser->lexer, 2)))
     cp_parser_linkage_specification (parser);
   /* Handle #pragma, if any.  */
   else if (token->type == CPP_PRAGMA)
Index: gcc/cp/cp-objcp-common.c
===================================================================
--- gcc/cp/cp-objcp-common.c	(revision 179317)
+++ gcc/cp/cp-objcp-common.c	(working copy)
@@ -100,6 +100,8 @@
 
     case TEMPLATE_INFO:         return sizeof (struct tree_template_info);
 
+    case USERDEF_LITERAL:	return sizeof (struct tree_userdef_literal);
+
     default:
       gcc_unreachable ();
     }
Index: gcc/cp/mangle.c
===================================================================
--- gcc/cp/mangle.c	(revision 179317)
+++ gcc/cp/mangle.c	(working copy)
@@ -181,6 +181,7 @@
 static void write_unqualified_name (const tree);
 static void write_conversion_operator_name (const tree);
 static void write_source_name (tree);
+static void write_literal_operator_name (tree);
 static void write_unnamed_type_name (const tree);
 static void write_closure_type_name (const tree);
 static int hwint_to_ascii (unsigned HOST_WIDE_INT, const unsigned int, char *,
@@ -1174,6 +1175,8 @@
 	  }
       write_string (mangled_name);
     }
+  else if (UDLIT_OPER_P (identifier))
+    write_literal_operator_name (identifier);
   else
     write_source_name (identifier);
 }
@@ -1227,6 +1230,8 @@
 
 	  write_string (oni[DECL_OVERLOADED_OPERATOR_P (decl)].mangled_name);
 	}
+      else if (UDLIT_OPER_P (DECL_NAME (decl)))
+	write_literal_operator_name (DECL_NAME (decl));
       else
 	found = false;
 
@@ -1286,6 +1291,21 @@
   write_identifier (IDENTIFIER_POINTER (identifier));
 }
 
+/* Write a user-defined literal operator.
+   IDENTIFIER is an LITERAL_IDENTIFIER_NODE.  */
+
+static void
+write_literal_operator_name (tree identifier)
+{
+  const char* suffix = UDLIT_OP_SUFFIX (identifier);
+  char* buffer = XNEWVEC (char, strlen (UDLIT_OP_MANGLED_PREFIX)
+			      + strlen (suffix) + 10);
+  sprintf (buffer, UDLIT_OP_MANGLED_FORMAT, suffix);
+
+  write_unsigned_number (strlen (buffer));
+  write_identifier (buffer);
+}
+
 /* Encode 0 as _, and 1+ as n-1_.  */
 
 static void
Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h	(revision 179317)
+++ gcc/cp/cp-tree.h	(working copy)
@@ -396,7 +396,9 @@
   /* override controls, override/final */
   CPP0X_OVERRIDE_CONTROLS,
   /* non-static data member initializers */
-  CPP0X_NSDMI
+  CPP0X_NSDMI,
+  /* user defined literals */
+  CPP0X_USER_DEFINED_LITERALS
 } cpp0x_warn_str;
   
 /* The various kinds of operation used by composite_pointer_type. */
@@ -727,6 +729,7 @@
   TS_CP_TRAIT_EXPR,
   TS_CP_LAMBDA_EXPR,
   TS_CP_TEMPLATE_INFO,
+  TS_CP_USERDEF_LITERAL,
   LAST_TS_CP_ENUM
 };
 
@@ -752,6 +755,8 @@
     lambda_expression;
   struct tree_template_info GTY ((tag ("TS_CP_TEMPLATE_INFO")))
     template_info;
+  struct tree_userdef_literal GTY ((tag ("TS_CP_USERDEF_LITERAL")))
+    userdef_literal;
 };
 
 \f
@@ -4204,6 +4209,17 @@
              LAMBDANAME_PREFIX, \
 	     sizeof (LAMBDANAME_PREFIX) - 1))
 
+#define UDLIT_OP_ANSI_PREFIX "operator\"\" "
+#define UDLIT_OP_ANSI_FORMAT UDLIT_OP_ANSI_PREFIX "%s"
+#define UDLIT_OP_MANGLED_PREFIX "li"
+#define UDLIT_OP_MANGLED_FORMAT UDLIT_OP_MANGLED_PREFIX "%s"
+#define UDLIT_OPER_P(ID_NODE) \
+  (!strncmp (IDENTIFIER_POINTER (ID_NODE), \
+             UDLIT_OP_ANSI_PREFIX, \
+	     sizeof (UDLIT_OP_ANSI_PREFIX) - 1))
+#define UDLIT_OP_SUFFIX(ID_NODE) \
+  (IDENTIFIER_POINTER (ID_NODE) + sizeof (UDLIT_OP_ANSI_PREFIX) - 1)
+
 #if !defined(NO_DOLLAR_IN_LABEL) || !defined(NO_DOT_IN_LABEL)
 
 #define VTABLE_NAME_P(ID_NODE) (IDENTIFIER_POINTER (ID_NODE)[1] == 'v' \
@@ -5728,6 +5744,8 @@
 extern int lvalue_or_else			(tree, enum lvalue_use,
                                                  tsubst_flags_t);
 extern void check_template_keyword		(tree);
+extern bool check_raw_literal_operator		(const_tree decl);
+extern bool check_literal_operator_args		(const_tree, bool *, bool *);
 
 /* in typeck2.c */
 extern void require_complete_eh_spec_types	(tree, tree);
Index: libcpp/include/cpplib.h
===================================================================
--- libcpp/include/cpplib.h	(revision 179317)
+++ libcpp/include/cpplib.h	(working copy)
@@ -131,6 +131,16 @@
   TK(OBJC_STRING,	LITERAL) /* @"string" - Objective-C */		\
   TK(HEADER_NAME,	LITERAL) /* <stdio.h> in #include */		\
 									\
+  TK(CHAR_USERDEF,	LITERAL) /* 'char'_suffix - C++-0x */		\
+  TK(WCHAR_USERDEF,	LITERAL) /* L'char'_suffix - C++-0x */		\
+  TK(CHAR16_USERDEF,	LITERAL) /* u'char'_suffix - C++-0x */		\
+  TK(CHAR32_USERDEF,	LITERAL) /* U'char'_suffix - C++-0x */		\
+  TK(STRING_USERDEF,	LITERAL) /* "string"_suffix - C++-0x */		\
+  TK(WSTRING_USERDEF,	LITERAL) /* L"string"_suffix - C++-0x */	\
+  TK(STRING16_USERDEF,	LITERAL) /* u"string"_suffix - C++-0x */	\
+  TK(STRING32_USERDEF,	LITERAL) /* U"string"_suffix - C++-0x */	\
+  TK(UTF8STRING_USERDEF,LITERAL) /* u8"string"_suffix - C++-0x */	\
+									\
   TK(COMMENT,		LITERAL) /* Only if output comments.  */	\
 				 /* SPELL_LITERAL happens to DTRT.  */	\
   TK(MACRO_ARG,		NONE)	 /* Macro argument.  */			\
@@ -402,6 +412,9 @@
   /* True for traditional preprocessing.  */
   unsigned char traditional;
 
+  /* Nonzero for the 2011 C++ Standard.  */
+  unsigned char cxx11;
+
   /* Holds the name of the target (execution) character set.  */
   const char *narrow_charset;
 
@@ -817,13 +830,22 @@
 #define CPP_N_FRACT	0x100000 /* Fract types.  */
 #define CPP_N_ACCUM	0x200000 /* Accum types.  */
 
+#define CPP_N_USERDEF	0x1000000 /* C++0x user-defined literal.  */
+
 /* Classify a CPP_NUMBER token.  The return value is a combination of
    the flags from the above sets.  */
-extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *);
+extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *,
+				     const char **);
 
+/* Return the classification flags for a float suffix.  */
+extern unsigned int cpp_interpret_float_suffix (const char *, size_t);
+
+/* Return the classification flags for an int suffix.  */
+extern unsigned int cpp_interpret_int_suffix (const char *, size_t);
+
 /* Evaluate a token classified as category CPP_N_INTEGER.  */
 extern cpp_num cpp_interpret_integer (cpp_reader *, const cpp_token *,
-				      unsigned int type);
+				      unsigned int);
 
 /* Sign extend a number, with PRECISION significant bits and all
    others assumed clear, to fill out a cpp_num structure.  */
@@ -993,4 +1015,20 @@
 extern void cpp_force_token_locations (cpp_reader *, source_location *);
 extern void cpp_stop_forcing_token_locations (cpp_reader *);
 
+/* In expr.c */
+extern enum cpp_ttype cpp_userdef_string_remove_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_string_add_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_char_remove_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_char_add_type
+  (enum cpp_ttype type);
+extern bool cpp_userdef_string_p
+  (enum cpp_ttype type);
+extern bool cpp_userdef_char_p
+  (enum cpp_ttype type);
+extern const char * cpp_get_userdef_suffix
+  (const cpp_token *);
+
 #endif /* ! LIBCPP_CPPLIB_H */
Index: libcpp/init.c
===================================================================
--- libcpp/init.c	(revision 179317)
+++ libcpp/init.c	(working copy)
@@ -80,22 +80,23 @@
   char digraphs;
   char uliterals;
   char rliterals;
+  char cxx11;
 };
 
 static const struct lang_flags lang_defaults[] =
-{ /*              c99 c++ xnum xid std  //   digr ulit rlit */
-  /* GNUC89   */  { 0,  0,  1,   0,  0,   1,   1,   0,   0 },
-  /* GNUC99   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1 },
-  /* GNUC1X   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1 },
-  /* STDC89   */  { 0,  0,  0,   0,  1,   0,   0,   0,   0 },
-  /* STDC94   */  { 0,  0,  0,   0,  1,   0,   1,   0,   0 },
-  /* STDC99   */  { 1,  0,  1,   0,  1,   1,   1,   0,   0 },
-  /* STDC1X   */  { 1,  0,  1,   0,  1,   1,   1,   1,   0 },
-  /* GNUCXX   */  { 0,  1,  1,   0,  0,   1,   1,   0,   0 },
-  /* CXX98    */  { 0,  1,  1,   0,  1,   1,   1,   0,   0 },
-  /* GNUCXX0X */  { 1,  1,  1,   0,  0,   1,   1,   1,   1 },
-  /* CXX0X    */  { 1,  1,  1,   0,  1,   1,   1,   1,   1 },
-  /* ASM      */  { 0,  0,  1,   0,  0,   1,   0,   0,   0 }
+{ /*              c99 c++ xnum xid std  //   digr ulit rlit cxx11 */
+  /* GNUC89   */  { 0,  0,  1,   0,  0,   1,   1,   0,   0,    0 },
+  /* GNUC99   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1,    0 },
+  /* GNUC1X   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1,    0 },
+  /* STDC89   */  { 0,  0,  0,   0,  1,   0,   0,   0,   0,    0 },
+  /* STDC94   */  { 0,  0,  0,   0,  1,   0,   1,   0,   0,    0 },
+  /* STDC99   */  { 1,  0,  1,   0,  1,   1,   1,   0,   0,    0 },
+  /* STDC1X   */  { 1,  0,  1,   0,  1,   1,   1,   1,   0,    0 },
+  /* GNUCXX   */  { 0,  1,  1,   0,  0,   1,   1,   0,   0,    0 },
+  /* CXX98    */  { 0,  1,  1,   0,  1,   1,   1,   0,   0,    0 },
+  /* GNUCXX0X */  { 1,  1,  1,   0,  0,   1,   1,   1,   1,    1 },
+  /* CXX0X    */  { 1,  1,  1,   0,  1,   1,   1,   1,   1,    1 },
+  /* ASM      */  { 0,  0,  1,   0,  0,   1,   0,   0,   0,    0 }
   /* xid should be 1 for GNUC99, STDC99, GNUCXX, CXX98, GNUCXX0X, and
      CXX0X when no longer experimental (when all uses of identifiers
      in the compiler have been audited for correct handling of
@@ -120,6 +121,7 @@
   CPP_OPTION (pfile, digraphs)			 = l->digraphs;
   CPP_OPTION (pfile, uliterals)			 = l->uliterals;
   CPP_OPTION (pfile, rliterals)			 = l->rliterals;
+  CPP_OPTION (pfile, cxx11)			 = l->cxx11;
 }
 
 /* Initialize library global state.  */
Index: libcpp/expr.c
===================================================================
--- libcpp/expr.c	(revision 179317)
+++ libcpp/expr.c	(working copy)
@@ -1,6 +1,6 @@
 /* Parse C expressions for cpplib.
    Copyright (C) 1987, 1992, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
-   2002, 2004, 2008, 2009, 2010 Free Software Foundation.
+   2002, 2004, 2008, 2009, 2010, 2011 Free Software Foundation.
    Contributed by Per Bothner, 1994.
 
 This program is free software; you can redistribute it and/or modify it
@@ -185,6 +185,13 @@
 	     q ? CPP_N_MD_Q : CPP_N_DEFAULT));
 }
 
+/* Return the classification flags for a float suffix.  */
+unsigned int
+cpp_interpret_float_suffix (const char *s, size_t len)
+{
+  return interpret_float_suffix ((const unsigned char *)s, len);
+}
+
 /* Subroutine of cpp_classify_number.  S points to an integer suffix
    of length LEN, possibly zero. Returns 0 for an invalid suffix, or a
    flag vector describing the suffix.  */
@@ -219,11 +226,143 @@
 	     : (l == 1) ? CPP_N_MEDIUM : CPP_N_LARGE));
 }
 
+/* Return the classification flags for an int suffix.  */
+unsigned int
+cpp_interpret_int_suffix (const char *s, size_t len)
+{
+  return interpret_int_suffix ((const unsigned char *)s, len);
+}
+
+/* Return the string type corresponding to the the input user-defined string
+   literal type.  If the input type is not a user-defined string literal
+   type return the input type.  */
+enum cpp_ttype
+cpp_userdef_string_remove_type (enum cpp_ttype type)
+{
+  if (type == CPP_STRING_USERDEF)
+    return CPP_STRING;
+  else if (type == CPP_WSTRING_USERDEF)
+    return CPP_WSTRING;
+  else if (type == CPP_STRING16_USERDEF)
+    return CPP_STRING16;
+  else if (type == CPP_STRING32_USERDEF)
+    return CPP_STRING32;
+  else if (type == CPP_UTF8STRING_USERDEF)
+    return CPP_UTF8STRING;
+  else
+    return type;
+}
+
+/* Return the user-defined string literal type corresponding to the input
+   string type.  If the input type is not a string type return the input
+   type.  */
+enum cpp_ttype
+cpp_userdef_string_add_type (enum cpp_ttype type)
+{
+  if (type == CPP_STRING)
+    return CPP_STRING_USERDEF;
+  else if (type == CPP_WSTRING)
+    return CPP_WSTRING_USERDEF;
+  else if (type == CPP_STRING16)
+    return CPP_STRING16_USERDEF;
+  else if (type == CPP_STRING32)
+    return CPP_STRING32_USERDEF;
+  else if (type == CPP_UTF8STRING)
+    return CPP_UTF8STRING_USERDEF;
+  else
+    return type;
+}
+
+/* Return the char type corresponding to the the input user-defined char
+   literal type.  If the input type is not a user-defined char literal
+   type return the input type.  */
+enum cpp_ttype
+cpp_userdef_char_remove_type (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR_USERDEF)
+    return CPP_CHAR;
+  else if (type == CPP_WCHAR_USERDEF)
+    return CPP_WCHAR;
+  else if (type == CPP_CHAR16_USERDEF)
+    return CPP_STRING16;
+  else if (type == CPP_CHAR32_USERDEF)
+    return CPP_STRING32;
+  else
+    return type;
+}
+
+/* Return the user-defined char literal type corresponding to the input
+   char type.  If the input type is not a char type return the input
+   type.  */
+enum cpp_ttype
+cpp_userdef_char_add_type (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR)
+    return CPP_CHAR_USERDEF;
+  else if (type == CPP_WCHAR)
+    return CPP_WCHAR_USERDEF;
+  else if (type == CPP_CHAR16)
+    return CPP_CHAR16_USERDEF;
+  else if (type == CPP_CHAR32)
+    return CPP_CHAR32_USERDEF;
+  else
+    return type;
+}
+
+/* Return true if the token type is a user-defined string literal.  */
+bool
+cpp_userdef_string_p (enum cpp_ttype type)
+{
+  if (type == CPP_STRING_USERDEF
+   || type == CPP_WSTRING_USERDEF
+   || type == CPP_STRING16_USERDEF
+   || type == CPP_STRING32_USERDEF
+   || type == CPP_UTF8STRING_USERDEF)
+    return true;
+  else
+    return false;
+}
+
+/* Return true if the token type is a user-defined char literal.  */
+bool
+cpp_userdef_char_p (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR_USERDEF
+   || type == CPP_WCHAR_USERDEF
+   || type == CPP_CHAR16_USERDEF
+   || type == CPP_CHAR32_USERDEF)
+    return true;
+  else
+    return false;
+}
+
+/* Extract the suffix from a user-defined literal string or char.  */
+const char *
+cpp_get_userdef_suffix (const cpp_token *tok)
+{
+  unsigned int len = tok->val.str.len;
+  const char *text = (const char *)tok->val.str.text;
+  char delim;
+  unsigned int i;
+  for (i = 0; i < len; ++i)
+    if (text[i] == '\'' || text[i] == '"')
+      break;
+  if (i == len)
+    return text + len;
+  delim = text[i];
+  for (i = len; i > 0; --i)
+    if (text[i - 1] == delim)
+      break;
+  return text + i;
+}
+
 /* Categorize numeric constants according to their field (integer,
    floating point, or invalid), radix (decimal, octal, hexadecimal),
-   and type suffixes.  */
+   and type suffixes.  In C++0X if UD_SUFFIX is non null it will be
+   assigned any unrecognized suffix for a user-defined literal.  */
 unsigned int
-cpp_classify_number (cpp_reader *pfile, const cpp_token *token)
+cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
+		     const char **ud_suffix)
 {
   const uchar *str = token->val.str.text;
   const uchar *limit;
@@ -231,6 +370,9 @@
   enum {NOT_FLOAT = 0, AFTER_POINT, AFTER_EXPON} float_flag;
   bool seen_digit;
 
+  if (ud_suffix)
+    *ud_suffix = NULL;
+
   /* If the lexer has done its job, length one can only be a single
      digit.  Fast-path this very common case.  */
   if (token->val.str.len == 1)
@@ -361,10 +503,19 @@
       result = interpret_float_suffix (str, limit - str);
       if (result == 0)
 	{
-	  cpp_error (pfile, CPP_DL_ERROR,
-		     "invalid suffix \"%.*s\" on floating constant",
-		     (int) (limit - str), str);
-	  return CPP_N_INVALID;
+	  if (CPP_OPTION (pfile, cxx11))
+	    {
+	      if (ud_suffix)
+		*ud_suffix = (const char *) str;
+	      result = CPP_N_LARGE | CPP_N_USERDEF;
+	    }
+	  else
+	    {
+	      cpp_error (pfile, CPP_DL_ERROR,
+			 "invalid suffix \"%.*s\" on floating constant",
+			 (int) (limit - str), str);
+	      return CPP_N_INVALID;
+	    }
 	}
 
       /* Traditional C didn't accept any floating suffixes.  */
@@ -406,10 +557,19 @@
       result = interpret_int_suffix (str, limit - str);
       if (result == 0)
 	{
-	  cpp_error (pfile, CPP_DL_ERROR,
-		     "invalid suffix \"%.*s\" on integer constant",
-		     (int) (limit - str), str);
-	  return CPP_N_INVALID;
+	  if (CPP_OPTION (pfile, cxx11))
+	    {
+	      if (ud_suffix)
+		*ud_suffix = (const char *) str;
+	      result = CPP_N_UNSIGNED | CPP_N_LARGE | CPP_N_USERDEF;
+	    }
+	  else
+	    {
+	      cpp_error (pfile, CPP_DL_ERROR,
+			 "invalid suffix \"%.*s\" on integer constant",
+			 (int) (limit - str), str);
+	      return CPP_N_INVALID;
+	    }
 	}
 
       /* Traditional C only accepted the 'L' suffix.
@@ -748,7 +908,7 @@
   switch (token->type)
     {
     case CPP_NUMBER:
-      temp = cpp_classify_number (pfile, token);
+      temp = cpp_classify_number (pfile, token, NULL);
       switch (temp & CPP_N_CATEGORY)
 	{
 	case CPP_N_FLOATING:
Index: libcpp/lex.c
===================================================================
--- libcpp/lex.c	(revision 179317)
+++ libcpp/lex.c	(working copy)
@@ -1478,6 +1478,18 @@
     }
  break_outer_loop:
 
+  if (CPP_OPTION (pfile, cxx11))
+    {
+      /* Grab user defined literal suffix.  */
+      if (ISIDST(*cur))
+	{
+	  type = cpp_userdef_string_add_type (type);
+	  ++cur;
+	}
+      while (ISIDNUM(*cur))
+	++cur;
+    }
+
   pfile->buffer->cur = cur;
   if (first_buff == NULL)
     create_literal (pfile, token, base, cur - base, type);
@@ -1581,6 +1593,19 @@
     cpp_error (pfile, CPP_DL_PEDWARN, "missing terminating %c character",
 	       (int) terminator);
 
+  if (CPP_OPTION (pfile, cxx11))
+    {
+      /* Grab user defined literal suffix.  */
+      if (ISIDST(*cur))
+	{
+	  type = cpp_userdef_char_add_type (type);
+	  type = cpp_userdef_string_add_type (type);
+          ++cur;
+	}
+      while (ISIDNUM(*cur))
+	++cur;
+    }
+
   pfile->buffer->cur = cur;
   create_literal (pfile, token, base, cur - base, type);
 }

[-- Attachment #3: CL_udlit --]
[-- Type: application/octet-stream, Size: 3851 bytes --]

2011-10-12  Ed Smith-Rowland  <3dw4rd@verizon.net>

	Implement C++11 user-defined literals.
	* gcc/c-family/c-common.c (build_userdef_literal): New.
	* gcc/c-family/c-common.def: New tree code.
	* gcc/c-family/c-common.h (tree_userdef_literal): New tree
	struct and accessors.
	* gcc/c-family/c-lex.c (interpret_integer, interpret_float):
	Return suffixes.(c_lex_with_flags): Build literal tokens.
	* gcc/cp/cp-objcp-common.c: 
	* gcc/cp/cp-tree.h: (UDLIT_OP_*, UDLIT_OPER_P): Literal operator
	name tools. New tree code for user-defined literals.
	* gcc/cp/cxx-pretty-print.h: (pp_cxx_userdef_literal) New.
	* gcc/cp/cxx-pretty-print.c: (pp_cxx_userdef_literal) New.
	(pp_cxx_primary_expression, pp_cxx_expression): Use it.
	* gcc/cp/decl.c: (cp_tree_node_structure): Return new tree code.
	(duplicate_decls): Check for raw vs. template operator conflicts.
	(grokfndecl, grokdeclarator): New checks for literal operators.
	* gcc/cp/error.c: (dump_expr): Warn about user-defined literals
	in C++98 mode. (dump_function_name): Pretty printing.
	* gcc/cp/mangle.c: (write_literal_operator_name): New.
	(write_unqualified_id, write_unqualified_name): Use it.
	* gcc/cp/parser.c: (cp_parser_operator): Handle operator"".
	(cp_parser_userdef_char_literal, cp_parser_userdef_numeric_literal,
	cp_parser_userdef_string_literal): New.
	(cp_parser_primary_expression): Handle new user-defined literal tokens
	with new functions.
	* gcc/cp/semantics.c: (potential_constant_expression_1): Add
	user-defined literals.
	* gcc/cp/typeck.c (check_raw_literal_operator,
	check_literal_operator_args): New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-addr.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-args.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-concat.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-declare-neg.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-friend.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-general.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-inline.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-nospace-neg.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-template.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C: New.
	* gcc/testsuite/g++.dg/cpp0x/udlit_system_header: New.
	* libcpp/expr.c: (cpp_interpret_float_suffix, cpp_interpret_int_suffix,
	cpp_userdef_string_remove_type, cpp_userdef_string_add_type,
	cpp_userdef_char_remove_type, cpp_userdef_char_add_type,
	cpp_userdef_string_p, cpp_userdef_char_p, cpp_get_userdef_suffix): New.
	(cpp_classify_number): Classify unrecognized tokens as user-defined literals.
	* libcpp/include/cpplib.h: Add new tokens.
	* libcpp/init.c: Add new preprocessor flag (cxx11).
	* libcpp/lex.c: (lex_string, lex_raw_string): Handle user-defined literals
	including concatenation and promotion with suffixes.


^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-12 21:12 Re: [C++-11] User defined literals 3dw4rd
@ 2011-10-15 23:13 ` Jason Merrill
  2011-10-16  7:59 ` Jason Merrill
  1 sibling, 0 replies; 36+ messages in thread
From: Jason Merrill @ 2011-10-15 23:13 UTC (permalink / raw)
  To: 3dw4rd; +Cc: gcc-patches

On 10/12/2011 04:58 PM, 3dw4rd@verizon.net wrote:
> +  const char *text = (const char *)tok->val.str.text;
> +  char delim;
> +  unsigned int i;
> +  for (i = 0; i < len; ++i)
> +    if (text[i] == '\'' || text[i] == '"')
> +      break;

This seems like it will get confused by embedded ' or \" in the string 
itself.

Jason

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-12 21:12 Re: [C++-11] User defined literals 3dw4rd
  2011-10-15 23:13 ` Jason Merrill
@ 2011-10-16  7:59 ` Jason Merrill
  2011-10-21 14:56   ` Ed Smith-Rowland
  1 sibling, 1 reply; 36+ messages in thread
From: Jason Merrill @ 2011-10-16  7:59 UTC (permalink / raw)
  To: 3dw4rd; +Cc: gcc-patches

On 10/12/2011 04:58 PM, 3dw4rd@verizon.net wrote:
> +  tree const_char_ptr_type_node
> +       = build_pointer_type (build_type_variant (char_type_node, 1, 0));

You can just use const_string_type_node here.

Jason

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-16  7:59 ` Jason Merrill
@ 2011-10-21 14:56   ` Ed Smith-Rowland
  2011-10-21 21:20     ` Tom Tromey
  0 siblings, 1 reply; 36+ messages in thread
From: Ed Smith-Rowland @ 2011-10-21 14:56 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 866 bytes --]

On 10/15/2011 04:42 PM, Jason Merrill wrote:
> On 10/12/2011 04:58 PM, 3dw4rd@verizon.net wrote:
>> +  tree const_char_ptr_type_node
>> +       = build_pointer_type (build_type_variant (char_type_node, 1, 
>> 0));
>
> You can just use const_string_type_node here.
>
> Jason
>
I made this change.

I also added a test case to make sure that embedded quotes are not a 
problem.
No valid string can begin or end with an escaped quote.  So the string 
delimiter is found by loking for the first quote in the string.
The suffix is found by looking for that same quote from the end of the 
string.

While looking at the embedded string issue I found that if you apply the 
suffix of a raw literal to a string it errors as it should but the error 
complained that there were too many arguments for the function.  This 
was not helpful so I made a nicer error message.

Ed


[-- Attachment #2: patch30 --]
[-- Type: text/plain, Size: 76539 bytes --]

Index: gcc/c-family/c-lex.c
===================================================================
--- gcc/c-family/c-lex.c	(revision 180284)
+++ gcc/c-family/c-lex.c	(working copy)
@@ -44,8 +44,8 @@
 int pending_lang_change; /* If we need to switch languages - C++ only */
 int c_header_level;	 /* depth in C headers - C++ only */
 
-static tree interpret_integer (const cpp_token *, unsigned int);
-static tree interpret_float (const cpp_token *, unsigned int);
+static tree interpret_integer (const cpp_token *, unsigned int, const char *);
+static tree interpret_float (const cpp_token *, unsigned int, const char *);
 static tree interpret_fixed (const cpp_token *, unsigned int);
 static enum integer_type_kind narrowest_unsigned_type
 	(unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned int);
@@ -314,7 +314,8 @@
 
     case CPP_NUMBER:
       {
-	unsigned int flags = cpp_classify_number (parse_in, tok);
+	const char *suffix = NULL;
+	unsigned int flags = cpp_classify_number (parse_in, tok, &suffix);
 
 	switch (flags & CPP_N_CATEGORY)
 	  {
@@ -328,16 +329,27 @@
 	       Set PURE_ZERO to pass this information to the C++ parser.  */
 	    if (tok->val.str.len == 1 && *tok->val.str.text == '0')
 	      add_flags = PURE_ZERO;
-	    *value = interpret_integer (tok, flags);
+	    *value = interpret_integer (tok, flags, suffix);
 	    break;
 
 	  case CPP_N_FLOATING:
-	    *value = interpret_float (tok, flags);
+	    *value = interpret_float (tok, flags, suffix);
 	    break;
 
 	  default:
 	    gcc_unreachable ();
 	  }
+
+	if (flags & CPP_N_USERDEF)
+	  {
+	    tree num_string = build_string (tok->val.str.len - strlen (suffix),
+					    (const char *) tok->val.str.text);
+	    TREE_TYPE (num_string) = char_array_type_node;
+	    num_string = fix_string_type (num_string);
+	    tree literal = build_userdef_literal (get_identifier (suffix),
+						  *value, num_string);
+	    *value = literal;
+	  }
       }
       break;
 
@@ -415,6 +427,22 @@
       }
       goto retry;
 
+    case CPP_CHAR_USERDEF:
+    case CPP_WCHAR_USERDEF:
+    case CPP_CHAR16_USERDEF:
+    case CPP_CHAR32_USERDEF:
+      {
+	tree literal;
+	cpp_token temp_tok = *tok;
+	const char *suffix = cpp_get_userdef_suffix (tok);
+	temp_tok.val.str.len -= strlen (suffix);
+	temp_tok.type = cpp_userdef_char_remove_type (type);
+	literal = build_userdef_literal (get_identifier (suffix),
+					 lex_charconst (&temp_tok), NULL_TREE);
+	*value = literal;
+      }
+      break;
+
     case CPP_CHAR:
     case CPP_WCHAR:
     case CPP_CHAR16:
@@ -422,6 +450,22 @@
       *value = lex_charconst (tok);
       break;
 
+    case CPP_STRING_USERDEF:
+    case CPP_WSTRING_USERDEF:
+    case CPP_STRING16_USERDEF:
+    case CPP_STRING32_USERDEF:
+    case CPP_UTF8STRING_USERDEF:
+      {
+	tree literal, string;
+	const char *suffix = cpp_get_userdef_suffix (tok);
+	string = build_string (tok->val.str.len - strlen (suffix),
+			       (const char *) tok->val.str.text);
+	literal = build_userdef_literal (get_identifier (suffix),
+					 string, NULL_TREE);
+	*value = literal;
+      }
+      break;
+
     case CPP_STRING:
     case CPP_WSTRING:
     case CPP_STRING16:
@@ -536,9 +580,11 @@
   return itk_none;
 }
 
-/* Interpret TOKEN, an integer with FLAGS as classified by cpplib.  */
+/* Interpret TOKEN, an integer with FLAGS as classified by cpplib.
+   For C++0X SUFFIX may contain a user-defined literal suffix.  */
 static tree
-interpret_integer (const cpp_token *token, unsigned int flags)
+interpret_integer (const cpp_token *token, unsigned int flags,
+		   const char *suffix)
 {
   tree value, type;
   enum integer_type_kind itk;
@@ -621,9 +667,10 @@
 }
 
 /* Interpret TOKEN, a floating point number with FLAGS as classified
-   by cpplib.  */
+   by cpplib.  For C++0X SUFFIX may contain a user-defined literal suffix.  */
 static tree
-interpret_float (const cpp_token *token, unsigned int flags)
+interpret_float (const cpp_token *token, unsigned int flags,
+		 const char *suffix)
 {
   tree type;
   tree const_type;
@@ -702,7 +749,9 @@
      has any suffixes, cut them off; REAL_VALUE_ATOF/ REAL_VALUE_HTOF
      can't handle them.  */
   copylen = token->val.str.len;
-  if (flags & CPP_N_DFLOAT)
+  if (flags & CPP_N_USERDEF)
+    copylen -= strlen (suffix);
+  else if (flags & CPP_N_DFLOAT)
     copylen -= 2;
   else
     {
Index: gcc/c-family/c-common.c
===================================================================
--- gcc/c-family/c-common.c	(revision 180284)
+++ gcc/c-family/c-common.c	(working copy)
@@ -9923,4 +9923,17 @@
   MARK_TS_TYPED (EXCESS_PRECISION_EXPR);
 }
 
+/* Build a user-defined numeric literal out of an integer constant type VALUE
+   with identifier SUFFIX.  */
+
+tree
+build_userdef_literal (tree suffix_id, tree value, tree num_string)
+{
+  tree literal = make_node (USERDEF_LITERAL);
+  USERDEF_LITERAL_SUFFIX_ID (literal) = suffix_id;
+  USERDEF_LITERAL_VALUE (literal) = value;
+  USERDEF_LITERAL_NUM_STRING (literal) = num_string;
+  return literal;
+}
+
 #include "gt-c-family-c-common.h"
Index: gcc/c-family/c-common.h
===================================================================
--- gcc/c-family/c-common.h	(revision 180284)
+++ gcc/c-family/c-common.h	(working copy)
@@ -1067,4 +1067,27 @@
   return NULL;
 }
 
+/* A suffix-identifier value doublet that represents user-defined literals
+   for C++-0x.  */
+struct GTY(()) tree_userdef_literal {
+  struct tree_base base;
+  tree suffix_id;
+  tree value;
+  tree num_string;
+};
+
+#define USERDEF_LITERAL_SUFFIX_ID(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->suffix_id)
+
+#define USERDEF_LITERAL_VALUE(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->value)
+
+#define USERDEF_LITERAL_NUM_STRING(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->num_string)
+
+#define USERDEF_LITERAL_TYPE(NODE) \
+  (TREE_TYPE (USERDEF_LITERAL_VALUE (NODE)))
+
+extern tree build_userdef_literal (tree suffix_id, tree value, tree num_string);
+
 #endif /* ! GCC_C_COMMON_H */
Index: gcc/c-family/c-common.def
===================================================================
--- gcc/c-family/c-common.def	(revision 180284)
+++ gcc/c-family/c-common.def	(working copy)
@@ -47,6 +47,12 @@
    evaluated.  */
 DEFTREECODE (EXCESS_PRECISION_EXPR, "excess_precision_expr", tcc_expression, 1)
 
+/* Used to represent a user-defined literal.
+   The operands are an IDENTIFIER for the suffix, the VALUE of the literal,
+   and for numeric literals the original string representation of the
+   number.  */
+DEFTREECODE (USERDEF_LITERAL, "userdef_literal", tcc_exceptional, 3)
+
 /*
 Local variables:
 mode:c
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C	(revision 0)
@@ -0,0 +1,4 @@
+// { dg-options -std=c++0x }
+
+template<char...>
+  int operator"" _xyz(unsigned long long);	// { dg-error "has invalid argument list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit_system_header
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit_system_header	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit_system_header	(revision 0)
@@ -0,0 +1,6 @@
+
+#pragma GCC system_header
+
+char
+operator"" stdsuffix(char __c)
+{ return __c/2; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C	(revision 0)
@@ -0,0 +1,42 @@
+// { dg-options "-std=c++0x" }
+
+//  Can't have *both* literal operator template and raw literal operator.
+
+int
+operator"" _abc(const char*)
+  {
+    return 42;
+  }
+
+template<char...>
+  int
+  operator"" _abc() // { dg-error "literal operator template|conflicts with raw literal operator" }
+  {
+    return 13;
+  }
+
+template<char...>
+  int
+  operator"" _def()
+  {
+    return 12;
+  }
+
+int
+operator"" _def(const char*) // { dg-error "raw literal operator|conflicts with literal operator template" }
+  {
+    return 43;
+  }
+
+int
+operator"" _ghi(long double)
+  {
+    return 42;
+  }
+
+template<char...>
+  int
+  operator"" _ghi() // OK
+  {
+    return 13;
+  }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C	(revision 0)
@@ -0,0 +1,43 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test simple operator declaration and definition in namespaces.
+
+#include <cmath>
+#include <limits>
+
+namespace Long
+{
+  long double operator"" _LL(long double);
+}
+
+namespace Short
+{
+  short
+  operator"" _SS(long double x)
+  { return std::fmod(x, static_cast<long double>(std::numeric_limits<short>::max())); }
+}
+
+void
+test1()
+{
+  long double x = Long::operator "" _LL(1.2L);
+
+  using namespace Short;
+  short s = operator"" _SS(1.2L);
+  short s2 = 1.2_SS;
+}
+
+int
+main()
+{
+  test1();
+}
+
+namespace Long
+{
+  long double
+  operator"" _LL(long double x)
+  { return x + 2.0L; }
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-raw-op-string-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-raw-op-string-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-raw-op-string-neg.C	(revision 0)
@@ -0,0 +1,8 @@
+// { dg-options "-std=c++0x" }
+
+//  Make sure handing a string to a raw literal generates a sensible error message.
+
+int operator"" _embedraw(const char*)
+{ return 41; };
+
+int k = "Boo!"_embedraw;  //  { dg-error "invalid string literal prefix|for user-defined raw literal operator" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-embed-quote.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-embed-quote.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-embed-quote.C	(revision 0)
@@ -0,0 +1,34 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+//  Make sure embedded quotes are not a problem for string and char literals.
+
+#include <cstdint>
+#include <cassert>
+
+int operator"" _embedchar(char)
+{ return 41; };
+
+int operator"" _embedstr(const char*, std::size_t len)
+{ return 42 + len; };
+
+void
+test()
+{
+  int i = '\''_embedchar;
+
+  int j = "\""_embedstr;
+  assert(j == 43);
+
+  int k = "foo\""_embedstr;
+  assert(k == 46);
+
+  int l = "\"bar"_embedstr;
+  assert(l == 46);
+}
+
+int
+main()
+{
+  test();
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C	(revision 0)
@@ -0,0 +1,15 @@
+// { dg-options -std=c++0x }
+
+class Foo
+{
+public:
+  Foo() { }
+  int operator"" _Bar(char32_t);  // { dg-error "must be a non-member function" }
+};
+
+int i = operator"" _Bar(U'x');  // { dg-error "was not declared in this scope" }
+int j = U'x'_Bar;  // { dg-error "unable to find user-defined character literal operator" }
+
+int
+Foo::operator"" _Bar(char32_t)  // { dg-error "must be a non-member function" }
+{ return 42; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C	(revision 0)
@@ -0,0 +1,38 @@
+// { dg-options -std=c++0x }
+
+#include <cstddef>
+
+class Foo { };
+
+Foo
+operator"" _Foo(int *);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(unsigned long int);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(double);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const float *, std::size_t);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const wchar_t *, int);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const char16_t *);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(char...);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(unsigned long long int, char);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const char *, std::size_t, int);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(long double &);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(std::size_t, const char16_t *);	// { dg-error "has invalid argument list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C	(revision 0)
@@ -0,0 +1,17 @@
+// { dg-options "-std=c++98" }
+
+#include <cstddef>
+
+int
+operator"" _mm(long double m)	// { dg-warning "user-defined literals only available with" }
+{ return int(1000.0L * m); }
+
+int in = 0.0254_mm;	// { dg-error "invalid suffix" }
+
+int
+operator"" _Q(const char *, std::size_t)	// { dg-warning "user-defined literals only available with" }
+{ return 42; }
+
+int x = "Hello"_Q;	// { dg-error "invalid conversion from" }
+
+// { dg-error "expected" "" { target *-*-* } 15 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C	(revision 0)
@@ -0,0 +1,5 @@
+// { dg-options -std=c++0x }
+
+#include <string>
+
+std::string operator"" 5X(const char*, std::size_t);	// { dg-error "expected suffix identifier" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+constexpr unsigned long long
+operator"" _grow(unsigned long long n)
+{ return 2 * n; }
+
+double buffer[25_grow];
Index: gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C	(revision 0)
@@ -0,0 +1,49 @@
+// { dg-options -std=c++0x }
+
+//  Test that the standard suffixes shadow any user-defined suffixes of the same name.
+long double
+operator"" L(long double x)  // { dg-warning "floating point suffix|shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ULL(unsigned long long int k)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return k; }
+
+long double
+operator"" l(long double x)  // { dg-warning "floating point suffix|shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ull(unsigned long long int k)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return k; }
+
+//  Namespaces are no hiding place.
+namespace Long
+{
+
+long double
+operator"" L(long double x)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ULL(unsigned long long int k)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return k; }
+
+long double
+operator"" l(long double x)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ull(unsigned long long int k)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return k; }
+
+}
+
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 5 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 9 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 13 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 17 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 25 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 29 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 33 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 37 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test warning on declaration without leading underscore.
+
+long double operator"" nounder(long double); // { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" }
+
+template<char...>
+  int operator"" nounder(); // { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C	(revision 0)
@@ -0,0 +1,12 @@
+// { dg-options -std=c++0x }
+
+class Foo { };
+
+template<wchar_t...>
+  Foo operator"" _Foo(); // { dg-error "literal operator template|has invalid parameter list" }
+
+template<char>
+  Foo operator"" _Bar(); // { dg-error "literal operator template|has invalid parameter list" }
+
+template<typename... Type>
+  Foo operator"" _Bar(); // { dg-error "literal operator template|has invalid parameter list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-general.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-general.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-general.C	(revision 0)
@@ -0,0 +1,52 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test simple operator declaration and definition.
+
+#include <cstring>
+#include <string>
+#include <complex>
+#include <cassert>
+
+long double operator"" _v(long double);
+std::string operator"" _w(const char16_t*, size_t);
+unsigned operator"" _w(const char*);
+
+std::complex<double>
+operator"" _i(long double y)
+{ return std::complex<double>(0.0L, y); }
+
+void
+test1()
+{
+  long double x = operator"" _v(1.2L);
+  assert(x == 2.2L);
+
+  std::string s = operator"" _w(u"one", 3);
+  assert(s == "boo");
+
+  unsigned u = operator"" _w("Hello, World!");
+  assert(u == 13U);
+
+  std::complex<double> i = operator"" _i(2.0);
+  assert(i == std::complex<double>(0.0, 2.0));
+}
+
+int
+main()
+{
+  test1();
+}
+
+long double
+operator"" _v(long double x)
+{ return x + 1.0L; }
+
+std::string
+operator"" _w(const char16_t*, size_t)
+{ return std::string("boo"); }
+
+unsigned
+operator"" _w(const char* str)
+{ return strlen(str); }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C	(revision 0)
@@ -0,0 +1,3 @@
+// { dg-options -std=c++0x }
+
+#include "udlit_system_header"
Index: gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C	(revision 0)
@@ -0,0 +1,15 @@
+// { dg-options -std=c++0x }
+
+#include <string>
+
+std::string operator"" _i18n(const char*, std::size_t);
+
+std::string vogon_poem = R"V0G0N(
+                O freddled gruntbuggly thy micturations are to me
+                    As plured gabbleblochits on a lurgid bee.
+                 Groop, I implore thee my foonting turlingdromes.   
+              And hooptiously drangle me with crinkly bindlewurdles,
+  Or I will rend thee in the gobberwarts with my blurlecruncheon, see if I don't.
+
+                    (by Prostetnic Vogon Jeltz; see p. 56/57)
+)V0G0N"_i18n;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test error on non-function declaration.
+
+double operator"" _baddecl; // { dg-error "as non-function" }
+
+template<char...>
+  int operator"" _badtmpldecl; // { dg-error "as non-function" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-addr.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-addr.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-addr.C	(revision 0)
@@ -0,0 +1,10 @@
+// { dg-options "-std=c++0x" }
+
+#include <cstddef>
+
+bool operator"" _yn(const char*, size_t);
+
+typedef bool (*pfunk)(const char*, size_t);
+pfunk p = &operator"" _yn;
+
+bool tf = p("Hello,\0 World!", 14);
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C	(revision 0)
@@ -0,0 +1,4 @@
+// { dg-options -std=c++0x }
+
+template<char...>
+  int operator"" _abc();
Index: gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C	(revision 0)
@@ -0,0 +1,8 @@
+// { dg-options -std=c++0x }
+
+extern "C" {
+
+int
+operator"" _badclinkage(unsigned long long);	// { dg-error "operator with C linkage" }
+
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-template.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-template.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-template.C	(revision 0)
@@ -0,0 +1,51 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test template operator declaration and definition.
+
+#include <cassert>
+
+template<char...>
+  int operator"" _abc();
+
+template<>
+  int
+  operator"" _abc<>()
+  { return -1; }
+
+template<>
+  int
+  operator"" _abc<'L','U','E'>()
+  { return 42; }
+
+template<>
+  int
+  operator"" _abc<'6','6','6'>()
+  { return 21; }
+
+int
+test1()
+{
+  int i = operator"" _abc<'1','2','3'>();
+  assert(i == 45);
+  int universal_meaning = operator"" _abc<'L','U','E'>();
+  assert(universal_meaning == 42);
+  int b = operator"" _abc<'6','6','6'>();
+  int z = operator"" _abc<>();
+  assert(z == -1);
+  int j = 123_abc;
+  assert(j == i);
+  int jb = 666_abc;
+  assert(jb == b);
+}
+
+int
+main()
+{
+  test1();
+}
+
+template<char... Chars>
+  int operator"" _abc()
+  { return 42 + sizeof...(Chars); }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-args.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-args.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-args.C	(revision 0)
@@ -0,0 +1,38 @@
+// { dg-options -std=c++0x }
+
+#include <cstddef>
+
+class Foo { };
+
+Foo
+operator"" _Foo(const char *);
+
+Foo
+operator"" _Foo(unsigned long long int);
+
+Foo
+operator"" _Foo(long double);
+
+Foo
+operator"" _Foo(char);
+
+Foo
+operator"" _Foo(wchar_t);
+
+Foo
+operator"" _Foo(char16_t);
+
+Foo
+operator"" _Foo(char32_t);
+
+Foo
+operator"" _Foo(const char *, std::size_t);
+
+Foo
+operator"" _Foo(const wchar_t *, std::size_t);
+
+Foo
+operator"" _Foo(const char16_t *, std::size_t);
+
+Foo
+operator"" _Foo(const char32_t *, std::size_t);
Index: gcc/testsuite/g++.dg/cpp0x/udlit-declare-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-declare-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-declare-neg.C	(revision 0)
@@ -0,0 +1,15 @@
+// { dg-options "-std=c++0x" }
+
+//  Check that undeclared literal operator calls and literals give appropriate errors.
+
+int i = operator"" _Bar('x');  // { dg-error "was not declared in this scope" }
+int j = 'x'_Bar;  // { dg-error "unable to find user-defined character literal operator" }
+
+int ii = operator"" _BarCharStr("Howdy, Pardner!");  // { dg-error "was not declared in this scope" }
+int jj = "Howdy, Pardner!"_BarCharStr;  // { dg-error "unable to find user-defined string literal operator" }
+
+unsigned long long iULL = operator"" _BarULL(666ULL);  // { dg-error "was not declared in this scope" }
+unsigned long long jULL = 666_BarULL;  // { dg-error "unable to find user-defined numeric literal operator" }
+
+long double iLD = operator"" _BarLD(666.0L);  // { dg-error "was not declared in this scope" }
+long double jLD = 666.0_BarLD;  // { dg-error "unable to find user-defined numeric literal operator" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C	(revision 0)
@@ -0,0 +1,5 @@
+// { dg-options -std=c++0x }
+
+char32_t
+operator"" (char32_t C)	// { dg-error "expected suffix identifier" }
+{ return C; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test error on non-empty string after 'operator' keyword.
+
+double operator"hi" _badword(long double); // { dg-error "expected empty string after" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nospace-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nospace-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nospace-neg.C	(revision 0)
@@ -0,0 +1,3 @@
+// { dg-options "-std=c++0x" }
+
+float operator ""_abc(const char*); // { dg-error "missing space between|and suffix identifier" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-inline.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-inline.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-inline.C	(revision 0)
@@ -0,0 +1,22 @@
+// { dg-options "-std=c++0x" }
+
+//  Literal operators can be inline.
+
+inline int
+operator"" _thing1(char cc)
+{ return 42 * cc; }
+
+int operator"" _thing2(char cc);
+
+class Foo
+{
+  int
+  friend operator"" _thing2(char cc)
+  { return 42 * cc; }
+};
+
+int i = operator"" _thing1('x');
+int j = 'x'_thing1;
+
+int iF = operator"" _thing2('x');
+int jF = 'x'_thing2;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+extern "C"_badlinkage {	// { dg-error "expected unqualified-id before" }
+
+int foo();
+
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-friend.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-friend.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-friend.C	(revision 0)
@@ -0,0 +1,28 @@
+// { dg-options -std=c++0x }
+
+long double
+operator"" _Hertz(long double);
+
+class Foo
+{
+public:
+  Foo() { }
+
+  friend Foo operator"" _Bar(char);
+
+  friend long double
+  operator"" _Hertz(long double omega)
+  { return omega / 6.28318530717958648; }
+};
+
+Foo
+operator"" _Bar(char)
+{ return Foo(); }
+
+Foo f1 = operator"" _Bar('x');
+
+Foo f2 = 'x'_Bar;
+
+long double fm1 = operator"" _Hertz(552.92L);
+
+long double fm2 = 552.92_Hertz;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+#include <string>
+
+std::string operator"" _xxx(const char*, size_t);
+
+std::string operator"" _yyy(const char*, size_t);
+
+std::string concat = "Hello, "_xxx "World!"_yyy;	// { dg-error "inconsistent user-defined literal suffixes" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options -std=c++0x }
+
+class Foo { };
+
+template<char...>
+  Foo operator"" _Foo();
Index: gcc/testsuite/g++.dg/cpp0x/udlit-concat.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-concat.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-concat.C	(revision 0)
@@ -0,0 +1,24 @@
+// { dg-options "-std=c++0x" }
+
+#include <string>
+
+std::string operator"" _www(const char*, size_t);
+
+std::string concat01 = "Hello, " "World!"_www;
+
+std::string concat10 = "Hello, "_www "World!";
+
+std::string concat11 = "Hello, "_www "World!"_www;
+
+
+class Tachyon { };
+
+Tachyon operator"" _fast(const char*, size_t);
+
+int operator"" _fast(const char32_t*, size_t);
+
+int speedy01 = "Hello, " U"World!"_fast;
+
+int speedy10 = "Hello, "_fast U"World!";
+
+int speedy11 = "Hello, "_fast U"World!"_fast;
Index: gcc/cp/typeck.c
===================================================================
--- gcc/cp/typeck.c	(revision 180284)
+++ gcc/cp/typeck.c	(working copy)
@@ -8352,3 +8352,122 @@
   return 1;
 }
 
+
+/* Return true if a user-defined literal operator is a raw operator.  */
+
+bool
+check_raw_literal_operator (const_tree decl)
+{
+  tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
+  tree argtype;
+  int arity;
+  bool maybe_raw_p = false;
+
+  /* Count the number and type of arguments and check for ellipsis.  */
+  for (argtype = argtypes, arity = 0;
+       argtype && argtype != void_list_node;
+       ++arity, argtype = TREE_CHAIN (argtype))
+    {
+      tree t = TREE_VALUE (argtype);
+
+      if (same_type_p (t, const_string_type_node))
+	maybe_raw_p = true;
+    }
+  if (!argtype)
+    return false; /* Found ellipsis.  */
+
+  if (!maybe_raw_p || arity != 1)
+    return false;
+
+  return true;
+}
+
+
+/* Return true if a user-defined literal operator has one of the allowed
+   argument types.  */
+
+bool
+check_literal_operator_args (const_tree decl,
+			     bool *long_long_unsigned_p, bool *long_double_p)
+{
+  tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
+  if (processing_template_decl)
+    return (argtypes == NULL_TREE
+	    || same_type_p (TREE_VALUE (argtypes), void_type_node));
+  else
+    {
+      tree argtype;
+      int arity;
+      int max_arity = 2;
+      bool found_string_p = false;
+      bool maybe_raw_p = false;
+      bool found_size_p = false;
+      tree const_wchar_ptr_type_node
+	   = build_pointer_type (build_type_variant (wchar_type_node, 1, 0));
+      tree const_char16_ptr_type_node
+	   = build_pointer_type (build_type_variant (char16_type_node, 1, 0));
+      tree const_char32_ptr_type_node
+	   = build_pointer_type (build_type_variant (char32_type_node, 1, 0));
+
+      *long_long_unsigned_p = false;
+      *long_double_p = false;
+
+      /* Count the number and type of arguments and check for ellipsis.  */
+      for (argtype = argtypes, arity = 0;
+	   argtype && argtype != void_list_node;
+	   argtype = TREE_CHAIN (argtype))
+	{
+	  tree t = TREE_VALUE (argtype);
+	  ++arity;
+
+	  if (same_type_p (t, const_string_type_node))
+	    {
+	      found_string_p = true;
+	      maybe_raw_p = true;
+	    }
+	  else if (same_type_p (t, const_wchar_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, const_char16_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, const_char32_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, size_type_node))
+	    {
+	      if (!found_string_p)
+		return false;
+	      found_size_p = true;
+	    }
+	  else if (same_type_p (t, long_long_unsigned_type_node))
+	    {
+	      max_arity = 1;
+	      *long_long_unsigned_p = true;
+	    }
+	  else if (same_type_p (t, long_double_type_node))
+	    {
+	      max_arity = 1;
+	      *long_double_p = true;
+	    }
+	  else if (same_type_p (t, char_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, wchar_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, char16_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, char32_type_node))
+	    max_arity = 1;
+	  else
+	    return false;
+	}
+      if (!argtype)
+	return false; /* Found ellipsis.  */
+
+      if (arity > max_arity)
+	return false;
+
+      if (found_string_p && !maybe_raw_p && !found_size_p)
+	return false;
+
+      return true;
+    }
+}
+
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 180284)
+++ gcc/cp/decl.c	(working copy)
@@ -1203,6 +1203,21 @@
       || TREE_TYPE (olddecl) == error_mark_node)
     return error_mark_node;
 
+  if (UDLIT_OPER_P (DECL_NAME (newdecl))
+      && UDLIT_OPER_P (DECL_NAME (olddecl)))
+    {
+      if (TREE_CODE (newdecl) == TEMPLATE_DECL
+	  && TREE_CODE (olddecl) != TEMPLATE_DECL
+	  && check_raw_literal_operator (olddecl))
+	error ("literal operator template %q+D conflicts with"
+	       " raw literal operator %qD", newdecl, olddecl);
+      else if (TREE_CODE (newdecl) != TEMPLATE_DECL
+	       && TREE_CODE (olddecl) == TEMPLATE_DECL
+	       && check_raw_literal_operator (newdecl))
+	error ("raw literal operator %q+D conflicts with"
+	       " literal operator template %qD", newdecl, olddecl);
+    }
+
   if (DECL_P (olddecl)
       && TREE_CODE (newdecl) == FUNCTION_DECL
       && TREE_CODE (olddecl) == FUNCTION_DECL
@@ -7343,7 +7358,48 @@
   if (IDENTIFIER_OPNAME_P (DECL_NAME (decl))
       && !grok_op_properties (decl, /*complain=*/true))
     return NULL_TREE;
+  else if (UDLIT_OPER_P (DECL_NAME (decl)))
+    {
+      bool long_long_unsigned_p;
+      bool long_double_p;
+      const char *suffix = NULL;
+      /* [over.literal]/6: Literal operators shall not have C linkage. */
+      if (DECL_LANGUAGE(decl) == lang_c)
+	{
+	  error ("literal operator with C linkage");
+	  return NULL_TREE;
+	}
 
+      if (DECL_NAMESPACE_SCOPE_P (decl))
+	{
+	  if (!check_literal_operator_args (decl, &long_long_unsigned_p,
+					    &long_double_p))
+	    {
+	      error ("%qD has invalid argument list", decl);
+	      return NULL_TREE;
+	    }
+
+	  suffix = UDLIT_OP_SUFFIX (DECL_NAME (decl));
+	  if (long_long_unsigned_p)
+	    {
+	      if (cpp_interpret_int_suffix (suffix, strlen (suffix)))
+		warning (0, "integer suffix %<%s%>"
+			    " shadowed by implementation", suffix);
+	    }
+	  else if (long_double_p)
+	    {
+	      if (cpp_interpret_float_suffix (suffix, strlen (suffix)))
+		warning (0, "floating point suffix %<%s%>"
+			    " shadowed by implementation", suffix);
+	    }
+	}
+      else
+	{
+	  error ("%qD must be a non-member function", decl);
+	  return NULL_TREE;
+	}
+    }
+
   if (funcdef_flag)
     /* Make the init_value nonzero so pushdecl knows this is not
        tentative.  error_mark_node is replaced later with the BLOCK.  */
@@ -8534,6 +8590,15 @@
       error ("declaration of %qD as non-function", dname);
       return error_mark_node;
     }
+ 
+  if (dname
+      && TREE_CODE (dname) == IDENTIFIER_NODE
+      && UDLIT_OPER_P (dname)
+      && innermost_code != cdk_function)
+    {
+      error ("declaration of %qD as non-function", dname);
+      return error_mark_node;
+    }
 
   if (dname && IDENTIFIER_OPNAME_P (dname))
     {
@@ -13752,6 +13817,7 @@
     case TRAIT_EXPR:		return TS_CP_TRAIT_EXPR;
     case LAMBDA_EXPR:		return TS_CP_LAMBDA_EXPR;
     case TEMPLATE_INFO:		return TS_CP_TEMPLATE_INFO;
+    case USERDEF_LITERAL:	return TS_CP_USERDEF_LITERAL;
     default:			return TS_CP_GENERIC;
     }
 }
Index: gcc/cp/error.c
===================================================================
--- gcc/cp/error.c	(revision 180284)
+++ gcc/cp/error.c	(working copy)
@@ -1534,6 +1534,8 @@
     }
   else if (name && IDENTIFIER_OPNAME_P (name))
     pp_cxx_tree_identifier (cxx_pp, name);
+  else if (name && UDLIT_OPER_P (name))
+    pp_cxx_tree_identifier (cxx_pp, name);
   else
     dump_decl (name, flags);
 
@@ -1756,6 +1758,10 @@
       pp_constant (cxx_pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (cxx_pp, t);
+      break;
+
     case THROW_EXPR:
       /* While waiting for caret diagnostics, avoid printing
 	 __cxa_allocate_exception, __cxa_throw, and the like.  */
@@ -3233,7 +3239,7 @@
 	pedwarn (input_location, OPT_pedantic,
 		 "inline namespaces "
 		 "only available with -std=c++0x or -std=gnu++0x");
-	break;	
+	break;
       case CPP0X_OVERRIDE_CONTROLS:
 	pedwarn (input_location, 0,
 		 "override controls (override/final) "
@@ -3244,8 +3250,13 @@
 		 "non-static data member initializers "
 		 "only available with -std=c++0x or -std=gnu++0x");
         break;
+      case CPP0X_USER_DEFINED_LITERALS:
+	pedwarn (input_location, 0,
+		 "user-defined literals "
+		 "only available with -std=c++0x or -std=gnu++0x");
+	break;
       default:
-	gcc_unreachable();
+	gcc_unreachable ();
       }
 }
 
Index: gcc/cp/cxx-pretty-print.c
===================================================================
--- gcc/cp/cxx-pretty-print.c	(revision 180284)
+++ gcc/cp/cxx-pretty-print.c	(working copy)
@@ -367,6 +367,17 @@
     pp_cxx_unqualified_id (pp, t);
 }
 
+/* user-defined literal:
+      literal ud-suffix  */
+
+void
+pp_cxx_userdef_literal (cxx_pretty_printer *pp, tree t)
+{
+  pp_cxx_constant (pp, USERDEF_LITERAL_VALUE (t));
+  pp_cxx_id_expression (pp, USERDEF_LITERAL_SUFFIX_ID (t));
+}
+
+
 /* primary-expression:
      literal
      this
@@ -413,6 +424,10 @@
       pp_cxx_constant (pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (pp, t);
+      break;
+
     case BASELINK:
       t = BASELINK_FUNCTIONS (t);
     case VAR_DECL:
@@ -1024,6 +1039,10 @@
       pp_cxx_constant (pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (pp, t);
+      break;
+
     case RESULT_DECL:
       pp_cxx_unqualified_id (pp, t);
       break;
Index: gcc/cp/semantics.c
===================================================================
--- gcc/cp/semantics.c	(revision 180284)
+++ gcc/cp/semantics.c	(working copy)
@@ -7865,6 +7865,7 @@
     case TEMPLATE_PARM_INDEX:
     case TRAIT_EXPR:
     case IDENTIFIER_NODE:
+    case USERDEF_LITERAL:
       /* We can see a FIELD_DECL in a pointer-to-member expression.  */
     case FIELD_DECL:
     case PARM_DECL:
Index: gcc/cp/cxx-pretty-print.h
===================================================================
--- gcc/cp/cxx-pretty-print.h	(revision 180284)
+++ gcc/cp/cxx-pretty-print.h	(working copy)
@@ -74,5 +74,7 @@
 void pp_cxx_trait_expression (cxx_pretty_printer *, tree);
 void pp_cxx_va_arg_expression (cxx_pretty_printer *, tree);
 void pp_cxx_offsetof_expression (cxx_pretty_printer *, tree);
+void pp_cxx_userdef_literal (cxx_pretty_printer *, tree);
 
+
 #endif /* GCC_CXX_PRETTY_PRINT_H */
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 180284)
+++ gcc/cp/parser.c	(working copy)
@@ -210,6 +210,8 @@
   (cp_lexer *);
 static void cp_lexer_rollback_tokens
   (cp_lexer *);
+static tree cp_literal_operator_id
+  (const char *);
 static void cp_lexer_print_token
   (FILE *, cp_token *);
 static inline bool cp_lexer_debugging_p
@@ -734,20 +736,20 @@
 	}
       else
 	{
-          if (warn_cxx0x_compat
-              && C_RID_CODE (token->u.value) >= RID_FIRST_CXX0X
-              && C_RID_CODE (token->u.value) <= RID_LAST_CXX0X)
-            {
-              /* Warn about the C++0x keyword (but still treat it as
-                 an identifier).  */
-              warning (OPT_Wc__0x_compat, 
-                       "identifier %qE will become a keyword in C++0x",
-                       token->u.value);
+	  if (warn_cxx0x_compat
+	      && C_RID_CODE (token->u.value) >= RID_FIRST_CXX0X
+	      && C_RID_CODE (token->u.value) <= RID_LAST_CXX0X)
+	    {
+	      /* Warn about the C++0x keyword (but still treat it as
+		 an identifier).  */
+	      warning (OPT_Wc__0x_compat, 
+		       "identifier %qE will become a keyword in C++0x",
+		       token->u.value);
 
-              /* Clear out the C_RID_CODE so we don't warn about this
-                 particular identifier-turned-keyword again.  */
-              C_SET_RID_CODE (token->u.value, RID_MAX);
-            }
+	      /* Clear out the C_RID_CODE so we don't warn about this
+		 particular identifier-turned-keyword again.  */
+	      C_SET_RID_CODE (token->u.value, RID_MAX);
+	    }
 
 	  token->ambiguous_p = false;
 	  token->keyword = RID_MAX;
@@ -1762,6 +1764,12 @@
   (cp_parser *);
 static tree cp_parser_string_literal
   (cp_parser *, bool, bool);
+static tree cp_parser_userdef_char_literal
+  (cp_parser *);
+static tree cp_parser_userdef_string_literal
+  (cp_token *);
+static tree cp_parser_userdef_numeric_literal
+  (cp_parser *);
 
 /* Basic concepts [gram.basic]  */
 
@@ -2270,6 +2278,8 @@
   (cp_parser *);
 static bool cp_parser_allow_gnu_extensions_p
   (cp_parser *);
+static bool cp_parser_is_pure_string_literal
+  (cp_token *);
 static bool cp_parser_is_string_literal
   (cp_token *);
 static bool cp_parser_is_keyword
@@ -2290,7 +2300,7 @@
 /* Returns nonzero if TOKEN is a string literal.  */
 
 static bool
-cp_parser_is_string_literal (cp_token* token)
+cp_parser_is_pure_string_literal (cp_token* token)
 {
   return (token->type == CPP_STRING ||
 	  token->type == CPP_STRING16 ||
@@ -2299,6 +2309,20 @@
 	  token->type == CPP_UTF8STRING);
 }
 
+/* Returns nonzero if TOKEN is a string literal
+   of a user-defined string literal.  */
+
+static bool
+cp_parser_is_string_literal (cp_token* token)
+{
+  return (cp_parser_is_pure_string_literal (token) ||
+	  token->type == CPP_STRING_USERDEF ||
+	  token->type == CPP_STRING16_USERDEF ||
+	  token->type == CPP_STRING32_USERDEF ||
+	  token->type == CPP_WSTRING_USERDEF ||
+	  token->type == CPP_UTF8STRING_USERDEF);
+}
+
 /* Returns nonzero if TOKEN is the indicated KEYWORD.  */
 
 static bool
@@ -3338,7 +3362,11 @@
   struct obstack str_ob;
   cpp_string str, istr, *strs;
   cp_token *tok;
-  enum cpp_ttype type;
+  enum cpp_ttype type, curr_type;
+  int have_suffix_p = 0;
+  tree string_tree;
+  tree suffix_id = NULL_TREE;
+  bool curr_tok_is_userdef_p = false;
 
   tok = cp_lexer_peek_token (parser->lexer);
   if (!cp_parser_is_string_literal (tok))
@@ -3347,7 +3375,18 @@
       return error_mark_node;
     }
 
-  type = tok->type;
+  if (cpp_userdef_string_p (tok->type))
+    {
+      string_tree = USERDEF_LITERAL_VALUE (tok->u.value);
+      curr_type = cpp_userdef_string_remove_type (tok->type);
+      curr_tok_is_userdef_p = true;
+    }
+  else
+    {
+      string_tree = tok->u.value;
+      curr_type = tok->type;
+    }
+  type = curr_type;
 
   /* Try to avoid the overhead of creating and destroying an obstack
      for the common case of just one string.  */
@@ -3356,10 +3395,19 @@
     {
       cp_lexer_consume_token (parser->lexer);
 
-      str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value);
-      str.len = TREE_STRING_LENGTH (tok->u.value);
+      str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree);
+      str.len = TREE_STRING_LENGTH (string_tree);
       count = 1;
 
+      if (curr_tok_is_userdef_p)
+	{
+	  suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value);
+	  have_suffix_p = 1;
+	  curr_type = cpp_userdef_string_remove_type (tok->type);
+	}
+      else
+	curr_type = tok->type;
+
       strs = &str;
     }
   else
@@ -3371,14 +3419,35 @@
 	{
 	  cp_lexer_consume_token (parser->lexer);
 	  count++;
-	  str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value);
-	  str.len = TREE_STRING_LENGTH (tok->u.value);
+	  str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree);
+	  str.len = TREE_STRING_LENGTH (string_tree);
 
-	  if (type != tok->type)
+	  if (curr_tok_is_userdef_p)
 	    {
+	      tree curr_suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value);
+	      if (have_suffix_p == 0)
+		{
+		  suffix_id = curr_suffix_id;
+		  have_suffix_p = 1;
+		}
+	      else if (have_suffix_p == 1
+		       && curr_suffix_id != suffix_id)
+		{
+		  error ("inconsistent user-defined literal suffixes"
+			 " %qD and %qD in string literal",
+			 suffix_id, curr_suffix_id);
+		  have_suffix_p = -1;
+		}
+	      curr_type = cpp_userdef_string_remove_type (tok->type);
+	    }
+	  else
+	    curr_type = tok->type;
+
+	  if (type != curr_type)
+	    {
 	      if (type == CPP_STRING)
-		type = tok->type;
-	      else if (tok->type != CPP_STRING)
+		type = curr_type;
+	      else if (curr_type != CPP_STRING)
 		error_at (tok->location,
 			  "unsupported non-standard concatenation "
 			  "of string literals");
@@ -3387,6 +3456,18 @@
 	  obstack_grow (&str_ob, &str, sizeof (cpp_string));
 
 	  tok = cp_lexer_peek_token (parser->lexer);
+	  if (cpp_userdef_string_p (tok->type))
+	    {
+	      string_tree = USERDEF_LITERAL_VALUE (tok->u.value);
+	      curr_type = cpp_userdef_string_remove_type (tok->type);
+	      curr_tok_is_userdef_p = true;
+	    }
+	  else
+	    {
+	      string_tree = tok->u.value;
+	      curr_type = tok->type;
+	      curr_tok_is_userdef_p = false;
+	    }
 	}
       while (cp_parser_is_string_literal (tok));
 
@@ -3424,6 +3505,13 @@
 	}
 
       value = fix_string_type (value);
+
+      if (have_suffix_p)
+	{
+	  tree literal = build_userdef_literal (suffix_id, value, NULL_TREE);
+	  tok->u.value = literal;
+	  return cp_parser_userdef_string_literal (tok);
+	}
     }
   else
     /* cpp_interpret_string has issued an error.  */
@@ -3435,7 +3523,186 @@
   return value;
 }
 
+/* Parse a user-defined char constant.  Returns a call to a user-defined
+   literal operator taking the character as an argument.  */
 
+static tree
+cp_parser_userdef_char_literal (cp_parser *parser)
+{
+  cp_token *token = NULL;
+  tree literal, suffix_id, value;
+  tree name, decl;
+  tree result;
+  VEC(tree,gc) *vec;
+
+  token = cp_lexer_consume_token (parser->lexer);
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  value = USERDEF_LITERAL_VALUE (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  vec = make_tree_vector ();
+  VEC_safe_push (tree, gc, vec, value);
+  decl = lookup_function_nonclass (name, vec, /*block_p=*/false);
+  if (!decl || decl == error_mark_node)
+    {
+      error ("unable to find user-defined character literal operator %qD",
+	     name);
+      release_tree_vector (vec);
+      return error_mark_node;
+    }
+  result = finish_call_expr (decl, &vec, false, true, tf_warning_or_error);
+  release_tree_vector (vec);
+
+  return result;
+}
+
+/* A subroutine of cp_parser_userdef_numeric_literal to
+   create a char... template parameter pack from a string node.  */
+
+static tree
+make_char_string_pack (tree value)
+{
+  tree parmvec;
+  tree argpack = make_node (NONTYPE_ARGUMENT_PACK);
+  const char *str = TREE_STRING_POINTER (value);
+  int i, len = TREE_STRING_LENGTH (value);
+  /*  Do I need to stuff THIS into a tree? */
+  tree argvec = make_tree_vec (1);
+
+  /* Fill in PARMVEC with all of the parameters.  */
+  parmvec = make_tree_vec (len);
+  for (i = 0; i < len; ++i)
+    TREE_VEC_ELT (parmvec, i) = build_int_cst (char_type_node, str[i]);
+
+  /* Build the argument packs.  */
+  SET_ARGUMENT_PACK_ARGS (argpack, parmvec);
+  TREE_TYPE (argpack) = char_type_node;
+
+  TREE_VEC_ELT (argvec, 0) = argpack;
+
+  return argvec;
+}
+
+/* Parse a user-defined numeric constant.  returns a call to a user-defined
+   literal operator.  */
+static tree
+cp_parser_userdef_numeric_literal (cp_parser *parser)
+{
+  cp_token *token = NULL;
+  tree literal, suffix_id, value, num_string;
+  tree name, decl;
+  tree result = error_mark_node;
+  VEC(tree,gc) *args;
+
+  token = cp_lexer_consume_token (parser->lexer);
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  value = USERDEF_LITERAL_VALUE (literal);
+  num_string = USERDEF_LITERAL_NUM_STRING (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  /* Try to find the literal operator by finishing the call expression
+     with the numeric argument.  */
+  args = make_tree_vector ();
+  VEC_safe_push (tree, gc, args, value);
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl && decl != error_mark_node)
+    {
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  /* If the numeric argument didn't work, look for a raw literal
+     operator taking a const char* argument consisting of the number
+     in string format.  */
+  args = make_tree_vector ();
+  VEC_safe_push (tree, gc, args, num_string);
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl && decl != error_mark_node)
+    {
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  /* If the raw literal didn't work, look for a non-type template
+     function with parameter pack char....  Call the function with
+     template parameter characters representing the number.  */
+  args = make_tree_vector ();
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl && decl != error_mark_node)
+    {
+      tree tmpl_args = make_char_string_pack (num_string);
+      decl = lookup_template_function (decl, tmpl_args);
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  if (result == error_mark_node)
+    error ("unable to find user-defined numeric literal operator %qD", name);
+
+  return result;
+}
+
+/* Parse a user-defined string constant.  Returns a call to a user-defined
+   literal operator taking a character pointer and the length of the string
+   as arguments.  */
+static tree
+cp_parser_userdef_string_literal (cp_token *token)
+{
+  tree literal, suffix_id, value;
+  tree name, decl;
+  tree result;
+  VEC(tree,gc) *vec;
+  int len;
+
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+  value = USERDEF_LITERAL_VALUE (literal);
+  len = TREE_STRING_LENGTH (value) - 1;
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  vec = make_tree_vector ();
+  VEC_safe_push (tree, gc, vec, value);
+  VEC_safe_push (tree, gc, vec, build_int_cst (size_type_node, len));
+  decl = lookup_function_nonclass (name, vec, /*block_p=*/false);
+  if (!decl || decl == error_mark_node)
+    {
+      error ("unable to find user-defined string literal operator %qD", name);
+      release_tree_vector (vec);
+      return error_mark_node;
+    }
+  result = finish_call_expr (decl, &vec, false, true, tf_none);
+  if (result == error_mark_node)
+    error ("invalid string literal prefix %<\"%s\"%> for user-defined"
+	   " raw literal operator %qD", TREE_STRING_POINTER (value), name);
+  release_tree_vector (vec);
+
+  return result;
+}
+
+
 /* Basic concepts [gram.basic]  */
 
 /* Parse a translation-unit.
@@ -3578,12 +3845,16 @@
 	   character-literal
 	   floating-literal
 	   string-literal
-	   boolean-literal  */
+	   boolean-literal
+	   pointer-literal
+	   user-defined-literal  */
     case CPP_CHAR:
     case CPP_CHAR16:
     case CPP_CHAR32:
     case CPP_WCHAR:
     case CPP_NUMBER:
+      if (TREE_CODE (token->u.value) == USERDEF_LITERAL)
+	return cp_parser_userdef_numeric_literal (parser);
       token = cp_lexer_consume_token (parser->lexer);
       if (TREE_CODE (token->u.value) == FIXED_CST)
 	{
@@ -3637,11 +3908,22 @@
 	}
       return token->u.value;
 
+    case CPP_CHAR_USERDEF:
+    case CPP_CHAR16_USERDEF:
+    case CPP_CHAR32_USERDEF:
+    case CPP_WCHAR_USERDEF:
+      return cp_parser_userdef_char_literal (parser);
+
     case CPP_STRING:
     case CPP_STRING16:
     case CPP_STRING32:
     case CPP_WSTRING:
     case CPP_UTF8STRING:
+    case CPP_STRING_USERDEF:
+    case CPP_STRING16_USERDEF:
+    case CPP_STRING32_USERDEF:
+    case CPP_WSTRING_USERDEF:
+    case CPP_UTF8STRING_USERDEF:
       /* ??? Should wide strings be allowed when parser->translate_strings_p
 	 is false (i.e. in attributes)?  If not, we can kill the third
 	 argument to cp_parser_string_literal.  */
@@ -4477,6 +4759,14 @@
 	  /* If that didn't work, try a conversion-function-id.  */
 	  if (!cp_parser_parse_definitely (parser))
 	    id = cp_parser_conversion_function_id (parser);
+	  else if (UDLIT_OPER_P (id))
+	    {
+	      /* 17.6.3.3.5  */
+	      const char *name = UDLIT_OP_SUFFIX (id);
+	      if (name[0] != '_' && !in_system_header)
+		warning (0, "literal operator suffixes not preceded by %<_%>"
+			    " are reserved for future standardization");
+	    }
 
 	  return id;
 	}
@@ -5119,7 +5409,7 @@
 	/* Restore the saved message.  */
 	parser->type_definition_forbidden_message = saved_message;
 	/* `typeid' may not appear in an integral constant expression.  */
-	if (cp_parser_non_integral_constant_expression(parser, NIC_TYPEID))
+	if (cp_parser_non_integral_constant_expression (parser, NIC_TYPEID))
 	  return error_mark_node;
       }
       break;
@@ -9739,7 +10029,7 @@
   /* If the next token is `extern' and the following token is a string
      literal, then we have a linkage specification.  */
   if (token1.keyword == RID_EXTERN
-      && cp_parser_is_string_literal (&token2))
+      && cp_parser_is_pure_string_literal (&token2))
     cp_parser_linkage_specification (parser);
   /* If the next token is `template', then we have either a template
      declaration, an explicit instantiation, or an explicit
@@ -11170,6 +11460,22 @@
   return cp_parser_operator (parser);
 }
 
+/* Return an identifier node for a user-defined literal operator.
+   The suffix identifier is chained to the operator name identifier.  */
+
+static tree
+cp_literal_operator_id (const char* name)
+{
+  tree identifier;
+  char *buffer = XNEWVEC (char, strlen (UDLIT_OP_ANSI_PREFIX)
+			      + strlen (name) + 10);
+  sprintf (buffer, UDLIT_OP_ANSI_FORMAT, name);
+  identifier = get_identifier (buffer);
+  /*IDENTIFIER_UDLIT_OPNAME_P (identifier) = 1; If we get a flag someday. */
+
+  return identifier;
+}
+
 /* Parse an operator.
 
    operator:
@@ -11389,6 +11695,37 @@
       cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE);
       return ansi_opname (ARRAY_REF);
 
+    case CPP_STRING:
+      if (cxx_dialect == cxx98)
+	maybe_warn_cpp0x (CPP0X_USER_DEFINED_LITERALS);
+      if (TREE_STRING_LENGTH (token->u.value) > 2)
+	{
+	  error ("expected empty string after %<operator%> keyword");
+	  return error_mark_node;
+	}
+      /* Consume the string.  */
+      cp_lexer_consume_token (parser->lexer);
+      /* Look for the suffix identifier.  */
+      token = cp_lexer_peek_token (parser->lexer);
+      if (token->type == CPP_NAME)
+	{
+	  id = cp_parser_identifier (parser);
+	  if (id != error_mark_node)
+	    {
+	      const char *name = IDENTIFIER_POINTER (id);
+	      return cp_literal_operator_id (name);
+	    }
+	}
+      else
+	{
+	  error ("expected suffix identifier");
+	  return error_mark_node;
+	}
+
+    case CPP_STRING_USERDEF:
+      error ("missing space between %<\"\"%> and suffix identifier");
+      return error_mark_node;
+
     default:
       /* Anything else is an error.  */
       break;
@@ -20583,6 +20920,32 @@
   /* Finish up.  */
   finish_template_decl (parameter_list);
 
+  /* Check the template arguments for a literal operator template.  */
+  if (decl
+      && (TREE_CODE (decl) == FUNCTION_DECL || DECL_FUNCTION_TEMPLATE_P (decl))
+      && UDLIT_OPER_P (DECL_NAME (decl)))
+    {
+      bool ok = true;
+      if (parameter_list == NULL_TREE)
+	ok = false;
+      else
+	{
+	  int num_parms = TREE_VEC_LENGTH (parameter_list);
+	  if (num_parms != 1)
+	    ok = false;
+	  else
+	    {
+	      tree parm_list = TREE_VEC_ELT (parameter_list, 0);
+	      tree parm = INNERMOST_TEMPLATE_PARMS (parm_list);
+	      if (TREE_TYPE (parm) != char_type_node
+		  || !TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (parm)))
+		ok = false;
+	    }
+	}
+      if (!ok)
+	error ("literal operator template %qD has invalid parameter list",
+	       decl);
+    }
   /* Register member declarations.  */
   if (member_p && !friend_p && decl && !DECL_CLASS_TEMPLATE_P (decl))
     finish_member_declaration (decl);
@@ -22891,7 +23254,8 @@
   /* If the next token is `extern' and the following token is a string
      literal, then we have a linkage specification.  */
   if (token->keyword == RID_EXTERN
-      && cp_parser_is_string_literal (cp_lexer_peek_nth_token (parser->lexer, 2)))
+      && cp_parser_is_pure_string_literal
+	 (cp_lexer_peek_nth_token (parser->lexer, 2)))
     cp_parser_linkage_specification (parser);
   /* Handle #pragma, if any.  */
   else if (token->type == CPP_PRAGMA)
Index: gcc/cp/cp-objcp-common.c
===================================================================
--- gcc/cp/cp-objcp-common.c	(revision 180284)
+++ gcc/cp/cp-objcp-common.c	(working copy)
@@ -100,6 +100,8 @@
 
     case TEMPLATE_INFO:         return sizeof (struct tree_template_info);
 
+    case USERDEF_LITERAL:	return sizeof (struct tree_userdef_literal);
+
     default:
       gcc_unreachable ();
     }
Index: gcc/cp/mangle.c
===================================================================
--- gcc/cp/mangle.c	(revision 180284)
+++ gcc/cp/mangle.c	(working copy)
@@ -181,6 +181,7 @@
 static void write_unqualified_name (const tree);
 static void write_conversion_operator_name (const tree);
 static void write_source_name (tree);
+static void write_literal_operator_name (tree);
 static void write_unnamed_type_name (const tree);
 static void write_closure_type_name (const tree);
 static int hwint_to_ascii (unsigned HOST_WIDE_INT, const unsigned int, char *,
@@ -1174,6 +1175,8 @@
 	  }
       write_string (mangled_name);
     }
+  else if (UDLIT_OPER_P (identifier))
+    write_literal_operator_name (identifier);
   else
     write_source_name (identifier);
 }
@@ -1227,6 +1230,8 @@
 
 	  write_string (oni[DECL_OVERLOADED_OPERATOR_P (decl)].mangled_name);
 	}
+      else if (UDLIT_OPER_P (DECL_NAME (decl)))
+	write_literal_operator_name (DECL_NAME (decl));
       else
 	found = false;
 
@@ -1286,6 +1291,21 @@
   write_identifier (IDENTIFIER_POINTER (identifier));
 }
 
+/* Write a user-defined literal operator.
+   IDENTIFIER is an LITERAL_IDENTIFIER_NODE.  */
+
+static void
+write_literal_operator_name (tree identifier)
+{
+  const char* suffix = UDLIT_OP_SUFFIX (identifier);
+  char* buffer = XNEWVEC (char, strlen (UDLIT_OP_MANGLED_PREFIX)
+			      + strlen (suffix) + 10);
+  sprintf (buffer, UDLIT_OP_MANGLED_FORMAT, suffix);
+
+  write_unsigned_number (strlen (buffer));
+  write_identifier (buffer);
+}
+
 /* Encode 0 as _, and 1+ as n-1_.  */
 
 static void
Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h	(revision 180284)
+++ gcc/cp/cp-tree.h	(working copy)
@@ -400,7 +400,9 @@
   /* override controls, override/final */
   CPP0X_OVERRIDE_CONTROLS,
   /* non-static data member initializers */
-  CPP0X_NSDMI
+  CPP0X_NSDMI,
+  /* user defined literals */
+  CPP0X_USER_DEFINED_LITERALS
 } cpp0x_warn_str;
   
 /* The various kinds of operation used by composite_pointer_type. */
@@ -740,6 +742,7 @@
   TS_CP_TRAIT_EXPR,
   TS_CP_LAMBDA_EXPR,
   TS_CP_TEMPLATE_INFO,
+  TS_CP_USERDEF_LITERAL,
   LAST_TS_CP_ENUM
 };
 
@@ -765,6 +768,8 @@
     lambda_expression;
   struct tree_template_info GTY ((tag ("TS_CP_TEMPLATE_INFO")))
     template_info;
+  struct tree_userdef_literal GTY ((tag ("TS_CP_USERDEF_LITERAL")))
+    userdef_literal;
 };
 
 \f
@@ -4228,6 +4233,17 @@
              LAMBDANAME_PREFIX, \
 	     sizeof (LAMBDANAME_PREFIX) - 1))
 
+#define UDLIT_OP_ANSI_PREFIX "operator\"\" "
+#define UDLIT_OP_ANSI_FORMAT UDLIT_OP_ANSI_PREFIX "%s"
+#define UDLIT_OP_MANGLED_PREFIX "li"
+#define UDLIT_OP_MANGLED_FORMAT UDLIT_OP_MANGLED_PREFIX "%s"
+#define UDLIT_OPER_P(ID_NODE) \
+  (!strncmp (IDENTIFIER_POINTER (ID_NODE), \
+             UDLIT_OP_ANSI_PREFIX, \
+	     sizeof (UDLIT_OP_ANSI_PREFIX) - 1))
+#define UDLIT_OP_SUFFIX(ID_NODE) \
+  (IDENTIFIER_POINTER (ID_NODE) + sizeof (UDLIT_OP_ANSI_PREFIX) - 1)
+
 #if !defined(NO_DOLLAR_IN_LABEL) || !defined(NO_DOT_IN_LABEL)
 
 #define VTABLE_NAME_P(ID_NODE) (IDENTIFIER_POINTER (ID_NODE)[1] == 'v' \
@@ -5758,6 +5774,8 @@
 extern int lvalue_or_else			(tree, enum lvalue_use,
                                                  tsubst_flags_t);
 extern void check_template_keyword		(tree);
+extern bool check_raw_literal_operator		(const_tree decl);
+extern bool check_literal_operator_args		(const_tree, bool *, bool *);
 
 /* in typeck2.c */
 extern void require_complete_eh_spec_types	(tree, tree);
Index: libcpp/include/cpplib.h
===================================================================
--- libcpp/include/cpplib.h	(revision 180284)
+++ libcpp/include/cpplib.h	(working copy)
@@ -131,6 +131,16 @@
   TK(OBJC_STRING,	LITERAL) /* @"string" - Objective-C */		\
   TK(HEADER_NAME,	LITERAL) /* <stdio.h> in #include */		\
 									\
+  TK(CHAR_USERDEF,	LITERAL) /* 'char'_suffix - C++-0x */		\
+  TK(WCHAR_USERDEF,	LITERAL) /* L'char'_suffix - C++-0x */		\
+  TK(CHAR16_USERDEF,	LITERAL) /* u'char'_suffix - C++-0x */		\
+  TK(CHAR32_USERDEF,	LITERAL) /* U'char'_suffix - C++-0x */		\
+  TK(STRING_USERDEF,	LITERAL) /* "string"_suffix - C++-0x */		\
+  TK(WSTRING_USERDEF,	LITERAL) /* L"string"_suffix - C++-0x */	\
+  TK(STRING16_USERDEF,	LITERAL) /* u"string"_suffix - C++-0x */	\
+  TK(STRING32_USERDEF,	LITERAL) /* U"string"_suffix - C++-0x */	\
+  TK(UTF8STRING_USERDEF,LITERAL) /* u8"string"_suffix - C++-0x */	\
+									\
   TK(COMMENT,		LITERAL) /* Only if output comments.  */	\
 				 /* SPELL_LITERAL happens to DTRT.  */	\
   TK(MACRO_ARG,		NONE)	 /* Macro argument.  */			\
@@ -414,6 +424,9 @@
   /* True for traditional preprocessing.  */
   unsigned char traditional;
 
+  /* Nonzero for the 2011 C++ Standard.  */
+  unsigned char cxx11;
+
   /* Holds the name of the target (execution) character set.  */
   const char *narrow_charset;
 
@@ -829,13 +842,22 @@
 #define CPP_N_FRACT	0x100000 /* Fract types.  */
 #define CPP_N_ACCUM	0x200000 /* Accum types.  */
 
+#define CPP_N_USERDEF	0x1000000 /* C++0x user-defined literal.  */
+
 /* Classify a CPP_NUMBER token.  The return value is a combination of
    the flags from the above sets.  */
-extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *);
+extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *,
+				     const char **);
 
+/* Return the classification flags for a float suffix.  */
+extern unsigned int cpp_interpret_float_suffix (const char *, size_t);
+
+/* Return the classification flags for an int suffix.  */
+extern unsigned int cpp_interpret_int_suffix (const char *, size_t);
+
 /* Evaluate a token classified as category CPP_N_INTEGER.  */
 extern cpp_num cpp_interpret_integer (cpp_reader *, const cpp_token *,
-				      unsigned int type);
+				      unsigned int);
 
 /* Sign extend a number, with PRECISION significant bits and all
    others assumed clear, to fill out a cpp_num structure.  */
@@ -1005,4 +1027,20 @@
 extern void cpp_force_token_locations (cpp_reader *, source_location *);
 extern void cpp_stop_forcing_token_locations (cpp_reader *);
 
+/* In expr.c */
+extern enum cpp_ttype cpp_userdef_string_remove_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_string_add_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_char_remove_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_char_add_type
+  (enum cpp_ttype type);
+extern bool cpp_userdef_string_p
+  (enum cpp_ttype type);
+extern bool cpp_userdef_char_p
+  (enum cpp_ttype type);
+extern const char * cpp_get_userdef_suffix
+  (const cpp_token *);
+
 #endif /* ! LIBCPP_CPPLIB_H */
Index: libcpp/init.c
===================================================================
--- libcpp/init.c	(revision 180284)
+++ libcpp/init.c	(working copy)
@@ -80,22 +80,23 @@
   char digraphs;
   char uliterals;
   char rliterals;
+  char cxx11;
 };
 
 static const struct lang_flags lang_defaults[] =
-{ /*              c99 c++ xnum xid std  //   digr ulit rlit */
-  /* GNUC89   */  { 0,  0,  1,   0,  0,   1,   1,   0,   0 },
-  /* GNUC99   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1 },
-  /* GNUC1X   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1 },
-  /* STDC89   */  { 0,  0,  0,   0,  1,   0,   0,   0,   0 },
-  /* STDC94   */  { 0,  0,  0,   0,  1,   0,   1,   0,   0 },
-  /* STDC99   */  { 1,  0,  1,   0,  1,   1,   1,   0,   0 },
-  /* STDC1X   */  { 1,  0,  1,   0,  1,   1,   1,   1,   0 },
-  /* GNUCXX   */  { 0,  1,  1,   0,  0,   1,   1,   0,   0 },
-  /* CXX98    */  { 0,  1,  1,   0,  1,   1,   1,   0,   0 },
-  /* GNUCXX0X */  { 1,  1,  1,   0,  0,   1,   1,   1,   1 },
-  /* CXX0X    */  { 1,  1,  1,   0,  1,   1,   1,   1,   1 },
-  /* ASM      */  { 0,  0,  1,   0,  0,   1,   0,   0,   0 }
+{ /*              c99 c++ xnum xid std  //   digr ulit rlit cxx11 */
+  /* GNUC89   */  { 0,  0,  1,   0,  0,   1,   1,   0,   0,    0 },
+  /* GNUC99   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1,    0 },
+  /* GNUC1X   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1,    0 },
+  /* STDC89   */  { 0,  0,  0,   0,  1,   0,   0,   0,   0,    0 },
+  /* STDC94   */  { 0,  0,  0,   0,  1,   0,   1,   0,   0,    0 },
+  /* STDC99   */  { 1,  0,  1,   0,  1,   1,   1,   0,   0,    0 },
+  /* STDC1X   */  { 1,  0,  1,   0,  1,   1,   1,   1,   0,    0 },
+  /* GNUCXX   */  { 0,  1,  1,   0,  0,   1,   1,   0,   0,    0 },
+  /* CXX98    */  { 0,  1,  1,   0,  1,   1,   1,   0,   0,    0 },
+  /* GNUCXX0X */  { 1,  1,  1,   0,  0,   1,   1,   1,   1,    1 },
+  /* CXX0X    */  { 1,  1,  1,   0,  1,   1,   1,   1,   1,    1 },
+  /* ASM      */  { 0,  0,  1,   0,  0,   1,   0,   0,   0,    0 }
   /* xid should be 1 for GNUC99, STDC99, GNUCXX, CXX98, GNUCXX0X, and
      CXX0X when no longer experimental (when all uses of identifiers
      in the compiler have been audited for correct handling of
@@ -120,6 +121,7 @@
   CPP_OPTION (pfile, digraphs)			 = l->digraphs;
   CPP_OPTION (pfile, uliterals)			 = l->uliterals;
   CPP_OPTION (pfile, rliterals)			 = l->rliterals;
+  CPP_OPTION (pfile, cxx11)			 = l->cxx11;
 }
 
 /* Initialize library global state.  */
Index: libcpp/expr.c
===================================================================
--- libcpp/expr.c	(revision 180284)
+++ libcpp/expr.c	(working copy)
@@ -1,6 +1,6 @@
 /* Parse C expressions for cpplib.
    Copyright (C) 1987, 1992, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
-   2002, 2004, 2008, 2009, 2010 Free Software Foundation.
+   2002, 2004, 2008, 2009, 2010, 2011 Free Software Foundation.
    Contributed by Per Bothner, 1994.
 
 This program is free software; you can redistribute it and/or modify it
@@ -185,6 +185,13 @@
 	     q ? CPP_N_MD_Q : CPP_N_DEFAULT));
 }
 
+/* Return the classification flags for a float suffix.  */
+unsigned int
+cpp_interpret_float_suffix (const char *s, size_t len)
+{
+  return interpret_float_suffix ((const unsigned char *)s, len);
+}
+
 /* Subroutine of cpp_classify_number.  S points to an integer suffix
    of length LEN, possibly zero. Returns 0 for an invalid suffix, or a
    flag vector describing the suffix.  */
@@ -219,11 +226,143 @@
 	     : (l == 1) ? CPP_N_MEDIUM : CPP_N_LARGE));
 }
 
+/* Return the classification flags for an int suffix.  */
+unsigned int
+cpp_interpret_int_suffix (const char *s, size_t len)
+{
+  return interpret_int_suffix ((const unsigned char *)s, len);
+}
+
+/* Return the string type corresponding to the the input user-defined string
+   literal type.  If the input type is not a user-defined string literal
+   type return the input type.  */
+enum cpp_ttype
+cpp_userdef_string_remove_type (enum cpp_ttype type)
+{
+  if (type == CPP_STRING_USERDEF)
+    return CPP_STRING;
+  else if (type == CPP_WSTRING_USERDEF)
+    return CPP_WSTRING;
+  else if (type == CPP_STRING16_USERDEF)
+    return CPP_STRING16;
+  else if (type == CPP_STRING32_USERDEF)
+    return CPP_STRING32;
+  else if (type == CPP_UTF8STRING_USERDEF)
+    return CPP_UTF8STRING;
+  else
+    return type;
+}
+
+/* Return the user-defined string literal type corresponding to the input
+   string type.  If the input type is not a string type return the input
+   type.  */
+enum cpp_ttype
+cpp_userdef_string_add_type (enum cpp_ttype type)
+{
+  if (type == CPP_STRING)
+    return CPP_STRING_USERDEF;
+  else if (type == CPP_WSTRING)
+    return CPP_WSTRING_USERDEF;
+  else if (type == CPP_STRING16)
+    return CPP_STRING16_USERDEF;
+  else if (type == CPP_STRING32)
+    return CPP_STRING32_USERDEF;
+  else if (type == CPP_UTF8STRING)
+    return CPP_UTF8STRING_USERDEF;
+  else
+    return type;
+}
+
+/* Return the char type corresponding to the the input user-defined char
+   literal type.  If the input type is not a user-defined char literal
+   type return the input type.  */
+enum cpp_ttype
+cpp_userdef_char_remove_type (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR_USERDEF)
+    return CPP_CHAR;
+  else if (type == CPP_WCHAR_USERDEF)
+    return CPP_WCHAR;
+  else if (type == CPP_CHAR16_USERDEF)
+    return CPP_STRING16;
+  else if (type == CPP_CHAR32_USERDEF)
+    return CPP_STRING32;
+  else
+    return type;
+}
+
+/* Return the user-defined char literal type corresponding to the input
+   char type.  If the input type is not a char type return the input
+   type.  */
+enum cpp_ttype
+cpp_userdef_char_add_type (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR)
+    return CPP_CHAR_USERDEF;
+  else if (type == CPP_WCHAR)
+    return CPP_WCHAR_USERDEF;
+  else if (type == CPP_CHAR16)
+    return CPP_CHAR16_USERDEF;
+  else if (type == CPP_CHAR32)
+    return CPP_CHAR32_USERDEF;
+  else
+    return type;
+}
+
+/* Return true if the token type is a user-defined string literal.  */
+bool
+cpp_userdef_string_p (enum cpp_ttype type)
+{
+  if (type == CPP_STRING_USERDEF
+   || type == CPP_WSTRING_USERDEF
+   || type == CPP_STRING16_USERDEF
+   || type == CPP_STRING32_USERDEF
+   || type == CPP_UTF8STRING_USERDEF)
+    return true;
+  else
+    return false;
+}
+
+/* Return true if the token type is a user-defined char literal.  */
+bool
+cpp_userdef_char_p (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR_USERDEF
+   || type == CPP_WCHAR_USERDEF
+   || type == CPP_CHAR16_USERDEF
+   || type == CPP_CHAR32_USERDEF)
+    return true;
+  else
+    return false;
+}
+
+/* Extract the suffix from a user-defined literal string or char.  */
+const char *
+cpp_get_userdef_suffix (const cpp_token *tok)
+{
+  unsigned int len = tok->val.str.len;
+  const char *text = (const char *)tok->val.str.text;
+  char delim;
+  unsigned int i;
+  for (i = 0; i < len; ++i)
+    if (text[i] == '\'' || text[i] == '"')
+      break;
+  if (i == len)
+    return text + len;
+  delim = text[i];
+  for (i = len; i > 0; --i)
+    if (text[i - 1] == delim)
+      break;
+  return text + i;
+}
+
 /* Categorize numeric constants according to their field (integer,
    floating point, or invalid), radix (decimal, octal, hexadecimal),
-   and type suffixes.  */
+   and type suffixes.  In C++0X if UD_SUFFIX is non null it will be
+   assigned any unrecognized suffix for a user-defined literal.  */
 unsigned int
-cpp_classify_number (cpp_reader *pfile, const cpp_token *token)
+cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
+		     const char **ud_suffix)
 {
   const uchar *str = token->val.str.text;
   const uchar *limit;
@@ -231,6 +370,9 @@
   enum {NOT_FLOAT = 0, AFTER_POINT, AFTER_EXPON} float_flag;
   bool seen_digit;
 
+  if (ud_suffix)
+    *ud_suffix = NULL;
+
   /* If the lexer has done its job, length one can only be a single
      digit.  Fast-path this very common case.  */
   if (token->val.str.len == 1)
@@ -361,10 +503,19 @@
       result = interpret_float_suffix (str, limit - str);
       if (result == 0)
 	{
-	  cpp_error (pfile, CPP_DL_ERROR,
-		     "invalid suffix \"%.*s\" on floating constant",
-		     (int) (limit - str), str);
-	  return CPP_N_INVALID;
+	  if (CPP_OPTION (pfile, cxx11))
+	    {
+	      if (ud_suffix)
+		*ud_suffix = (const char *) str;
+	      result = CPP_N_LARGE | CPP_N_USERDEF;
+	    }
+	  else
+	    {
+	      cpp_error (pfile, CPP_DL_ERROR,
+			 "invalid suffix \"%.*s\" on floating constant",
+			 (int) (limit - str), str);
+	      return CPP_N_INVALID;
+	    }
 	}
 
       /* Traditional C didn't accept any floating suffixes.  */
@@ -406,10 +557,19 @@
       result = interpret_int_suffix (str, limit - str);
       if (result == 0)
 	{
-	  cpp_error (pfile, CPP_DL_ERROR,
-		     "invalid suffix \"%.*s\" on integer constant",
-		     (int) (limit - str), str);
-	  return CPP_N_INVALID;
+	  if (CPP_OPTION (pfile, cxx11))
+	    {
+	      if (ud_suffix)
+		*ud_suffix = (const char *) str;
+	      result = CPP_N_UNSIGNED | CPP_N_LARGE | CPP_N_USERDEF;
+	    }
+	  else
+	    {
+	      cpp_error (pfile, CPP_DL_ERROR,
+			 "invalid suffix \"%.*s\" on integer constant",
+			 (int) (limit - str), str);
+	      return CPP_N_INVALID;
+	    }
 	}
 
       /* Traditional C only accepted the 'L' suffix.
@@ -748,7 +908,7 @@
   switch (token->type)
     {
     case CPP_NUMBER:
-      temp = cpp_classify_number (pfile, token);
+      temp = cpp_classify_number (pfile, token, NULL);
       switch (temp & CPP_N_CATEGORY)
 	{
 	case CPP_N_FLOATING:
Index: libcpp/lex.c
===================================================================
--- libcpp/lex.c	(revision 180284)
+++ libcpp/lex.c	(working copy)
@@ -1478,6 +1478,18 @@
     }
  break_outer_loop:
 
+  if (CPP_OPTION (pfile, cxx11))
+    {
+      /* Grab user defined literal suffix.  */
+      if (ISIDST(*cur))
+	{
+	  type = cpp_userdef_string_add_type (type);
+	  ++cur;
+	}
+      while (ISIDNUM(*cur))
+	++cur;
+    }
+
   pfile->buffer->cur = cur;
   if (first_buff == NULL)
     create_literal (pfile, token, base, cur - base, type);
@@ -1581,6 +1593,19 @@
     cpp_error (pfile, CPP_DL_PEDWARN, "missing terminating %c character",
 	       (int) terminator);
 
+  if (CPP_OPTION (pfile, cxx11))
+    {
+      /* Grab user defined literal suffix.  */
+      if (ISIDST(*cur))
+	{
+	  type = cpp_userdef_char_add_type (type);
+	  type = cpp_userdef_string_add_type (type);
+          ++cur;
+	}
+      while (ISIDNUM(*cur))
+	++cur;
+    }
+
   pfile->buffer->cur = cur;
   create_literal (pfile, token, base, cur - base, type);
 }

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-21 14:56   ` Ed Smith-Rowland
@ 2011-10-21 21:20     ` Tom Tromey
  2011-10-21 23:38       ` Jason Merrill
  0 siblings, 1 reply; 36+ messages in thread
From: Tom Tromey @ 2011-10-21 21:20 UTC (permalink / raw)
  To: Ed Smith-Rowland; +Cc: Jason Merrill, gcc-patches

>>>>> "Ed" == Ed Smith-Rowland <3dw4rd@verizon.net> writes:

Ed> +  /* Nonzero for the 2011 C++ Standard.  */
Ed> +  unsigned char cxx11;

I think it would be better if the new field name reflected its purpose,
so something like "user_literals".

Ed> +      if (ISIDST(*cur))
Ed> +	{
Ed> +	  type = cpp_userdef_string_add_type (type);
Ed> +	  ++cur;
Ed> +	}
Ed> +      while (ISIDNUM(*cur))

There are a few spots like this that are missing a space before an open
paren.

Otherwise the libcpp changes seem fine to me.  I don't actually know the
C++0x user-defined literal spec, though, so someone else will have to
review it for correctness against that.

Tom

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-21 21:20     ` Tom Tromey
@ 2011-10-21 23:38       ` Jason Merrill
  2011-10-23 22:29         ` Ed Smith-Rowland
                           ` (2 more replies)
  0 siblings, 3 replies; 36+ messages in thread
From: Jason Merrill @ 2011-10-21 23:38 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Ed Smith-Rowland, gcc-patches

I think we're down to minor cosmetic issues:

On 10/21/2011 03:55 PM, Tom Tromey wrote:
> There are a few spots like this that are missing a space before an open
> paren.

> +      if (DECL_LANGUAGE(decl) == lang_c)

Another one.

> -          if (warn_cxx0x_compat
> -              && C_RID_CODE (token->u.value) >= RID_FIRST_CXX0X
> -              && C_RID_CODE (token->u.value) <= RID_LAST_CXX0X)
....

This code doesn't seem to have actually changed, so let's not adjust its 
whitespace.

> +  /* Fill in PARMVEC with all of the parameters.  */
> +  parmvec = make_tree_vec (len);

Let's call it 'charvec'; the characters are template arguments, not 
parameters.

> +/* Parse a user-defined numeric constant.  returns a call to a user-defined
> +   literal operator.  */
> +static tree
> +cp_parser_userdef_numeric_literal (cp_parser *parser)

Add a blank line between comment and function.

> While looking at the embedded string issue I found that if you apply the suffix of a raw literal to a string it errors as it should but the error complained that there were too many arguments for the function.  This was not helpful so I made a nicer error message.

> +  if (result == error_mark_node)
> +    error ("invalid string literal prefix %<\"%s\"%> for user-defined"
> +          " raw literal operator %qD", TREE_STRING_POINTER (value), name);

I think that we want a combination of the two errors; the new error 
doesn't help the user to fix their code as much.  It should remind them 
that for a string literal the function is called with a length argument 
as well.

> +       error ("literal operator template %qD has invalid parameter list",
> +              decl);

Similarly, this message should say that the parameter list needs to be 
<char...>

>
> +
> +/* Return true if a user-defined literal operator is a raw operator.  */
> +

We don't need the extra newline before the comment.

Should be ready to go with these tweaks.

Jason

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-21 23:38       ` Jason Merrill
@ 2011-10-23 22:29         ` Ed Smith-Rowland
  2011-10-24 15:41         ` Ed Smith-Rowland
  2011-10-25  7:07         ` Ed Smith-Rowland
  2 siblings, 0 replies; 36+ messages in thread
From: Ed Smith-Rowland @ 2011-10-23 22:29 UTC (permalink / raw)
  To: Jason Merrill; +Cc: Tom Tromey, gcc-patches

On 10/21/2011 05:20 PM, Jason Merrill wrote:
> I think we're down to minor cosmetic issues:
>
> On 10/21/2011 03:55 PM, Tom Tromey wrote:
>> There are a few spots like this that are missing a space before an open
>> paren.
>
>> +      if (DECL_LANGUAGE(decl) == lang_c)
>
> Another one.
>
>> -          if (warn_cxx0x_compat
>> - && C_RID_CODE (token->u.value) >= RID_FIRST_CXX0X
>> - && C_RID_CODE (token->u.value) <= RID_LAST_CXX0X)
> ....
>
> This code doesn't seem to have actually changed, so let's not adjust 
> its whitespace.
>
>> +  /* Fill in PARMVEC with all of the parameters.  */
>> +  parmvec = make_tree_vec (len);
>
> Let's call it 'charvec'; the characters are template arguments, not 
> parameters.
>
>> +/* Parse a user-defined numeric constant.  returns a call to a 
>> user-defined
>> +   literal operator.  */
>> +static tree
>> +cp_parser_userdef_numeric_literal (cp_parser *parser)
>
> Add a blank line between comment and function.
>
>> While looking at the embedded string issue I found that if you apply 
>> the suffix of a raw literal to a string it errors as it should but 
>> the error complained that there were too many arguments for the 
>> function.  This was not helpful so I made a nicer error message.
>
>> +  if (result == error_mark_node)
>> +    error ("invalid string literal prefix %<\"%s\"%> for user-defined"
>> +          " raw literal operator %qD", TREE_STRING_POINTER (value), 
>> name);
>
> I think that we want a combination of the two errors; the new error 
> doesn't help the user to fix their code as much.  It should remind 
> them that for a string literal the function is called with a length 
> argument as well.
>
Concerning this error, the only way to get here is to mis-use a raw 
literal operator by giving it a quoted string.  The prefix must be 
interpretable as a number of some kind.  I think I'll tell the user to 
drop the quotes.
The length of a string literal is supplied implicitly by the compiler to 
a string literal operator when a string user defined literal is 
encountered.  The user doesn't explicitly call the operator (not here 
anyway).

>> +       error ("literal operator template %qD has invalid parameter 
>> list",
>> +              decl);
>
> Similarly, this message should say that the parameter list needs to be 
> <char...>
>
>>
>> +
>> +/* Return true if a user-defined literal operator is a raw 
>> operator.  */
>> +
>
> We don't need the extra newline before the comment.
>
> Should be ready to go with these tweaks.
>
> Jason
>
I've made these corrections.  They'll be in the next patch.

Unfortunately, as I was testing raw operators on very long strings I 
observed two things:
1. A bad error - the argument to a raw literal operator must be a 
null-terminated string.
2. If a very long number is given as the prefix to a numeric literal, a 
warning is issued ("integer constant is too large for its type")
If the receiving operator is either the raw operator or the operator 
template then this should not be given.  I anticipate people might like 
to have multi-precision numbers someday, for example.

Before I release another patch I have to fix 1.  The warning might be 
fixed in-tree if that's OK.

Ed

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-21 23:38       ` Jason Merrill
  2011-10-23 22:29         ` Ed Smith-Rowland
@ 2011-10-24 15:41         ` Ed Smith-Rowland
  2011-10-25 23:38           ` Jason Merrill
  2011-10-25  7:07         ` Ed Smith-Rowland
  2 siblings, 1 reply; 36+ messages in thread
From: Ed Smith-Rowland @ 2011-10-24 15:41 UTC (permalink / raw)
  To: Jason Merrill; +Cc: Tom Tromey, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 2497 bytes --]

On 10/21/2011 05:20 PM, Jason Merrill wrote:
> I think we're down to minor cosmetic issues:
>
> On 10/21/2011 03:55 PM, Tom Tromey wrote:
>> There are a few spots like this that are missing a space before an open
>> paren.
>
>> +      if (DECL_LANGUAGE(decl) == lang_c)
>
> Another one.
>
>> -          if (warn_cxx0x_compat
>> - && C_RID_CODE (token->u.value) >= RID_FIRST_CXX0X
>> - && C_RID_CODE (token->u.value) <= RID_LAST_CXX0X)
> ....
>
> This code doesn't seem to have actually changed, so let's not adjust 
> its whitespace.
>
>> +  /* Fill in PARMVEC with all of the parameters.  */
>> +  parmvec = make_tree_vec (len);
>
> Let's call it 'charvec'; the characters are template arguments, not 
> parameters.
>
>> +/* Parse a user-defined numeric constant.  returns a call to a 
>> user-defined
>> +   literal operator.  */
>> +static tree
>> +cp_parser_userdef_numeric_literal (cp_parser *parser)
>
> Add a blank line between comment and function.
>
>> While looking at the embedded string issue I found that if you apply 
>> the suffix of a raw literal to a string it errors as it should but 
>> the error complained that there were too many arguments for the 
>> function.  This was not helpful so I made a nicer error message.
>
>> +  if (result == error_mark_node)
>> +    error ("invalid string literal prefix %<\"%s\"%> for user-defined"
>> +          " raw literal operator %qD", TREE_STRING_POINTER (value), 
>> name);
>
> I think that we want a combination of the two errors; the new error 
> doesn't help the user to fix their code as much.  It should remind 
> them that for a string literal the function is called with a length 
> argument as well.
>
>> +       error ("literal operator template %qD has invalid parameter 
>> list",
>> +              decl);
>
> Similarly, this message should say that the parameter list needs to be 
> <char...>
>
>>
>> +
>> +/* Return true if a user-defined literal operator is a raw 
>> operator.  */
>> +
>
> We don't need the extra newline before the comment.
>
> Should be ready to go with these tweaks.
>
> Jason
>
Okay,  Now I'm puzzled.

For both the raw literal and the literal template I use num_string which 
ultimately comes from build_string in tree.c line 1531.
It looks like this function null terminates the buffer - i.e. the length 
is len + 1. Yet when I have two user-defined literals in sequence the 
first sees both strings concatenated.

I'm attaching my latest patch anyway.  It has all the requested corrections.

Ed


[-- Attachment #2: udlit-raw-op.C --]
[-- Type: text/x-c++src, Size: 484 bytes --]

// LIBRARY_PATH=/usr/lib/x86_64-linux-gnu ../bin_udlit2/bin/g++ -std=c++0x -g -o raw_umber raw_umber.cpp

#include <cassert>
#include <cstring>

int
operator"" _raw_umber(const char * str)
{
  return strlen(str);
}

int
main()
{
  int i = 0123012301230123012301230123012301230123012301230123012301230123_raw_umber;
  assert( i == 64 );

  int j = 90123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789_raw_umber;
  assert( j == 101 );
}

[-- Attachment #3: patch31 --]
[-- Type: text/plain, Size: 75425 bytes --]

Index: gcc/c-family/c-lex.c
===================================================================
--- gcc/c-family/c-lex.c	(revision 180284)
+++ gcc/c-family/c-lex.c	(working copy)
@@ -44,8 +44,8 @@
 int pending_lang_change; /* If we need to switch languages - C++ only */
 int c_header_level;	 /* depth in C headers - C++ only */
 
-static tree interpret_integer (const cpp_token *, unsigned int);
-static tree interpret_float (const cpp_token *, unsigned int);
+static tree interpret_integer (const cpp_token *, unsigned int, const char *);
+static tree interpret_float (const cpp_token *, unsigned int, const char *);
 static tree interpret_fixed (const cpp_token *, unsigned int);
 static enum integer_type_kind narrowest_unsigned_type
 	(unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned int);
@@ -314,7 +314,8 @@
 
     case CPP_NUMBER:
       {
-	unsigned int flags = cpp_classify_number (parse_in, tok);
+	const char *suffix = NULL;
+	unsigned int flags = cpp_classify_number (parse_in, tok, &suffix);
 
 	switch (flags & CPP_N_CATEGORY)
 	  {
@@ -328,16 +329,27 @@
 	       Set PURE_ZERO to pass this information to the C++ parser.  */
 	    if (tok->val.str.len == 1 && *tok->val.str.text == '0')
 	      add_flags = PURE_ZERO;
-	    *value = interpret_integer (tok, flags);
+	    *value = interpret_integer (tok, flags, suffix);
 	    break;
 
 	  case CPP_N_FLOATING:
-	    *value = interpret_float (tok, flags);
+	    *value = interpret_float (tok, flags, suffix);
 	    break;
 
 	  default:
 	    gcc_unreachable ();
 	  }
+
+	if (flags & CPP_N_USERDEF)
+	  {
+	    tree num_string = build_string (tok->val.str.len - strlen (suffix),
+					    (const char *) tok->val.str.text);
+	    TREE_TYPE (num_string) = char_array_type_node;
+	    num_string = fix_string_type (num_string);
+	    tree literal = build_userdef_literal (get_identifier (suffix),
+						  *value, num_string);
+	    *value = literal;
+	  }
       }
       break;
 
@@ -415,6 +427,22 @@
       }
       goto retry;
 
+    case CPP_CHAR_USERDEF:
+    case CPP_WCHAR_USERDEF:
+    case CPP_CHAR16_USERDEF:
+    case CPP_CHAR32_USERDEF:
+      {
+	tree literal;
+	cpp_token temp_tok = *tok;
+	const char *suffix = cpp_get_userdef_suffix (tok);
+	temp_tok.val.str.len -= strlen (suffix);
+	temp_tok.type = cpp_userdef_char_remove_type (type);
+	literal = build_userdef_literal (get_identifier (suffix),
+					 lex_charconst (&temp_tok), NULL_TREE);
+	*value = literal;
+      }
+      break;
+
     case CPP_CHAR:
     case CPP_WCHAR:
     case CPP_CHAR16:
@@ -422,6 +450,22 @@
       *value = lex_charconst (tok);
       break;
 
+    case CPP_STRING_USERDEF:
+    case CPP_WSTRING_USERDEF:
+    case CPP_STRING16_USERDEF:
+    case CPP_STRING32_USERDEF:
+    case CPP_UTF8STRING_USERDEF:
+      {
+	tree literal, string;
+	const char *suffix = cpp_get_userdef_suffix (tok);
+	string = build_string (tok->val.str.len - strlen (suffix),
+			       (const char *) tok->val.str.text);
+	literal = build_userdef_literal (get_identifier (suffix),
+					 string, NULL_TREE);
+	*value = literal;
+      }
+      break;
+
     case CPP_STRING:
     case CPP_WSTRING:
     case CPP_STRING16:
@@ -536,9 +580,11 @@
   return itk_none;
 }
 
-/* Interpret TOKEN, an integer with FLAGS as classified by cpplib.  */
+/* Interpret TOKEN, an integer with FLAGS as classified by cpplib.
+   For C++0X SUFFIX may contain a user-defined literal suffix.  */
 static tree
-interpret_integer (const cpp_token *token, unsigned int flags)
+interpret_integer (const cpp_token *token, unsigned int flags,
+		   const char *suffix)
 {
   tree value, type;
   enum integer_type_kind itk;
@@ -621,9 +667,10 @@
 }
 
 /* Interpret TOKEN, a floating point number with FLAGS as classified
-   by cpplib.  */
+   by cpplib.  For C++0X SUFFIX may contain a user-defined literal suffix.  */
 static tree
-interpret_float (const cpp_token *token, unsigned int flags)
+interpret_float (const cpp_token *token, unsigned int flags,
+		 const char *suffix)
 {
   tree type;
   tree const_type;
@@ -702,7 +749,9 @@
      has any suffixes, cut them off; REAL_VALUE_ATOF/ REAL_VALUE_HTOF
      can't handle them.  */
   copylen = token->val.str.len;
-  if (flags & CPP_N_DFLOAT)
+  if (flags & CPP_N_USERDEF)
+    copylen -= strlen (suffix);
+  else if (flags & CPP_N_DFLOAT)
     copylen -= 2;
   else
     {
Index: gcc/c-family/c-common.c
===================================================================
--- gcc/c-family/c-common.c	(revision 180284)
+++ gcc/c-family/c-common.c	(working copy)
@@ -9923,4 +9923,17 @@
   MARK_TS_TYPED (EXCESS_PRECISION_EXPR);
 }
 
+/* Build a user-defined numeric literal out of an integer constant type VALUE
+   with identifier SUFFIX.  */
+
+tree
+build_userdef_literal (tree suffix_id, tree value, tree num_string)
+{
+  tree literal = make_node (USERDEF_LITERAL);
+  USERDEF_LITERAL_SUFFIX_ID (literal) = suffix_id;
+  USERDEF_LITERAL_VALUE (literal) = value;
+  USERDEF_LITERAL_NUM_STRING (literal) = num_string;
+  return literal;
+}
+
 #include "gt-c-family-c-common.h"
Index: gcc/c-family/c-common.h
===================================================================
--- gcc/c-family/c-common.h	(revision 180284)
+++ gcc/c-family/c-common.h	(working copy)
@@ -1067,4 +1067,27 @@
   return NULL;
 }
 
+/* A suffix-identifier value doublet that represents user-defined literals
+   for C++-0x.  */
+struct GTY(()) tree_userdef_literal {
+  struct tree_base base;
+  tree suffix_id;
+  tree value;
+  tree num_string;
+};
+
+#define USERDEF_LITERAL_SUFFIX_ID(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->suffix_id)
+
+#define USERDEF_LITERAL_VALUE(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->value)
+
+#define USERDEF_LITERAL_NUM_STRING(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->num_string)
+
+#define USERDEF_LITERAL_TYPE(NODE) \
+  (TREE_TYPE (USERDEF_LITERAL_VALUE (NODE)))
+
+extern tree build_userdef_literal (tree suffix_id, tree value, tree num_string);
+
 #endif /* ! GCC_C_COMMON_H */
Index: gcc/c-family/c-common.def
===================================================================
--- gcc/c-family/c-common.def	(revision 180284)
+++ gcc/c-family/c-common.def	(working copy)
@@ -47,6 +47,12 @@
    evaluated.  */
 DEFTREECODE (EXCESS_PRECISION_EXPR, "excess_precision_expr", tcc_expression, 1)
 
+/* Used to represent a user-defined literal.
+   The operands are an IDENTIFIER for the suffix, the VALUE of the literal,
+   and for numeric literals the original string representation of the
+   number.  */
+DEFTREECODE (USERDEF_LITERAL, "userdef_literal", tcc_exceptional, 3)
+
 /*
 Local variables:
 mode:c
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C	(revision 0)
@@ -0,0 +1,4 @@
+// { dg-options -std=c++0x }
+
+template<char...>
+  int operator"" _xyz(unsigned long long);	// { dg-error "has invalid argument list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit_system_header
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit_system_header	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit_system_header	(revision 0)
@@ -0,0 +1,6 @@
+
+#pragma GCC system_header
+
+char
+operator"" stdsuffix(char __c)
+{ return __c/2; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C	(revision 0)
@@ -0,0 +1,42 @@
+// { dg-options "-std=c++0x" }
+
+//  Can't have *both* literal operator template and raw literal operator.
+
+int
+operator"" _abc(const char*)
+  {
+    return 42;
+  }
+
+template<char...>
+  int
+  operator"" _abc() // { dg-error "literal operator template|conflicts with raw literal operator" }
+  {
+    return 13;
+  }
+
+template<char...>
+  int
+  operator"" _def()
+  {
+    return 12;
+  }
+
+int
+operator"" _def(const char*) // { dg-error "raw literal operator|conflicts with literal operator template" }
+  {
+    return 43;
+  }
+
+int
+operator"" _ghi(long double)
+  {
+    return 42;
+  }
+
+template<char...>
+  int
+  operator"" _ghi() // OK
+  {
+    return 13;
+  }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C	(revision 0)
@@ -0,0 +1,43 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test simple operator declaration and definition in namespaces.
+
+#include <cmath>
+#include <limits>
+
+namespace Long
+{
+  long double operator"" _LL(long double);
+}
+
+namespace Short
+{
+  short
+  operator"" _SS(long double x)
+  { return std::fmod(x, static_cast<long double>(std::numeric_limits<short>::max())); }
+}
+
+void
+test1()
+{
+  long double x = Long::operator "" _LL(1.2L);
+
+  using namespace Short;
+  short s = operator"" _SS(1.2L);
+  short s2 = 1.2_SS;
+}
+
+int
+main()
+{
+  test1();
+}
+
+namespace Long
+{
+  long double
+  operator"" _LL(long double x)
+  { return x + 2.0L; }
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-raw-op-string-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-raw-op-string-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-raw-op-string-neg.C	(revision 0)
@@ -0,0 +1,8 @@
+// { dg-options "-std=c++0x" }
+
+//  Make sure handing a string to a raw literal generates a sensible error message.
+
+int operator"" _embedraw(const char*)
+{ return 41; };
+
+int k = "Boo!"_embedraw;  //  { dg-error "invalid string literal prefix|for user-defined raw literal operator" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-embed-quote.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-embed-quote.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-embed-quote.C	(revision 0)
@@ -0,0 +1,34 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+//  Make sure embedded quotes are not a problem for string and char literals.
+
+#include <cstdint>
+#include <cassert>
+
+int operator"" _embedchar(char)
+{ return 41; };
+
+int operator"" _embedstr(const char*, std::size_t len)
+{ return 42 + len; };
+
+void
+test()
+{
+  int i = '\''_embedchar;
+
+  int j = "\""_embedstr;
+  assert(j == 43);
+
+  int k = "foo\""_embedstr;
+  assert(k == 46);
+
+  int l = "\"bar"_embedstr;
+  assert(l == 46);
+}
+
+int
+main()
+{
+  test();
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C	(revision 0)
@@ -0,0 +1,15 @@
+// { dg-options -std=c++0x }
+
+class Foo
+{
+public:
+  Foo() { }
+  int operator"" _Bar(char32_t);  // { dg-error "must be a non-member function" }
+};
+
+int i = operator"" _Bar(U'x');  // { dg-error "was not declared in this scope" }
+int j = U'x'_Bar;  // { dg-error "unable to find user-defined character literal operator" }
+
+int
+Foo::operator"" _Bar(char32_t)  // { dg-error "must be a non-member function" }
+{ return 42; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C	(revision 0)
@@ -0,0 +1,38 @@
+// { dg-options -std=c++0x }
+
+#include <cstddef>
+
+class Foo { };
+
+Foo
+operator"" _Foo(int *);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(unsigned long int);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(double);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const float *, std::size_t);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const wchar_t *, int);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const char16_t *);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(char...);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(unsigned long long int, char);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const char *, std::size_t, int);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(long double &);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(std::size_t, const char16_t *);	// { dg-error "has invalid argument list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C	(revision 0)
@@ -0,0 +1,17 @@
+// { dg-options "-std=c++98" }
+
+#include <cstddef>
+
+int
+operator"" _mm(long double m)	// { dg-warning "user-defined literals only available with" }
+{ return int(1000.0L * m); }
+
+int in = 0.0254_mm;	// { dg-error "invalid suffix" }
+
+int
+operator"" _Q(const char *, std::size_t)	// { dg-warning "user-defined literals only available with" }
+{ return 42; }
+
+int x = "Hello"_Q;	// { dg-error "invalid conversion from" }
+
+// { dg-error "expected" "" { target *-*-* } 15 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C	(revision 0)
@@ -0,0 +1,5 @@
+// { dg-options -std=c++0x }
+
+#include <string>
+
+std::string operator"" 5X(const char*, std::size_t);	// { dg-error "expected suffix identifier" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+constexpr unsigned long long
+operator"" _grow(unsigned long long n)
+{ return 2 * n; }
+
+double buffer[25_grow];
Index: gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C	(revision 0)
@@ -0,0 +1,49 @@
+// { dg-options -std=c++0x }
+
+//  Test that the standard suffixes shadow any user-defined suffixes of the same name.
+long double
+operator"" L(long double x)  // { dg-warning "floating point suffix|shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ULL(unsigned long long int k)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return k; }
+
+long double
+operator"" l(long double x)  // { dg-warning "floating point suffix|shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ull(unsigned long long int k)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return k; }
+
+//  Namespaces are no hiding place.
+namespace Long
+{
+
+long double
+operator"" L(long double x)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ULL(unsigned long long int k)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return k; }
+
+long double
+operator"" l(long double x)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ull(unsigned long long int k)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return k; }
+
+}
+
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 5 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 9 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 13 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 17 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 25 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 29 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 33 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 37 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test warning on declaration without leading underscore.
+
+long double operator"" nounder(long double); // { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" }
+
+template<char...>
+  int operator"" nounder(); // { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C	(revision 0)
@@ -0,0 +1,12 @@
+// { dg-options -std=c++0x }
+
+class Foo { };
+
+template<wchar_t...>
+  Foo operator"" _Foo(); // { dg-error "literal operator template|has invalid parameter list" }
+
+template<char>
+  Foo operator"" _Bar(); // { dg-error "literal operator template|has invalid parameter list" }
+
+template<typename... Type>
+  Foo operator"" _Bar(); // { dg-error "literal operator template|has invalid parameter list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-general.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-general.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-general.C	(revision 0)
@@ -0,0 +1,52 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test simple operator declaration and definition.
+
+#include <cstring>
+#include <string>
+#include <complex>
+#include <cassert>
+
+long double operator"" _v(long double);
+std::string operator"" _w(const char16_t*, size_t);
+unsigned operator"" _w(const char*);
+
+std::complex<double>
+operator"" _i(long double y)
+{ return std::complex<double>(0.0L, y); }
+
+void
+test1()
+{
+  long double x = operator"" _v(1.2L);
+  assert(x == 2.2L);
+
+  std::string s = operator"" _w(u"one", 3);
+  assert(s == "boo");
+
+  unsigned u = operator"" _w("Hello, World!");
+  assert(u == 13U);
+
+  std::complex<double> i = operator"" _i(2.0);
+  assert(i == std::complex<double>(0.0, 2.0));
+}
+
+int
+main()
+{
+  test1();
+}
+
+long double
+operator"" _v(long double x)
+{ return x + 1.0L; }
+
+std::string
+operator"" _w(const char16_t*, size_t)
+{ return std::string("boo"); }
+
+unsigned
+operator"" _w(const char* str)
+{ return strlen(str); }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C	(revision 0)
@@ -0,0 +1,3 @@
+// { dg-options -std=c++0x }
+
+#include "udlit_system_header"
Index: gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C	(revision 0)
@@ -0,0 +1,15 @@
+// { dg-options -std=c++0x }
+
+#include <string>
+
+std::string operator"" _i18n(const char*, std::size_t);
+
+std::string vogon_poem = R"V0G0N(
+                O freddled gruntbuggly thy micturations are to me
+                    As plured gabbleblochits on a lurgid bee.
+                 Groop, I implore thee my foonting turlingdromes.   
+              And hooptiously drangle me with crinkly bindlewurdles,
+  Or I will rend thee in the gobberwarts with my blurlecruncheon, see if I don't.
+
+                    (by Prostetnic Vogon Jeltz; see p. 56/57)
+)V0G0N"_i18n;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test error on non-function declaration.
+
+double operator"" _baddecl; // { dg-error "as non-function" }
+
+template<char...>
+  int operator"" _badtmpldecl; // { dg-error "as non-function" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-addr.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-addr.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-addr.C	(revision 0)
@@ -0,0 +1,10 @@
+// { dg-options "-std=c++0x" }
+
+#include <cstddef>
+
+bool operator"" _yn(const char*, size_t);
+
+typedef bool (*pfunk)(const char*, size_t);
+pfunk p = &operator"" _yn;
+
+bool tf = p("Hello,\0 World!", 14);
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C	(revision 0)
@@ -0,0 +1,4 @@
+// { dg-options -std=c++0x }
+
+template<char...>
+  int operator"" _abc();
Index: gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C	(revision 0)
@@ -0,0 +1,8 @@
+// { dg-options -std=c++0x }
+
+extern "C" {
+
+int
+operator"" _badclinkage(unsigned long long);	// { dg-error "operator with C linkage" }
+
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-template.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-template.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-template.C	(revision 0)
@@ -0,0 +1,51 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test template operator declaration and definition.
+
+#include <cassert>
+
+template<char...>
+  int operator"" _abc();
+
+template<>
+  int
+  operator"" _abc<>()
+  { return -1; }
+
+template<>
+  int
+  operator"" _abc<'L','U','E'>()
+  { return 42; }
+
+template<>
+  int
+  operator"" _abc<'6','6','6'>()
+  { return 21; }
+
+int
+test1()
+{
+  int i = operator"" _abc<'1','2','3'>();
+  assert(i == 45);
+  int universal_meaning = operator"" _abc<'L','U','E'>();
+  assert(universal_meaning == 42);
+  int b = operator"" _abc<'6','6','6'>();
+  int z = operator"" _abc<>();
+  assert(z == -1);
+  int j = 123_abc;
+  assert(j == i);
+  int jb = 666_abc;
+  assert(jb == b);
+}
+
+int
+main()
+{
+  test1();
+}
+
+template<char... Chars>
+  int operator"" _abc()
+  { return 42 + sizeof...(Chars); }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-args.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-args.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-args.C	(revision 0)
@@ -0,0 +1,38 @@
+// { dg-options -std=c++0x }
+
+#include <cstddef>
+
+class Foo { };
+
+Foo
+operator"" _Foo(const char *);
+
+Foo
+operator"" _Foo(unsigned long long int);
+
+Foo
+operator"" _Foo(long double);
+
+Foo
+operator"" _Foo(char);
+
+Foo
+operator"" _Foo(wchar_t);
+
+Foo
+operator"" _Foo(char16_t);
+
+Foo
+operator"" _Foo(char32_t);
+
+Foo
+operator"" _Foo(const char *, std::size_t);
+
+Foo
+operator"" _Foo(const wchar_t *, std::size_t);
+
+Foo
+operator"" _Foo(const char16_t *, std::size_t);
+
+Foo
+operator"" _Foo(const char32_t *, std::size_t);
Index: gcc/testsuite/g++.dg/cpp0x/udlit-declare-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-declare-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-declare-neg.C	(revision 0)
@@ -0,0 +1,15 @@
+// { dg-options "-std=c++0x" }
+
+//  Check that undeclared literal operator calls and literals give appropriate errors.
+
+int i = operator"" _Bar('x');  // { dg-error "was not declared in this scope" }
+int j = 'x'_Bar;  // { dg-error "unable to find user-defined character literal operator" }
+
+int ii = operator"" _BarCharStr("Howdy, Pardner!");  // { dg-error "was not declared in this scope" }
+int jj = "Howdy, Pardner!"_BarCharStr;  // { dg-error "unable to find user-defined string literal operator" }
+
+unsigned long long iULL = operator"" _BarULL(666ULL);  // { dg-error "was not declared in this scope" }
+unsigned long long jULL = 666_BarULL;  // { dg-error "unable to find user-defined numeric literal operator" }
+
+long double iLD = operator"" _BarLD(666.0L);  // { dg-error "was not declared in this scope" }
+long double jLD = 666.0_BarLD;  // { dg-error "unable to find user-defined numeric literal operator" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C	(revision 0)
@@ -0,0 +1,5 @@
+// { dg-options -std=c++0x }
+
+char32_t
+operator"" (char32_t C)	// { dg-error "expected suffix identifier" }
+{ return C; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test error on non-empty string after 'operator' keyword.
+
+double operator"hi" _badword(long double); // { dg-error "expected empty string after" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nospace-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nospace-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nospace-neg.C	(revision 0)
@@ -0,0 +1,3 @@
+// { dg-options "-std=c++0x" }
+
+float operator ""_abc(const char*); // { dg-error "missing space between|and suffix identifier" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-inline.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-inline.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-inline.C	(revision 0)
@@ -0,0 +1,22 @@
+// { dg-options "-std=c++0x" }
+
+//  Literal operators can be inline.
+
+inline int
+operator"" _thing1(char cc)
+{ return 42 * cc; }
+
+int operator"" _thing2(char cc);
+
+class Foo
+{
+  int
+  friend operator"" _thing2(char cc)
+  { return 42 * cc; }
+};
+
+int i = operator"" _thing1('x');
+int j = 'x'_thing1;
+
+int iF = operator"" _thing2('x');
+int jF = 'x'_thing2;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+extern "C"_badlinkage {	// { dg-error "expected unqualified-id before" }
+
+int foo();
+
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-friend.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-friend.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-friend.C	(revision 0)
@@ -0,0 +1,28 @@
+// { dg-options -std=c++0x }
+
+long double
+operator"" _Hertz(long double);
+
+class Foo
+{
+public:
+  Foo() { }
+
+  friend Foo operator"" _Bar(char);
+
+  friend long double
+  operator"" _Hertz(long double omega)
+  { return omega / 6.28318530717958648; }
+};
+
+Foo
+operator"" _Bar(char)
+{ return Foo(); }
+
+Foo f1 = operator"" _Bar('x');
+
+Foo f2 = 'x'_Bar;
+
+long double fm1 = operator"" _Hertz(552.92L);
+
+long double fm2 = 552.92_Hertz;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+#include <string>
+
+std::string operator"" _xxx(const char*, size_t);
+
+std::string operator"" _yyy(const char*, size_t);
+
+std::string concat = "Hello, "_xxx "World!"_yyy;	// { dg-error "inconsistent user-defined literal suffixes" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options -std=c++0x }
+
+class Foo { };
+
+template<char...>
+  Foo operator"" _Foo();
Index: gcc/testsuite/g++.dg/cpp0x/udlit-concat.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-concat.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-concat.C	(revision 0)
@@ -0,0 +1,24 @@
+// { dg-options "-std=c++0x" }
+
+#include <string>
+
+std::string operator"" _www(const char*, size_t);
+
+std::string concat01 = "Hello, " "World!"_www;
+
+std::string concat10 = "Hello, "_www "World!";
+
+std::string concat11 = "Hello, "_www "World!"_www;
+
+
+class Tachyon { };
+
+Tachyon operator"" _fast(const char*, size_t);
+
+int operator"" _fast(const char32_t*, size_t);
+
+int speedy01 = "Hello, " U"World!"_fast;
+
+int speedy10 = "Hello, "_fast U"World!";
+
+int speedy11 = "Hello, "_fast U"World!"_fast;
Index: gcc/cp/typeck.c
===================================================================
--- gcc/cp/typeck.c	(revision 180284)
+++ gcc/cp/typeck.c	(working copy)
@@ -8352,3 +8352,121 @@
   return 1;
 }
 
+/* Return true if a user-defined literal operator is a raw operator.  */
+
+bool
+check_raw_literal_operator (const_tree decl)
+{
+  tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
+  tree argtype;
+  int arity;
+  bool maybe_raw_p = false;
+
+  /* Count the number and type of arguments and check for ellipsis.  */
+  for (argtype = argtypes, arity = 0;
+       argtype && argtype != void_list_node;
+       ++arity, argtype = TREE_CHAIN (argtype))
+    {
+      tree t = TREE_VALUE (argtype);
+
+      if (same_type_p (t, const_string_type_node))
+	maybe_raw_p = true;
+    }
+  if (!argtype)
+    return false; /* Found ellipsis.  */
+
+  if (!maybe_raw_p || arity != 1)
+    return false;
+
+  return true;
+}
+
+
+/* Return true if a user-defined literal operator has one of the allowed
+   argument types.  */
+
+bool
+check_literal_operator_args (const_tree decl,
+			     bool *long_long_unsigned_p, bool *long_double_p)
+{
+  tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
+  if (processing_template_decl)
+    return (argtypes == NULL_TREE
+	    || same_type_p (TREE_VALUE (argtypes), void_type_node));
+  else
+    {
+      tree argtype;
+      int arity;
+      int max_arity = 2;
+      bool found_string_p = false;
+      bool maybe_raw_p = false;
+      bool found_size_p = false;
+      tree const_wchar_ptr_type_node
+	   = build_pointer_type (build_type_variant (wchar_type_node, 1, 0));
+      tree const_char16_ptr_type_node
+	   = build_pointer_type (build_type_variant (char16_type_node, 1, 0));
+      tree const_char32_ptr_type_node
+	   = build_pointer_type (build_type_variant (char32_type_node, 1, 0));
+
+      *long_long_unsigned_p = false;
+      *long_double_p = false;
+
+      /* Count the number and type of arguments and check for ellipsis.  */
+      for (argtype = argtypes, arity = 0;
+	   argtype && argtype != void_list_node;
+	   argtype = TREE_CHAIN (argtype))
+	{
+	  tree t = TREE_VALUE (argtype);
+	  ++arity;
+
+	  if (same_type_p (t, const_string_type_node))
+	    {
+	      found_string_p = true;
+	      maybe_raw_p = true;
+	    }
+	  else if (same_type_p (t, const_wchar_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, const_char16_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, const_char32_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, size_type_node))
+	    {
+	      if (!found_string_p)
+		return false;
+	      found_size_p = true;
+	    }
+	  else if (same_type_p (t, long_long_unsigned_type_node))
+	    {
+	      max_arity = 1;
+	      *long_long_unsigned_p = true;
+	    }
+	  else if (same_type_p (t, long_double_type_node))
+	    {
+	      max_arity = 1;
+	      *long_double_p = true;
+	    }
+	  else if (same_type_p (t, char_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, wchar_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, char16_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, char32_type_node))
+	    max_arity = 1;
+	  else
+	    return false;
+	}
+      if (!argtype)
+	return false; /* Found ellipsis.  */
+
+      if (arity > max_arity)
+	return false;
+
+      if (found_string_p && !maybe_raw_p && !found_size_p)
+	return false;
+
+      return true;
+    }
+}
+
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 180284)
+++ gcc/cp/decl.c	(working copy)
@@ -1203,6 +1203,21 @@
       || TREE_TYPE (olddecl) == error_mark_node)
     return error_mark_node;
 
+  if (UDLIT_OPER_P (DECL_NAME (newdecl))
+      && UDLIT_OPER_P (DECL_NAME (olddecl)))
+    {
+      if (TREE_CODE (newdecl) == TEMPLATE_DECL
+	  && TREE_CODE (olddecl) != TEMPLATE_DECL
+	  && check_raw_literal_operator (olddecl))
+	error ("literal operator template %q+D conflicts with"
+	       " raw literal operator %qD", newdecl, olddecl);
+      else if (TREE_CODE (newdecl) != TEMPLATE_DECL
+	       && TREE_CODE (olddecl) == TEMPLATE_DECL
+	       && check_raw_literal_operator (newdecl))
+	error ("raw literal operator %q+D conflicts with"
+	       " literal operator template %qD", newdecl, olddecl);
+    }
+
   if (DECL_P (olddecl)
       && TREE_CODE (newdecl) == FUNCTION_DECL
       && TREE_CODE (olddecl) == FUNCTION_DECL
@@ -7343,7 +7358,48 @@
   if (IDENTIFIER_OPNAME_P (DECL_NAME (decl))
       && !grok_op_properties (decl, /*complain=*/true))
     return NULL_TREE;
+  else if (UDLIT_OPER_P (DECL_NAME (decl)))
+    {
+      bool long_long_unsigned_p;
+      bool long_double_p;
+      const char *suffix = NULL;
+      /* [over.literal]/6: Literal operators shall not have C linkage. */
+      if (DECL_LANGUAGE (decl) == lang_c)
+	{
+	  error ("literal operator with C linkage");
+	  return NULL_TREE;
+	}
 
+      if (DECL_NAMESPACE_SCOPE_P (decl))
+	{
+	  if (!check_literal_operator_args (decl, &long_long_unsigned_p,
+					    &long_double_p))
+	    {
+	      error ("%qD has invalid argument list", decl);
+	      return NULL_TREE;
+	    }
+
+	  suffix = UDLIT_OP_SUFFIX (DECL_NAME (decl));
+	  if (long_long_unsigned_p)
+	    {
+	      if (cpp_interpret_int_suffix (suffix, strlen (suffix)))
+		warning (0, "integer suffix %<%s%>"
+			    " shadowed by implementation", suffix);
+	    }
+	  else if (long_double_p)
+	    {
+	      if (cpp_interpret_float_suffix (suffix, strlen (suffix)))
+		warning (0, "floating point suffix %<%s%>"
+			    " shadowed by implementation", suffix);
+	    }
+	}
+      else
+	{
+	  error ("%qD must be a non-member function", decl);
+	  return NULL_TREE;
+	}
+    }
+
   if (funcdef_flag)
     /* Make the init_value nonzero so pushdecl knows this is not
        tentative.  error_mark_node is replaced later with the BLOCK.  */
@@ -8534,6 +8590,15 @@
       error ("declaration of %qD as non-function", dname);
       return error_mark_node;
     }
+ 
+  if (dname
+      && TREE_CODE (dname) == IDENTIFIER_NODE
+      && UDLIT_OPER_P (dname)
+      && innermost_code != cdk_function)
+    {
+      error ("declaration of %qD as non-function", dname);
+      return error_mark_node;
+    }
 
   if (dname && IDENTIFIER_OPNAME_P (dname))
     {
@@ -13752,6 +13817,7 @@
     case TRAIT_EXPR:		return TS_CP_TRAIT_EXPR;
     case LAMBDA_EXPR:		return TS_CP_LAMBDA_EXPR;
     case TEMPLATE_INFO:		return TS_CP_TEMPLATE_INFO;
+    case USERDEF_LITERAL:	return TS_CP_USERDEF_LITERAL;
     default:			return TS_CP_GENERIC;
     }
 }
Index: gcc/cp/error.c
===================================================================
--- gcc/cp/error.c	(revision 180284)
+++ gcc/cp/error.c	(working copy)
@@ -1534,6 +1534,8 @@
     }
   else if (name && IDENTIFIER_OPNAME_P (name))
     pp_cxx_tree_identifier (cxx_pp, name);
+  else if (name && UDLIT_OPER_P (name))
+    pp_cxx_tree_identifier (cxx_pp, name);
   else
     dump_decl (name, flags);
 
@@ -1756,6 +1758,10 @@
       pp_constant (cxx_pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (cxx_pp, t);
+      break;
+
     case THROW_EXPR:
       /* While waiting for caret diagnostics, avoid printing
 	 __cxa_allocate_exception, __cxa_throw, and the like.  */
@@ -3233,7 +3239,7 @@
 	pedwarn (input_location, OPT_pedantic,
 		 "inline namespaces "
 		 "only available with -std=c++0x or -std=gnu++0x");
-	break;	
+	break;
       case CPP0X_OVERRIDE_CONTROLS:
 	pedwarn (input_location, 0,
 		 "override controls (override/final) "
@@ -3244,8 +3250,13 @@
 		 "non-static data member initializers "
 		 "only available with -std=c++0x or -std=gnu++0x");
         break;
+      case CPP0X_USER_DEFINED_LITERALS:
+	pedwarn (input_location, 0,
+		 "user-defined literals "
+		 "only available with -std=c++0x or -std=gnu++0x");
+	break;
       default:
-	gcc_unreachable();
+	gcc_unreachable ();
       }
 }
 
Index: gcc/cp/cxx-pretty-print.c
===================================================================
--- gcc/cp/cxx-pretty-print.c	(revision 180284)
+++ gcc/cp/cxx-pretty-print.c	(working copy)
@@ -367,6 +367,17 @@
     pp_cxx_unqualified_id (pp, t);
 }
 
+/* user-defined literal:
+      literal ud-suffix  */
+
+void
+pp_cxx_userdef_literal (cxx_pretty_printer *pp, tree t)
+{
+  pp_cxx_constant (pp, USERDEF_LITERAL_VALUE (t));
+  pp_cxx_id_expression (pp, USERDEF_LITERAL_SUFFIX_ID (t));
+}
+
+
 /* primary-expression:
      literal
      this
@@ -413,6 +424,10 @@
       pp_cxx_constant (pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (pp, t);
+      break;
+
     case BASELINK:
       t = BASELINK_FUNCTIONS (t);
     case VAR_DECL:
@@ -1024,6 +1039,10 @@
       pp_cxx_constant (pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (pp, t);
+      break;
+
     case RESULT_DECL:
       pp_cxx_unqualified_id (pp, t);
       break;
Index: gcc/cp/semantics.c
===================================================================
--- gcc/cp/semantics.c	(revision 180284)
+++ gcc/cp/semantics.c	(working copy)
@@ -7865,6 +7865,7 @@
     case TEMPLATE_PARM_INDEX:
     case TRAIT_EXPR:
     case IDENTIFIER_NODE:
+    case USERDEF_LITERAL:
       /* We can see a FIELD_DECL in a pointer-to-member expression.  */
     case FIELD_DECL:
     case PARM_DECL:
Index: gcc/cp/cxx-pretty-print.h
===================================================================
--- gcc/cp/cxx-pretty-print.h	(revision 180284)
+++ gcc/cp/cxx-pretty-print.h	(working copy)
@@ -74,5 +74,7 @@
 void pp_cxx_trait_expression (cxx_pretty_printer *, tree);
 void pp_cxx_va_arg_expression (cxx_pretty_printer *, tree);
 void pp_cxx_offsetof_expression (cxx_pretty_printer *, tree);
+void pp_cxx_userdef_literal (cxx_pretty_printer *, tree);
 
+
 #endif /* GCC_CXX_PRETTY_PRINT_H */
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 180284)
+++ gcc/cp/parser.c	(working copy)
@@ -210,6 +210,8 @@
   (cp_lexer *);
 static void cp_lexer_rollback_tokens
   (cp_lexer *);
+static tree cp_literal_operator_id
+  (const char *);
 static void cp_lexer_print_token
   (FILE *, cp_token *);
 static inline bool cp_lexer_debugging_p
@@ -1762,6 +1764,12 @@
   (cp_parser *);
 static tree cp_parser_string_literal
   (cp_parser *, bool, bool);
+static tree cp_parser_userdef_char_literal
+  (cp_parser *);
+static tree cp_parser_userdef_string_literal
+  (cp_token *);
+static tree cp_parser_userdef_numeric_literal
+  (cp_parser *);
 
 /* Basic concepts [gram.basic]  */
 
@@ -2270,6 +2278,8 @@
   (cp_parser *);
 static bool cp_parser_allow_gnu_extensions_p
   (cp_parser *);
+static bool cp_parser_is_pure_string_literal
+  (cp_token *);
 static bool cp_parser_is_string_literal
   (cp_token *);
 static bool cp_parser_is_keyword
@@ -2290,7 +2300,7 @@
 /* Returns nonzero if TOKEN is a string literal.  */
 
 static bool
-cp_parser_is_string_literal (cp_token* token)
+cp_parser_is_pure_string_literal (cp_token* token)
 {
   return (token->type == CPP_STRING ||
 	  token->type == CPP_STRING16 ||
@@ -2299,6 +2309,20 @@
 	  token->type == CPP_UTF8STRING);
 }
 
+/* Returns nonzero if TOKEN is a string literal
+   of a user-defined string literal.  */
+
+static bool
+cp_parser_is_string_literal (cp_token* token)
+{
+  return (cp_parser_is_pure_string_literal (token) ||
+	  token->type == CPP_STRING_USERDEF ||
+	  token->type == CPP_STRING16_USERDEF ||
+	  token->type == CPP_STRING32_USERDEF ||
+	  token->type == CPP_WSTRING_USERDEF ||
+	  token->type == CPP_UTF8STRING_USERDEF);
+}
+
 /* Returns nonzero if TOKEN is the indicated KEYWORD.  */
 
 static bool
@@ -3338,7 +3362,11 @@
   struct obstack str_ob;
   cpp_string str, istr, *strs;
   cp_token *tok;
-  enum cpp_ttype type;
+  enum cpp_ttype type, curr_type;
+  int have_suffix_p = 0;
+  tree string_tree;
+  tree suffix_id = NULL_TREE;
+  bool curr_tok_is_userdef_p = false;
 
   tok = cp_lexer_peek_token (parser->lexer);
   if (!cp_parser_is_string_literal (tok))
@@ -3347,7 +3375,18 @@
       return error_mark_node;
     }
 
-  type = tok->type;
+  if (cpp_userdef_string_p (tok->type))
+    {
+      string_tree = USERDEF_LITERAL_VALUE (tok->u.value);
+      curr_type = cpp_userdef_string_remove_type (tok->type);
+      curr_tok_is_userdef_p = true;
+    }
+  else
+    {
+      string_tree = tok->u.value;
+      curr_type = tok->type;
+    }
+  type = curr_type;
 
   /* Try to avoid the overhead of creating and destroying an obstack
      for the common case of just one string.  */
@@ -3356,10 +3395,19 @@
     {
       cp_lexer_consume_token (parser->lexer);
 
-      str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value);
-      str.len = TREE_STRING_LENGTH (tok->u.value);
+      str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree);
+      str.len = TREE_STRING_LENGTH (string_tree);
       count = 1;
 
+      if (curr_tok_is_userdef_p)
+	{
+	  suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value);
+	  have_suffix_p = 1;
+	  curr_type = cpp_userdef_string_remove_type (tok->type);
+	}
+      else
+	curr_type = tok->type;
+
       strs = &str;
     }
   else
@@ -3371,14 +3419,35 @@
 	{
 	  cp_lexer_consume_token (parser->lexer);
 	  count++;
-	  str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value);
-	  str.len = TREE_STRING_LENGTH (tok->u.value);
+	  str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree);
+	  str.len = TREE_STRING_LENGTH (string_tree);
 
-	  if (type != tok->type)
+	  if (curr_tok_is_userdef_p)
 	    {
+	      tree curr_suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value);
+	      if (have_suffix_p == 0)
+		{
+		  suffix_id = curr_suffix_id;
+		  have_suffix_p = 1;
+		}
+	      else if (have_suffix_p == 1
+		       && curr_suffix_id != suffix_id)
+		{
+		  error ("inconsistent user-defined literal suffixes"
+			 " %qD and %qD in string literal",
+			 suffix_id, curr_suffix_id);
+		  have_suffix_p = -1;
+		}
+	      curr_type = cpp_userdef_string_remove_type (tok->type);
+	    }
+	  else
+	    curr_type = tok->type;
+
+	  if (type != curr_type)
+	    {
 	      if (type == CPP_STRING)
-		type = tok->type;
-	      else if (tok->type != CPP_STRING)
+		type = curr_type;
+	      else if (curr_type != CPP_STRING)
 		error_at (tok->location,
 			  "unsupported non-standard concatenation "
 			  "of string literals");
@@ -3387,6 +3456,18 @@
 	  obstack_grow (&str_ob, &str, sizeof (cpp_string));
 
 	  tok = cp_lexer_peek_token (parser->lexer);
+	  if (cpp_userdef_string_p (tok->type))
+	    {
+	      string_tree = USERDEF_LITERAL_VALUE (tok->u.value);
+	      curr_type = cpp_userdef_string_remove_type (tok->type);
+	      curr_tok_is_userdef_p = true;
+	    }
+	  else
+	    {
+	      string_tree = tok->u.value;
+	      curr_type = tok->type;
+	      curr_tok_is_userdef_p = false;
+	    }
 	}
       while (cp_parser_is_string_literal (tok));
 
@@ -3424,6 +3505,13 @@
 	}
 
       value = fix_string_type (value);
+
+      if (have_suffix_p)
+	{
+	  tree literal = build_userdef_literal (suffix_id, value, NULL_TREE);
+	  tok->u.value = literal;
+	  return cp_parser_userdef_string_literal (tok);
+	}
     }
   else
     /* cpp_interpret_string has issued an error.  */
@@ -3435,7 +3523,188 @@
   return value;
 }
 
+/* Parse a user-defined char constant.  Returns a call to a user-defined
+   literal operator taking the character as an argument.  */
 
+static tree
+cp_parser_userdef_char_literal (cp_parser *parser)
+{
+  cp_token *token = NULL;
+  tree literal, suffix_id, value;
+  tree name, decl;
+  tree result;
+  VEC(tree,gc) *vec;
+
+  token = cp_lexer_consume_token (parser->lexer);
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  value = USERDEF_LITERAL_VALUE (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  vec = make_tree_vector ();
+  VEC_safe_push (tree, gc, vec, value);
+  decl = lookup_function_nonclass (name, vec, /*block_p=*/false);
+  if (!decl || decl == error_mark_node)
+    {
+      error ("unable to find user-defined character literal operator %qD",
+	     name);
+      release_tree_vector (vec);
+      return error_mark_node;
+    }
+  result = finish_call_expr (decl, &vec, false, true, tf_warning_or_error);
+  release_tree_vector (vec);
+
+  return result;
+}
+
+/* A subroutine of cp_parser_userdef_numeric_literal to
+   create a char... template parameter pack from a string node.  */
+
+static tree
+make_char_string_pack (tree value)
+{
+  tree charvec;
+  tree argpack = make_node (NONTYPE_ARGUMENT_PACK);
+  const char *str = TREE_STRING_POINTER (value);
+  int i, len = TREE_STRING_LENGTH (value);
+  /*  Do I need to stuff THIS into a tree? */
+  tree argvec = make_tree_vec (1);
+
+  /* Fill in CHARVEC with all of the parameters.  */
+  charvec = make_tree_vec (len);
+  for (i = 0; i < len; ++i)
+    TREE_VEC_ELT (charvec, i) = build_int_cst (char_type_node, str[i]);
+
+  /* Build the argument packs.  */
+  SET_ARGUMENT_PACK_ARGS (argpack, charvec);
+  TREE_TYPE (argpack) = char_type_node;
+
+  TREE_VEC_ELT (argvec, 0) = argpack;
+
+  return argvec;
+}
+
+/* Parse a user-defined numeric constant.  returns a call to a user-defined
+   literal operator.  */
+
+static tree
+cp_parser_userdef_numeric_literal (cp_parser *parser)
+{
+  cp_token *token = NULL;
+  tree literal, suffix_id, value, num_string;
+  tree name, decl;
+  tree result = error_mark_node;
+  VEC(tree,gc) *args;
+
+  token = cp_lexer_consume_token (parser->lexer);
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  value = USERDEF_LITERAL_VALUE (literal);
+  num_string = USERDEF_LITERAL_NUM_STRING (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  /* Try to find the literal operator by finishing the call expression
+     with the numeric argument.  */
+  args = make_tree_vector ();
+  VEC_safe_push (tree, gc, args, value);
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl && decl != error_mark_node)
+    {
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  /* If the numeric argument didn't work, look for a raw literal
+     operator taking a const char* argument consisting of the number
+     in string format.  */
+  args = make_tree_vector ();
+  VEC_safe_push (tree, gc, args, num_string);
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl && decl != error_mark_node)
+    {
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  /* If the raw literal didn't work, look for a non-type template
+     function with parameter pack char....  Call the function with
+     template parameter characters representing the number.  */
+  args = make_tree_vector ();
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl && decl != error_mark_node)
+    {
+      tree tmpl_args = make_char_string_pack (num_string);
+      decl = lookup_template_function (decl, tmpl_args);
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  if (result == error_mark_node)
+    error ("unable to find user-defined numeric literal operator %qD", name);
+
+  return result;
+}
+
+/* Parse a user-defined string constant.  Returns a call to a user-defined
+   literal operator taking a character pointer and the length of the string
+   as arguments.  */
+static tree
+cp_parser_userdef_string_literal (cp_token *token)
+{
+  tree literal, suffix_id, value;
+  tree name, decl;
+  tree result;
+  VEC(tree,gc) *vec;
+  int len;
+
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+  value = USERDEF_LITERAL_VALUE (literal);
+  len = TREE_STRING_LENGTH (value) - 1;
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  vec = make_tree_vector ();
+  VEC_safe_push (tree, gc, vec, value);
+  VEC_safe_push (tree, gc, vec, build_int_cst (size_type_node, len));
+  decl = lookup_function_nonclass (name, vec, /*block_p=*/false);
+  if (!decl || decl == error_mark_node)
+    {
+      error ("unable to find user-defined string literal operator %qD", name);
+      release_tree_vector (vec);
+      return error_mark_node;
+    }
+  result = finish_call_expr (decl, &vec, false, true, tf_none);
+  if (result == error_mark_node)
+    error ("invalid string literal prefix %<\"%s\"%> for user-defined"
+	   " raw literal operator %qD.  Remove quotes.",
+	   TREE_STRING_POINTER (value), name);
+  release_tree_vector (vec);
+
+  return result;
+}
+
+
 /* Basic concepts [gram.basic]  */
 
 /* Parse a translation-unit.
@@ -3578,12 +3847,16 @@
 	   character-literal
 	   floating-literal
 	   string-literal
-	   boolean-literal  */
+	   boolean-literal
+	   pointer-literal
+	   user-defined-literal  */
     case CPP_CHAR:
     case CPP_CHAR16:
     case CPP_CHAR32:
     case CPP_WCHAR:
     case CPP_NUMBER:
+      if (TREE_CODE (token->u.value) == USERDEF_LITERAL)
+	return cp_parser_userdef_numeric_literal (parser);
       token = cp_lexer_consume_token (parser->lexer);
       if (TREE_CODE (token->u.value) == FIXED_CST)
 	{
@@ -3637,11 +3910,22 @@
 	}
       return token->u.value;
 
+    case CPP_CHAR_USERDEF:
+    case CPP_CHAR16_USERDEF:
+    case CPP_CHAR32_USERDEF:
+    case CPP_WCHAR_USERDEF:
+      return cp_parser_userdef_char_literal (parser);
+
     case CPP_STRING:
     case CPP_STRING16:
     case CPP_STRING32:
     case CPP_WSTRING:
     case CPP_UTF8STRING:
+    case CPP_STRING_USERDEF:
+    case CPP_STRING16_USERDEF:
+    case CPP_STRING32_USERDEF:
+    case CPP_WSTRING_USERDEF:
+    case CPP_UTF8STRING_USERDEF:
       /* ??? Should wide strings be allowed when parser->translate_strings_p
 	 is false (i.e. in attributes)?  If not, we can kill the third
 	 argument to cp_parser_string_literal.  */
@@ -4477,6 +4761,14 @@
 	  /* If that didn't work, try a conversion-function-id.  */
 	  if (!cp_parser_parse_definitely (parser))
 	    id = cp_parser_conversion_function_id (parser);
+	  else if (UDLIT_OPER_P (id))
+	    {
+	      /* 17.6.3.3.5  */
+	      const char *name = UDLIT_OP_SUFFIX (id);
+	      if (name[0] != '_' && !in_system_header)
+		warning (0, "literal operator suffixes not preceded by %<_%>"
+			    " are reserved for future standardization");
+	    }
 
 	  return id;
 	}
@@ -5119,7 +5411,7 @@
 	/* Restore the saved message.  */
 	parser->type_definition_forbidden_message = saved_message;
 	/* `typeid' may not appear in an integral constant expression.  */
-	if (cp_parser_non_integral_constant_expression(parser, NIC_TYPEID))
+	if (cp_parser_non_integral_constant_expression (parser, NIC_TYPEID))
 	  return error_mark_node;
       }
       break;
@@ -9739,7 +10031,7 @@
   /* If the next token is `extern' and the following token is a string
      literal, then we have a linkage specification.  */
   if (token1.keyword == RID_EXTERN
-      && cp_parser_is_string_literal (&token2))
+      && cp_parser_is_pure_string_literal (&token2))
     cp_parser_linkage_specification (parser);
   /* If the next token is `template', then we have either a template
      declaration, an explicit instantiation, or an explicit
@@ -11170,6 +11462,22 @@
   return cp_parser_operator (parser);
 }
 
+/* Return an identifier node for a user-defined literal operator.
+   The suffix identifier is chained to the operator name identifier.  */
+
+static tree
+cp_literal_operator_id (const char* name)
+{
+  tree identifier;
+  char *buffer = XNEWVEC (char, strlen (UDLIT_OP_ANSI_PREFIX)
+			      + strlen (name) + 10);
+  sprintf (buffer, UDLIT_OP_ANSI_FORMAT, name);
+  identifier = get_identifier (buffer);
+  /*IDENTIFIER_UDLIT_OPNAME_P (identifier) = 1; If we get a flag someday. */
+
+  return identifier;
+}
+
 /* Parse an operator.
 
    operator:
@@ -11389,6 +11697,37 @@
       cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE);
       return ansi_opname (ARRAY_REF);
 
+    case CPP_STRING:
+      if (cxx_dialect == cxx98)
+	maybe_warn_cpp0x (CPP0X_USER_DEFINED_LITERALS);
+      if (TREE_STRING_LENGTH (token->u.value) > 2)
+	{
+	  error ("expected empty string after %<operator%> keyword");
+	  return error_mark_node;
+	}
+      /* Consume the string.  */
+      cp_lexer_consume_token (parser->lexer);
+      /* Look for the suffix identifier.  */
+      token = cp_lexer_peek_token (parser->lexer);
+      if (token->type == CPP_NAME)
+	{
+	  id = cp_parser_identifier (parser);
+	  if (id != error_mark_node)
+	    {
+	      const char *name = IDENTIFIER_POINTER (id);
+	      return cp_literal_operator_id (name);
+	    }
+	}
+      else
+	{
+	  error ("expected suffix identifier");
+	  return error_mark_node;
+	}
+
+    case CPP_STRING_USERDEF:
+      error ("missing space between %<\"\"%> and suffix identifier");
+      return error_mark_node;
+
     default:
       /* Anything else is an error.  */
       break;
@@ -20583,6 +20922,33 @@
   /* Finish up.  */
   finish_template_decl (parameter_list);
 
+  /* Check the template arguments for a literal operator template.  */
+  if (decl
+      && (TREE_CODE (decl) == FUNCTION_DECL || DECL_FUNCTION_TEMPLATE_P (decl))
+      && UDLIT_OPER_P (DECL_NAME (decl)))
+    {
+      bool ok = true;
+      if (parameter_list == NULL_TREE)
+	ok = false;
+      else
+	{
+	  int num_parms = TREE_VEC_LENGTH (parameter_list);
+	  if (num_parms != 1)
+	    ok = false;
+	  else
+	    {
+	      tree parm_list = TREE_VEC_ELT (parameter_list, 0);
+	      tree parm = INNERMOST_TEMPLATE_PARMS (parm_list);
+	      if (TREE_TYPE (parm) != char_type_node
+		  || !TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (parm)))
+		ok = false;
+	    }
+	}
+      if (!ok)
+	error ("literal operator template %qD has invalid parameter list."
+	       "  Expected non-type template argument pack <char...>",
+	       decl);
+    }
   /* Register member declarations.  */
   if (member_p && !friend_p && decl && !DECL_CLASS_TEMPLATE_P (decl))
     finish_member_declaration (decl);
@@ -22891,7 +23257,8 @@
   /* If the next token is `extern' and the following token is a string
      literal, then we have a linkage specification.  */
   if (token->keyword == RID_EXTERN
-      && cp_parser_is_string_literal (cp_lexer_peek_nth_token (parser->lexer, 2)))
+      && cp_parser_is_pure_string_literal
+	 (cp_lexer_peek_nth_token (parser->lexer, 2)))
     cp_parser_linkage_specification (parser);
   /* Handle #pragma, if any.  */
   else if (token->type == CPP_PRAGMA)
Index: gcc/cp/cp-objcp-common.c
===================================================================
--- gcc/cp/cp-objcp-common.c	(revision 180284)
+++ gcc/cp/cp-objcp-common.c	(working copy)
@@ -100,6 +100,8 @@
 
     case TEMPLATE_INFO:         return sizeof (struct tree_template_info);
 
+    case USERDEF_LITERAL:	return sizeof (struct tree_userdef_literal);
+
     default:
       gcc_unreachable ();
     }
Index: gcc/cp/mangle.c
===================================================================
--- gcc/cp/mangle.c	(revision 180284)
+++ gcc/cp/mangle.c	(working copy)
@@ -181,6 +181,7 @@
 static void write_unqualified_name (const tree);
 static void write_conversion_operator_name (const tree);
 static void write_source_name (tree);
+static void write_literal_operator_name (tree);
 static void write_unnamed_type_name (const tree);
 static void write_closure_type_name (const tree);
 static int hwint_to_ascii (unsigned HOST_WIDE_INT, const unsigned int, char *,
@@ -1174,6 +1175,8 @@
 	  }
       write_string (mangled_name);
     }
+  else if (UDLIT_OPER_P (identifier))
+    write_literal_operator_name (identifier);
   else
     write_source_name (identifier);
 }
@@ -1227,6 +1230,8 @@
 
 	  write_string (oni[DECL_OVERLOADED_OPERATOR_P (decl)].mangled_name);
 	}
+      else if (UDLIT_OPER_P (DECL_NAME (decl)))
+	write_literal_operator_name (DECL_NAME (decl));
       else
 	found = false;
 
@@ -1286,6 +1291,21 @@
   write_identifier (IDENTIFIER_POINTER (identifier));
 }
 
+/* Write a user-defined literal operator.
+   IDENTIFIER is an LITERAL_IDENTIFIER_NODE.  */
+
+static void
+write_literal_operator_name (tree identifier)
+{
+  const char* suffix = UDLIT_OP_SUFFIX (identifier);
+  char* buffer = XNEWVEC (char, strlen (UDLIT_OP_MANGLED_PREFIX)
+			      + strlen (suffix) + 10);
+  sprintf (buffer, UDLIT_OP_MANGLED_FORMAT, suffix);
+
+  write_unsigned_number (strlen (buffer));
+  write_identifier (buffer);
+}
+
 /* Encode 0 as _, and 1+ as n-1_.  */
 
 static void
Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h	(revision 180284)
+++ gcc/cp/cp-tree.h	(working copy)
@@ -400,7 +400,9 @@
   /* override controls, override/final */
   CPP0X_OVERRIDE_CONTROLS,
   /* non-static data member initializers */
-  CPP0X_NSDMI
+  CPP0X_NSDMI,
+  /* user defined literals */
+  CPP0X_USER_DEFINED_LITERALS
 } cpp0x_warn_str;
   
 /* The various kinds of operation used by composite_pointer_type. */
@@ -740,6 +742,7 @@
   TS_CP_TRAIT_EXPR,
   TS_CP_LAMBDA_EXPR,
   TS_CP_TEMPLATE_INFO,
+  TS_CP_USERDEF_LITERAL,
   LAST_TS_CP_ENUM
 };
 
@@ -765,6 +768,8 @@
     lambda_expression;
   struct tree_template_info GTY ((tag ("TS_CP_TEMPLATE_INFO")))
     template_info;
+  struct tree_userdef_literal GTY ((tag ("TS_CP_USERDEF_LITERAL")))
+    userdef_literal;
 };
 
 \f
@@ -4228,6 +4233,17 @@
              LAMBDANAME_PREFIX, \
 	     sizeof (LAMBDANAME_PREFIX) - 1))
 
+#define UDLIT_OP_ANSI_PREFIX "operator\"\" "
+#define UDLIT_OP_ANSI_FORMAT UDLIT_OP_ANSI_PREFIX "%s"
+#define UDLIT_OP_MANGLED_PREFIX "li"
+#define UDLIT_OP_MANGLED_FORMAT UDLIT_OP_MANGLED_PREFIX "%s"
+#define UDLIT_OPER_P(ID_NODE) \
+  (!strncmp (IDENTIFIER_POINTER (ID_NODE), \
+             UDLIT_OP_ANSI_PREFIX, \
+	     sizeof (UDLIT_OP_ANSI_PREFIX) - 1))
+#define UDLIT_OP_SUFFIX(ID_NODE) \
+  (IDENTIFIER_POINTER (ID_NODE) + sizeof (UDLIT_OP_ANSI_PREFIX) - 1)
+
 #if !defined(NO_DOLLAR_IN_LABEL) || !defined(NO_DOT_IN_LABEL)
 
 #define VTABLE_NAME_P(ID_NODE) (IDENTIFIER_POINTER (ID_NODE)[1] == 'v' \
@@ -5758,6 +5774,8 @@
 extern int lvalue_or_else			(tree, enum lvalue_use,
                                                  tsubst_flags_t);
 extern void check_template_keyword		(tree);
+extern bool check_raw_literal_operator		(const_tree decl);
+extern bool check_literal_operator_args		(const_tree, bool *, bool *);
 
 /* in typeck2.c */
 extern void require_complete_eh_spec_types	(tree, tree);
Index: libcpp/include/cpplib.h
===================================================================
--- libcpp/include/cpplib.h	(revision 180284)
+++ libcpp/include/cpplib.h	(working copy)
@@ -131,6 +131,16 @@
   TK(OBJC_STRING,	LITERAL) /* @"string" - Objective-C */		\
   TK(HEADER_NAME,	LITERAL) /* <stdio.h> in #include */		\
 									\
+  TK(CHAR_USERDEF,	LITERAL) /* 'char'_suffix - C++-0x */		\
+  TK(WCHAR_USERDEF,	LITERAL) /* L'char'_suffix - C++-0x */		\
+  TK(CHAR16_USERDEF,	LITERAL) /* u'char'_suffix - C++-0x */		\
+  TK(CHAR32_USERDEF,	LITERAL) /* U'char'_suffix - C++-0x */		\
+  TK(STRING_USERDEF,	LITERAL) /* "string"_suffix - C++-0x */		\
+  TK(WSTRING_USERDEF,	LITERAL) /* L"string"_suffix - C++-0x */	\
+  TK(STRING16_USERDEF,	LITERAL) /* u"string"_suffix - C++-0x */	\
+  TK(STRING32_USERDEF,	LITERAL) /* U"string"_suffix - C++-0x */	\
+  TK(UTF8STRING_USERDEF,LITERAL) /* u8"string"_suffix - C++-0x */	\
+									\
   TK(COMMENT,		LITERAL) /* Only if output comments.  */	\
 				 /* SPELL_LITERAL happens to DTRT.  */	\
   TK(MACRO_ARG,		NONE)	 /* Macro argument.  */			\
@@ -414,6 +424,9 @@
   /* True for traditional preprocessing.  */
   unsigned char traditional;
 
+  /* Nonzero for C++ 2011 Standard user-defnied literals.  */
+  unsigned char user_literals;
+
   /* Holds the name of the target (execution) character set.  */
   const char *narrow_charset;
 
@@ -829,13 +842,22 @@
 #define CPP_N_FRACT	0x100000 /* Fract types.  */
 #define CPP_N_ACCUM	0x200000 /* Accum types.  */
 
+#define CPP_N_USERDEF	0x1000000 /* C++0x user-defined literal.  */
+
 /* Classify a CPP_NUMBER token.  The return value is a combination of
    the flags from the above sets.  */
-extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *);
+extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *,
+				     const char **);
 
+/* Return the classification flags for a float suffix.  */
+extern unsigned int cpp_interpret_float_suffix (const char *, size_t);
+
+/* Return the classification flags for an int suffix.  */
+extern unsigned int cpp_interpret_int_suffix (const char *, size_t);
+
 /* Evaluate a token classified as category CPP_N_INTEGER.  */
 extern cpp_num cpp_interpret_integer (cpp_reader *, const cpp_token *,
-				      unsigned int type);
+				      unsigned int);
 
 /* Sign extend a number, with PRECISION significant bits and all
    others assumed clear, to fill out a cpp_num structure.  */
@@ -1005,4 +1027,20 @@
 extern void cpp_force_token_locations (cpp_reader *, source_location *);
 extern void cpp_stop_forcing_token_locations (cpp_reader *);
 
+/* In expr.c */
+extern enum cpp_ttype cpp_userdef_string_remove_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_string_add_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_char_remove_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_char_add_type
+  (enum cpp_ttype type);
+extern bool cpp_userdef_string_p
+  (enum cpp_ttype type);
+extern bool cpp_userdef_char_p
+  (enum cpp_ttype type);
+extern const char * cpp_get_userdef_suffix
+  (const cpp_token *);
+
 #endif /* ! LIBCPP_CPPLIB_H */
Index: libcpp/init.c
===================================================================
--- libcpp/init.c	(revision 180284)
+++ libcpp/init.c	(working copy)
@@ -80,22 +80,23 @@
   char digraphs;
   char uliterals;
   char rliterals;
+  char user_literals;
 };
 
 static const struct lang_flags lang_defaults[] =
-{ /*              c99 c++ xnum xid std  //   digr ulit rlit */
-  /* GNUC89   */  { 0,  0,  1,   0,  0,   1,   1,   0,   0 },
-  /* GNUC99   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1 },
-  /* GNUC1X   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1 },
-  /* STDC89   */  { 0,  0,  0,   0,  1,   0,   0,   0,   0 },
-  /* STDC94   */  { 0,  0,  0,   0,  1,   0,   1,   0,   0 },
-  /* STDC99   */  { 1,  0,  1,   0,  1,   1,   1,   0,   0 },
-  /* STDC1X   */  { 1,  0,  1,   0,  1,   1,   1,   1,   0 },
-  /* GNUCXX   */  { 0,  1,  1,   0,  0,   1,   1,   0,   0 },
-  /* CXX98    */  { 0,  1,  1,   0,  1,   1,   1,   0,   0 },
-  /* GNUCXX0X */  { 1,  1,  1,   0,  0,   1,   1,   1,   1 },
-  /* CXX0X    */  { 1,  1,  1,   0,  1,   1,   1,   1,   1 },
-  /* ASM      */  { 0,  0,  1,   0,  0,   1,   0,   0,   0 }
+{ /*              c99 c++ xnum xid std  //   digr ulit rlit user_literals */
+  /* GNUC89   */  { 0,  0,  1,   0,  0,   1,   1,   0,   0,    0 },
+  /* GNUC99   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1,    0 },
+  /* GNUC1X   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1,    0 },
+  /* STDC89   */  { 0,  0,  0,   0,  1,   0,   0,   0,   0,    0 },
+  /* STDC94   */  { 0,  0,  0,   0,  1,   0,   1,   0,   0,    0 },
+  /* STDC99   */  { 1,  0,  1,   0,  1,   1,   1,   0,   0,    0 },
+  /* STDC1X   */  { 1,  0,  1,   0,  1,   1,   1,   1,   0,    0 },
+  /* GNUCXX   */  { 0,  1,  1,   0,  0,   1,   1,   0,   0,    0 },
+  /* CXX98    */  { 0,  1,  1,   0,  1,   1,   1,   0,   0,    0 },
+  /* GNUCXX0X */  { 1,  1,  1,   0,  0,   1,   1,   1,   1,    1 },
+  /* CXX0X    */  { 1,  1,  1,   0,  1,   1,   1,   1,   1,    1 },
+  /* ASM      */  { 0,  0,  1,   0,  0,   1,   0,   0,   0,    0 }
   /* xid should be 1 for GNUC99, STDC99, GNUCXX, CXX98, GNUCXX0X, and
      CXX0X when no longer experimental (when all uses of identifiers
      in the compiler have been audited for correct handling of
@@ -120,6 +121,7 @@
   CPP_OPTION (pfile, digraphs)			 = l->digraphs;
   CPP_OPTION (pfile, uliterals)			 = l->uliterals;
   CPP_OPTION (pfile, rliterals)			 = l->rliterals;
+  CPP_OPTION (pfile, user_literals)		 = l->user_literals;
 }
 
 /* Initialize library global state.  */
Index: libcpp/expr.c
===================================================================
--- libcpp/expr.c	(revision 180284)
+++ libcpp/expr.c	(working copy)
@@ -1,6 +1,6 @@
 /* Parse C expressions for cpplib.
    Copyright (C) 1987, 1992, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
-   2002, 2004, 2008, 2009, 2010 Free Software Foundation.
+   2002, 2004, 2008, 2009, 2010, 2011 Free Software Foundation.
    Contributed by Per Bothner, 1994.
 
 This program is free software; you can redistribute it and/or modify it
@@ -185,6 +185,13 @@
 	     q ? CPP_N_MD_Q : CPP_N_DEFAULT));
 }
 
+/* Return the classification flags for a float suffix.  */
+unsigned int
+cpp_interpret_float_suffix (const char *s, size_t len)
+{
+  return interpret_float_suffix ((const unsigned char *)s, len);
+}
+
 /* Subroutine of cpp_classify_number.  S points to an integer suffix
    of length LEN, possibly zero. Returns 0 for an invalid suffix, or a
    flag vector describing the suffix.  */
@@ -219,11 +226,143 @@
 	     : (l == 1) ? CPP_N_MEDIUM : CPP_N_LARGE));
 }
 
+/* Return the classification flags for an int suffix.  */
+unsigned int
+cpp_interpret_int_suffix (const char *s, size_t len)
+{
+  return interpret_int_suffix ((const unsigned char *)s, len);
+}
+
+/* Return the string type corresponding to the the input user-defined string
+   literal type.  If the input type is not a user-defined string literal
+   type return the input type.  */
+enum cpp_ttype
+cpp_userdef_string_remove_type (enum cpp_ttype type)
+{
+  if (type == CPP_STRING_USERDEF)
+    return CPP_STRING;
+  else if (type == CPP_WSTRING_USERDEF)
+    return CPP_WSTRING;
+  else if (type == CPP_STRING16_USERDEF)
+    return CPP_STRING16;
+  else if (type == CPP_STRING32_USERDEF)
+    return CPP_STRING32;
+  else if (type == CPP_UTF8STRING_USERDEF)
+    return CPP_UTF8STRING;
+  else
+    return type;
+}
+
+/* Return the user-defined string literal type corresponding to the input
+   string type.  If the input type is not a string type return the input
+   type.  */
+enum cpp_ttype
+cpp_userdef_string_add_type (enum cpp_ttype type)
+{
+  if (type == CPP_STRING)
+    return CPP_STRING_USERDEF;
+  else if (type == CPP_WSTRING)
+    return CPP_WSTRING_USERDEF;
+  else if (type == CPP_STRING16)
+    return CPP_STRING16_USERDEF;
+  else if (type == CPP_STRING32)
+    return CPP_STRING32_USERDEF;
+  else if (type == CPP_UTF8STRING)
+    return CPP_UTF8STRING_USERDEF;
+  else
+    return type;
+}
+
+/* Return the char type corresponding to the the input user-defined char
+   literal type.  If the input type is not a user-defined char literal
+   type return the input type.  */
+enum cpp_ttype
+cpp_userdef_char_remove_type (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR_USERDEF)
+    return CPP_CHAR;
+  else if (type == CPP_WCHAR_USERDEF)
+    return CPP_WCHAR;
+  else if (type == CPP_CHAR16_USERDEF)
+    return CPP_STRING16;
+  else if (type == CPP_CHAR32_USERDEF)
+    return CPP_STRING32;
+  else
+    return type;
+}
+
+/* Return the user-defined char literal type corresponding to the input
+   char type.  If the input type is not a char type return the input
+   type.  */
+enum cpp_ttype
+cpp_userdef_char_add_type (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR)
+    return CPP_CHAR_USERDEF;
+  else if (type == CPP_WCHAR)
+    return CPP_WCHAR_USERDEF;
+  else if (type == CPP_CHAR16)
+    return CPP_CHAR16_USERDEF;
+  else if (type == CPP_CHAR32)
+    return CPP_CHAR32_USERDEF;
+  else
+    return type;
+}
+
+/* Return true if the token type is a user-defined string literal.  */
+bool
+cpp_userdef_string_p (enum cpp_ttype type)
+{
+  if (type == CPP_STRING_USERDEF
+   || type == CPP_WSTRING_USERDEF
+   || type == CPP_STRING16_USERDEF
+   || type == CPP_STRING32_USERDEF
+   || type == CPP_UTF8STRING_USERDEF)
+    return true;
+  else
+    return false;
+}
+
+/* Return true if the token type is a user-defined char literal.  */
+bool
+cpp_userdef_char_p (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR_USERDEF
+   || type == CPP_WCHAR_USERDEF
+   || type == CPP_CHAR16_USERDEF
+   || type == CPP_CHAR32_USERDEF)
+    return true;
+  else
+    return false;
+}
+
+/* Extract the suffix from a user-defined literal string or char.  */
+const char *
+cpp_get_userdef_suffix (const cpp_token *tok)
+{
+  unsigned int len = tok->val.str.len;
+  const char *text = (const char *)tok->val.str.text;
+  char delim;
+  unsigned int i;
+  for (i = 0; i < len; ++i)
+    if (text[i] == '\'' || text[i] == '"')
+      break;
+  if (i == len)
+    return text + len;
+  delim = text[i];
+  for (i = len; i > 0; --i)
+    if (text[i - 1] == delim)
+      break;
+  return text + i;
+}
+
 /* Categorize numeric constants according to their field (integer,
    floating point, or invalid), radix (decimal, octal, hexadecimal),
-   and type suffixes.  */
+   and type suffixes.  In C++0X if UD_SUFFIX is non null it will be
+   assigned any unrecognized suffix for a user-defined literal.  */
 unsigned int
-cpp_classify_number (cpp_reader *pfile, const cpp_token *token)
+cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
+		     const char **ud_suffix)
 {
   const uchar *str = token->val.str.text;
   const uchar *limit;
@@ -231,6 +370,9 @@
   enum {NOT_FLOAT = 0, AFTER_POINT, AFTER_EXPON} float_flag;
   bool seen_digit;
 
+  if (ud_suffix)
+    *ud_suffix = NULL;
+
   /* If the lexer has done its job, length one can only be a single
      digit.  Fast-path this very common case.  */
   if (token->val.str.len == 1)
@@ -361,10 +503,19 @@
       result = interpret_float_suffix (str, limit - str);
       if (result == 0)
 	{
-	  cpp_error (pfile, CPP_DL_ERROR,
-		     "invalid suffix \"%.*s\" on floating constant",
-		     (int) (limit - str), str);
-	  return CPP_N_INVALID;
+	  if (CPP_OPTION (pfile, user_literals))
+	    {
+	      if (ud_suffix)
+		*ud_suffix = (const char *) str;
+	      result = CPP_N_LARGE | CPP_N_USERDEF;
+	    }
+	  else
+	    {
+	      cpp_error (pfile, CPP_DL_ERROR,
+			 "invalid suffix \"%.*s\" on floating constant",
+			 (int) (limit - str), str);
+	      return CPP_N_INVALID;
+	    }
 	}
 
       /* Traditional C didn't accept any floating suffixes.  */
@@ -406,10 +557,19 @@
       result = interpret_int_suffix (str, limit - str);
       if (result == 0)
 	{
-	  cpp_error (pfile, CPP_DL_ERROR,
-		     "invalid suffix \"%.*s\" on integer constant",
-		     (int) (limit - str), str);
-	  return CPP_N_INVALID;
+	  if (CPP_OPTION (pfile, user_literals))
+	    {
+	      if (ud_suffix)
+		*ud_suffix = (const char *) str;
+	      result = CPP_N_UNSIGNED | CPP_N_LARGE | CPP_N_USERDEF;
+	    }
+	  else
+	    {
+	      cpp_error (pfile, CPP_DL_ERROR,
+			 "invalid suffix \"%.*s\" on integer constant",
+			 (int) (limit - str), str);
+	      return CPP_N_INVALID;
+	    }
 	}
 
       /* Traditional C only accepted the 'L' suffix.
@@ -748,7 +908,7 @@
   switch (token->type)
     {
     case CPP_NUMBER:
-      temp = cpp_classify_number (pfile, token);
+      temp = cpp_classify_number (pfile, token, NULL);
       switch (temp & CPP_N_CATEGORY)
 	{
 	case CPP_N_FLOATING:
Index: libcpp/lex.c
===================================================================
--- libcpp/lex.c	(revision 180284)
+++ libcpp/lex.c	(working copy)
@@ -1478,6 +1478,18 @@
     }
  break_outer_loop:
 
+  if (CPP_OPTION (pfile, user_literals))
+    {
+      /* Grab user defined literal suffix.  */
+      if (ISIDST (*cur))
+	{
+	  type = cpp_userdef_string_add_type (type);
+	  ++cur;
+	}
+      while (ISIDNUM (*cur))
+	++cur;
+    }
+
   pfile->buffer->cur = cur;
   if (first_buff == NULL)
     create_literal (pfile, token, base, cur - base, type);
@@ -1581,6 +1593,19 @@
     cpp_error (pfile, CPP_DL_PEDWARN, "missing terminating %c character",
 	       (int) terminator);
 
+  if (CPP_OPTION (pfile, user_literals))
+    {
+      /* Grab user defined literal suffix.  */
+      if (ISIDST (*cur))
+	{
+	  type = cpp_userdef_char_add_type (type);
+	  type = cpp_userdef_string_add_type (type);
+          ++cur;
+	}
+      while (ISIDNUM (*cur))
+	++cur;
+    }
+
   pfile->buffer->cur = cur;
   create_literal (pfile, token, base, cur - base, type);
 }

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-21 23:38       ` Jason Merrill
  2011-10-23 22:29         ` Ed Smith-Rowland
  2011-10-24 15:41         ` Ed Smith-Rowland
@ 2011-10-25  7:07         ` Ed Smith-Rowland
  2 siblings, 0 replies; 36+ messages in thread
From: Ed Smith-Rowland @ 2011-10-25  7:07 UTC (permalink / raw)
  To: Jason Merrill; +Cc: Tom Tromey, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 2332 bytes --]

On 10/21/2011 05:20 PM, Jason Merrill wrote:
> I think we're down to minor cosmetic issues:
>
> On 10/21/2011 03:55 PM, Tom Tromey wrote:
>> There are a few spots like this that are missing a space before an open
>> paren.
>
>> +      if (DECL_LANGUAGE(decl) == lang_c)
>
> Another one.
>
>> -          if (warn_cxx0x_compat
>> - && C_RID_CODE (token->u.value) >= RID_FIRST_CXX0X
>> - && C_RID_CODE (token->u.value) <= RID_LAST_CXX0X)
> ....
>
> This code doesn't seem to have actually changed, so let's not adjust 
> its whitespace.
>
>> +  /* Fill in PARMVEC with all of the parameters.  */
>> +  parmvec = make_tree_vec (len);
>
> Let's call it 'charvec'; the characters are template arguments, not 
> parameters.
>
>> +/* Parse a user-defined numeric constant.  returns a call to a 
>> user-defined
>> +   literal operator.  */
>> +static tree
>> +cp_parser_userdef_numeric_literal (cp_parser *parser)
>
> Add a blank line between comment and function.
>
>> While looking at the embedded string issue I found that if you apply 
>> the suffix of a raw literal to a string it errors as it should but 
>> the error complained that there were too many arguments for the 
>> function.  This was not helpful so I made a nicer error message.
>
>> +  if (result == error_mark_node)
>> +    error ("invalid string literal prefix %<\"%s\"%> for user-defined"
>> +          " raw literal operator %qD", TREE_STRING_POINTER (value), 
>> name);
>
> I think that we want a combination of the two errors; the new error 
> doesn't help the user to fix their code as much.  It should remind 
> them that for a string literal the function is called with a length 
> argument as well.
>
>> +       error ("literal operator template %qD has invalid parameter 
>> list",
>> +              decl);
>
> Similarly, this message should say that the parameter list needs to be 
> <char...>
>
>>
>> +
>> +/* Return true if a user-defined literal operator is a raw 
>> operator.  */
>> +
>
> We don't need the extra newline before the comment.
>
> Should be ready to go with these tweaks.
>
> Jason
>
Jason,

Here is a patch that fixes both issues noted in the previous email.
Also, I'm preventing user-defined literals in a preprocessor expression 
since there's no way we can tell they are integral or not.  They could 
return anything (or nothing).

Ed


[-- Attachment #2: patch32 --]
[-- Type: text/plain, Size: 77216 bytes --]

Index: gcc/c-family/c-common.c
===================================================================
--- gcc/c-family/c-common.c	(revision 180284)
+++ gcc/c-family/c-common.c	(working copy)
@@ -9923,4 +9923,17 @@
   MARK_TS_TYPED (EXCESS_PRECISION_EXPR);
 }
 
+/* Build a user-defined numeric literal out of an integer constant type VALUE
+   with identifier SUFFIX.  */
+
+tree
+build_userdef_literal (tree suffix_id, tree value, tree num_string)
+{
+  tree literal = make_node (USERDEF_LITERAL);
+  USERDEF_LITERAL_SUFFIX_ID (literal) = suffix_id;
+  USERDEF_LITERAL_VALUE (literal) = value;
+  USERDEF_LITERAL_NUM_STRING (literal) = num_string;
+  return literal;
+}
+
 #include "gt-c-family-c-common.h"
Index: gcc/c-family/c-lex.c
===================================================================
--- gcc/c-family/c-lex.c	(revision 180284)
+++ gcc/c-family/c-lex.c	(working copy)
@@ -44,8 +44,8 @@
 int pending_lang_change; /* If we need to switch languages - C++ only */
 int c_header_level;	 /* depth in C headers - C++ only */
 
-static tree interpret_integer (const cpp_token *, unsigned int);
-static tree interpret_float (const cpp_token *, unsigned int);
+static tree interpret_integer (const cpp_token *, unsigned int, const char *);
+static tree interpret_float (const cpp_token *, unsigned int, const char *);
 static tree interpret_fixed (const cpp_token *, unsigned int);
 static enum integer_type_kind narrowest_unsigned_type
 	(unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned int);
@@ -314,7 +314,8 @@
 
     case CPP_NUMBER:
       {
-	unsigned int flags = cpp_classify_number (parse_in, tok);
+	const char *suffix = NULL;
+	unsigned int flags = cpp_classify_number (parse_in, tok, &suffix);
 
 	switch (flags & CPP_N_CATEGORY)
 	  {
@@ -328,16 +329,31 @@
 	       Set PURE_ZERO to pass this information to the C++ parser.  */
 	    if (tok->val.str.len == 1 && *tok->val.str.text == '0')
 	      add_flags = PURE_ZERO;
-	    *value = interpret_integer (tok, flags);
+	    *value = interpret_integer (tok, flags, suffix);
 	    break;
 
 	  case CPP_N_FLOATING:
-	    *value = interpret_float (tok, flags);
+	    *value = interpret_float (tok, flags, suffix);
 	    break;
 
 	  default:
 	    gcc_unreachable ();
 	  }
+
+	if (flags & CPP_N_USERDEF)
+	  {
+	    tree num_string;
+	    int len = tok->val.str.len - strlen (suffix);
+	    char *str = (char *) tok->val.str.text;
+	    tree suffix_id = get_identifier (suffix);
+	    str[len] = '\0';
+	    num_string = build_string (len + 1, (const char *) str);
+	    TREE_TYPE (num_string) = char_array_type_node;
+	    num_string = fix_string_type (num_string);
+	    tree literal = build_userdef_literal (suffix_id, *value,
+						  num_string);
+	    *value = literal;
+	  }
       }
       break;
 
@@ -415,6 +431,22 @@
       }
       goto retry;
 
+    case CPP_CHAR_USERDEF:
+    case CPP_WCHAR_USERDEF:
+    case CPP_CHAR16_USERDEF:
+    case CPP_CHAR32_USERDEF:
+      {
+	tree literal;
+	cpp_token temp_tok = *tok;
+	const char *suffix = cpp_get_userdef_suffix (tok);
+	temp_tok.val.str.len -= strlen (suffix);
+	temp_tok.type = cpp_userdef_char_remove_type (type);
+	literal = build_userdef_literal (get_identifier (suffix),
+					 lex_charconst (&temp_tok), NULL_TREE);
+	*value = literal;
+      }
+      break;
+
     case CPP_CHAR:
     case CPP_WCHAR:
     case CPP_CHAR16:
@@ -422,6 +454,22 @@
       *value = lex_charconst (tok);
       break;
 
+    case CPP_STRING_USERDEF:
+    case CPP_WSTRING_USERDEF:
+    case CPP_STRING16_USERDEF:
+    case CPP_STRING32_USERDEF:
+    case CPP_UTF8STRING_USERDEF:
+      {
+	tree literal, string;
+	const char *suffix = cpp_get_userdef_suffix (tok);
+	string = build_string (tok->val.str.len - strlen (suffix),
+			       (const char *) tok->val.str.text);
+	literal = build_userdef_literal (get_identifier (suffix),
+					 string, NULL_TREE);
+	*value = literal;
+      }
+      break;
+
     case CPP_STRING:
     case CPP_WSTRING:
     case CPP_STRING16:
@@ -536,9 +584,11 @@
   return itk_none;
 }
 
-/* Interpret TOKEN, an integer with FLAGS as classified by cpplib.  */
+/* Interpret TOKEN, an integer with FLAGS as classified by cpplib.
+   For C++0X SUFFIX may contain a user-defined literal suffix.  */
 static tree
-interpret_integer (const cpp_token *token, unsigned int flags)
+interpret_integer (const cpp_token *token, unsigned int flags,
+		   const char *suffix)
 {
   tree value, type;
   enum integer_type_kind itk;
@@ -621,9 +671,10 @@
 }
 
 /* Interpret TOKEN, a floating point number with FLAGS as classified
-   by cpplib.  */
+   by cpplib.  For C++0X SUFFIX may contain a user-defined literal suffix.  */
 static tree
-interpret_float (const cpp_token *token, unsigned int flags)
+interpret_float (const cpp_token *token, unsigned int flags,
+		 const char *suffix)
 {
   tree type;
   tree const_type;
@@ -702,7 +753,9 @@
      has any suffixes, cut them off; REAL_VALUE_ATOF/ REAL_VALUE_HTOF
      can't handle them.  */
   copylen = token->val.str.len;
-  if (flags & CPP_N_DFLOAT)
+  if (flags & CPP_N_USERDEF)
+    copylen -= strlen (suffix);
+  else if (flags & CPP_N_DFLOAT)
     copylen -= 2;
   else
     {
Index: gcc/c-family/c-common.h
===================================================================
--- gcc/c-family/c-common.h	(revision 180284)
+++ gcc/c-family/c-common.h	(working copy)
@@ -1067,4 +1067,27 @@
   return NULL;
 }
 
+/* A suffix-identifier value doublet that represents user-defined literals
+   for C++-0x.  */
+struct GTY(()) tree_userdef_literal {
+  struct tree_base base;
+  tree suffix_id;
+  tree value;
+  tree num_string;
+};
+
+#define USERDEF_LITERAL_SUFFIX_ID(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->suffix_id)
+
+#define USERDEF_LITERAL_VALUE(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->value)
+
+#define USERDEF_LITERAL_NUM_STRING(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->num_string)
+
+#define USERDEF_LITERAL_TYPE(NODE) \
+  (TREE_TYPE (USERDEF_LITERAL_VALUE (NODE)))
+
+extern tree build_userdef_literal (tree suffix_id, tree value, tree num_string);
+
 #endif /* ! GCC_C_COMMON_H */
Index: gcc/c-family/c-common.def
===================================================================
--- gcc/c-family/c-common.def	(revision 180284)
+++ gcc/c-family/c-common.def	(working copy)
@@ -47,6 +47,12 @@
    evaluated.  */
 DEFTREECODE (EXCESS_PRECISION_EXPR, "excess_precision_expr", tcc_expression, 1)
 
+/* Used to represent a user-defined literal.
+   The operands are an IDENTIFIER for the suffix, the VALUE of the literal,
+   and for numeric literals the original string representation of the
+   number.  */
+DEFTREECODE (USERDEF_LITERAL, "userdef_literal", tcc_exceptional, 3)
+
 /*
 Local variables:
 mode:c
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C	(revision 0)
@@ -0,0 +1,4 @@
+// { dg-options -std=c++0x }
+
+template<char...>
+  int operator"" _xyz(unsigned long long);	// { dg-error "has invalid argument list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit_system_header
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit_system_header	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit_system_header	(revision 0)
@@ -0,0 +1,6 @@
+
+#pragma GCC system_header
+
+char
+operator"" stdsuffix(char __c)
+{ return __c/2; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C	(revision 0)
@@ -0,0 +1,42 @@
+// { dg-options "-std=c++0x" }
+
+//  Can't have *both* literal operator template and raw literal operator.
+
+int
+operator"" _abc(const char*)
+  {
+    return 42;
+  }
+
+template<char...>
+  int
+  operator"" _abc() // { dg-error "literal operator template|conflicts with raw literal operator" }
+  {
+    return 13;
+  }
+
+template<char...>
+  int
+  operator"" _def()
+  {
+    return 12;
+  }
+
+int
+operator"" _def(const char*) // { dg-error "raw literal operator|conflicts with literal operator template" }
+  {
+    return 43;
+  }
+
+int
+operator"" _ghi(long double)
+  {
+    return 42;
+  }
+
+template<char...>
+  int
+  operator"" _ghi() // OK
+  {
+    return 13;
+  }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C	(revision 0)
@@ -0,0 +1,43 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test simple operator declaration and definition in namespaces.
+
+#include <cmath>
+#include <limits>
+
+namespace Long
+{
+  long double operator"" _LL(long double);
+}
+
+namespace Short
+{
+  short
+  operator"" _SS(long double x)
+  { return std::fmod(x, static_cast<long double>(std::numeric_limits<short>::max())); }
+}
+
+void
+test1()
+{
+  long double x = Long::operator "" _LL(1.2L);
+
+  using namespace Short;
+  short s = operator"" _SS(1.2L);
+  short s2 = 1.2_SS;
+}
+
+int
+main()
+{
+  test1();
+}
+
+namespace Long
+{
+  long double
+  operator"" _LL(long double x)
+  { return x + 2.0L; }
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-raw-op-string-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-raw-op-string-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-raw-op-string-neg.C	(revision 0)
@@ -0,0 +1,8 @@
+// { dg-options "-std=c++0x" }
+
+//  Make sure handing a string to a raw literal generates a sensible error message.
+
+int operator"" _embedraw(const char*)
+{ return 41; };
+
+int k = "Boo!"_embedraw;  //  { dg-error "invalid string literal prefix|for user-defined raw literal operator" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-embed-quote.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-embed-quote.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-embed-quote.C	(revision 0)
@@ -0,0 +1,34 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+//  Make sure embedded quotes are not a problem for string and char literals.
+
+#include <cstdint>
+#include <cassert>
+
+int operator"" _embedchar(char)
+{ return 41; };
+
+int operator"" _embedstr(const char*, std::size_t len)
+{ return 42 + len; };
+
+void
+test()
+{
+  int i = '\''_embedchar;
+
+  int j = "\""_embedstr;
+  assert(j == 43);
+
+  int k = "foo\""_embedstr;
+  assert(k == 46);
+
+  int l = "\"bar"_embedstr;
+  assert(l == 46);
+}
+
+int
+main()
+{
+  test();
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C	(revision 0)
@@ -0,0 +1,15 @@
+// { dg-options -std=c++0x }
+
+class Foo
+{
+public:
+  Foo() { }
+  int operator"" _Bar(char32_t);  // { dg-error "must be a non-member function" }
+};
+
+int i = operator"" _Bar(U'x');  // { dg-error "was not declared in this scope" }
+int j = U'x'_Bar;  // { dg-error "unable to find user-defined character literal operator" }
+
+int
+Foo::operator"" _Bar(char32_t)  // { dg-error "must be a non-member function" }
+{ return 42; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C	(revision 0)
@@ -0,0 +1,38 @@
+// { dg-options -std=c++0x }
+
+#include <cstddef>
+
+class Foo { };
+
+Foo
+operator"" _Foo(int *);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(unsigned long int);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(double);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const float *, std::size_t);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const wchar_t *, int);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const char16_t *);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(char...);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(unsigned long long int, char);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const char *, std::size_t, int);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(long double &);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(std::size_t, const char16_t *);	// { dg-error "has invalid argument list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C	(revision 0)
@@ -0,0 +1,17 @@
+// { dg-options "-std=c++98" }
+
+#include <cstddef>
+
+int
+operator"" _mm(long double m)	// { dg-warning "user-defined literals only available with" }
+{ return int(1000.0L * m); }
+
+int in = 0.0254_mm;	// { dg-error "invalid suffix" }
+
+int
+operator"" _Q(const char *, std::size_t)	// { dg-warning "user-defined literals only available with" }
+{ return 42; }
+
+int x = "Hello"_Q;	// { dg-error "invalid conversion from" }
+
+// { dg-error "expected" "" { target *-*-* } 15 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C	(revision 0)
@@ -0,0 +1,5 @@
+// { dg-options -std=c++0x }
+
+#include <string>
+
+std::string operator"" 5X(const char*, std::size_t);	// { dg-error "expected suffix identifier" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-raw-op.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-raw-op.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-raw-op.C	(revision 0)
@@ -0,0 +1,21 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+#include <cassert>
+#include <cstring>
+
+int
+operator"" _raw_umber(const char * str)
+{
+  return strlen(str);
+}
+
+int
+main()
+{
+  int i = 0123012301230123012301230123012301230123012301230123012301230123_raw_umber;
+  assert( i == 64 );
+
+  int j = 90123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789_raw_umber;
+  assert( j == 101 );
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+constexpr unsigned long long
+operator"" _grow(unsigned long long n)
+{ return 2 * n; }
+
+double buffer[25_grow];
Index: gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C	(revision 0)
@@ -0,0 +1,49 @@
+// { dg-options -std=c++0x }
+
+//  Test that the standard suffixes shadow any user-defined suffixes of the same name.
+long double
+operator"" L(long double x)  // { dg-warning "floating point suffix|shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ULL(unsigned long long int k)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return k; }
+
+long double
+operator"" l(long double x)  // { dg-warning "floating point suffix|shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ull(unsigned long long int k)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return k; }
+
+//  Namespaces are no hiding place.
+namespace Long
+{
+
+long double
+operator"" L(long double x)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ULL(unsigned long long int k)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return k; }
+
+long double
+operator"" l(long double x)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ull(unsigned long long int k)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return k; }
+
+}
+
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 5 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 9 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 13 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 17 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 25 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 29 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 33 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 37 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test warning on declaration without leading underscore.
+
+long double operator"" nounder(long double); // { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" }
+
+template<char...>
+  int operator"" nounder(); // { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C	(revision 0)
@@ -0,0 +1,12 @@
+// { dg-options -std=c++0x }
+
+class Foo { };
+
+template<wchar_t...>
+  Foo operator"" _Foo(); // { dg-error "literal operator template|has invalid parameter list" }
+
+template<char>
+  Foo operator"" _Bar(); // { dg-error "literal operator template|has invalid parameter list" }
+
+template<typename... Type>
+  Foo operator"" _Bar(); // { dg-error "literal operator template|has invalid parameter list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-general.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-general.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-general.C	(revision 0)
@@ -0,0 +1,52 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test simple operator declaration and definition.
+
+#include <cstring>
+#include <string>
+#include <complex>
+#include <cassert>
+
+long double operator"" _v(long double);
+std::string operator"" _w(const char16_t*, size_t);
+unsigned operator"" _w(const char*);
+
+std::complex<double>
+operator"" _i(long double y)
+{ return std::complex<double>(0.0L, y); }
+
+void
+test1()
+{
+  long double x = operator"" _v(1.2L);
+  assert(x == 2.2L);
+
+  std::string s = operator"" _w(u"one", 3);
+  assert(s == "boo");
+
+  unsigned u = operator"" _w("Hello, World!");
+  assert(u == 13U);
+
+  std::complex<double> i = operator"" _i(2.0);
+  assert(i == std::complex<double>(0.0, 2.0));
+}
+
+int
+main()
+{
+  test1();
+}
+
+long double
+operator"" _v(long double x)
+{ return x + 1.0L; }
+
+std::string
+operator"" _w(const char16_t*, size_t)
+{ return std::string("boo"); }
+
+unsigned
+operator"" _w(const char* str)
+{ return strlen(str); }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C	(revision 0)
@@ -0,0 +1,3 @@
+// { dg-options -std=c++0x }
+
+#include "udlit_system_header"
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test error on non-function declaration.
+
+double operator"" _baddecl; // { dg-error "as non-function" }
+
+template<char...>
+  int operator"" _badtmpldecl; // { dg-error "as non-function" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C	(revision 0)
@@ -0,0 +1,15 @@
+// { dg-options -std=c++0x }
+
+#include <string>
+
+std::string operator"" _i18n(const char*, std::size_t);
+
+std::string vogon_poem = R"V0G0N(
+                O freddled gruntbuggly thy micturations are to me
+                    As plured gabbleblochits on a lurgid bee.
+                 Groop, I implore thee my foonting turlingdromes.   
+              And hooptiously drangle me with crinkly bindlewurdles,
+  Or I will rend thee in the gobberwarts with my blurlecruncheon, see if I don't.
+
+                    (by Prostetnic Vogon Jeltz; see p. 56/57)
+)V0G0N"_i18n;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-addr.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-addr.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-addr.C	(revision 0)
@@ -0,0 +1,10 @@
+// { dg-options "-std=c++0x" }
+
+#include <cstddef>
+
+bool operator"" _yn(const char*, size_t);
+
+typedef bool (*pfunk)(const char*, size_t);
+pfunk p = &operator"" _yn;
+
+bool tf = p("Hello,\0 World!", 14);
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C	(revision 0)
@@ -0,0 +1,4 @@
+// { dg-options -std=c++0x }
+
+template<char...>
+  int operator"" _abc();
Index: gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C	(revision 0)
@@ -0,0 +1,8 @@
+// { dg-options -std=c++0x }
+
+extern "C" {
+
+int
+operator"" _badclinkage(unsigned long long);	// { dg-error "operator with C linkage" }
+
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-template.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-template.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-template.C	(revision 0)
@@ -0,0 +1,51 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test template operator declaration and definition.
+
+#include <cassert>
+
+template<char...>
+  int operator"" _abc();
+
+template<>
+  int
+  operator"" _abc<>()
+  { return -1; }
+
+template<>
+  int
+  operator"" _abc<'L','U','E'>()
+  { return 42; }
+
+template<>
+  int
+  operator"" _abc<'6','6','6'>()
+  { return 21; }
+
+int
+test1()
+{
+  int i = operator"" _abc<'1','2','3'>();
+  assert(i == 45);
+  int universal_meaning = operator"" _abc<'L','U','E'>();
+  assert(universal_meaning == 42);
+  int b = operator"" _abc<'6','6','6'>();
+  int z = operator"" _abc<>();
+  assert(z == -1);
+  int j = 123_abc;
+  assert(j == i);
+  int jb = 666_abc;
+  assert(jb == b);
+}
+
+int
+main()
+{
+  test1();
+}
+
+template<char... Chars>
+  int operator"" _abc()
+  { return 42 + sizeof...(Chars); }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-preproc-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-preproc-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-preproc-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+int
+operator"" _badpreproc(const char *str)
+{ return 0; }
+
+#if 123_badpreproc  //  { dg-error "user-defined literal in preprocessor expression" }
+#  error ("user-defined literal in preprocessor expression")  //  { dg-error "user-defined literal in preprocessor expression" }
+#endif
Index: gcc/testsuite/g++.dg/cpp0x/udlit-args.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-args.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-args.C	(revision 0)
@@ -0,0 +1,38 @@
+// { dg-options -std=c++0x }
+
+#include <cstddef>
+
+class Foo { };
+
+Foo
+operator"" _Foo(const char *);
+
+Foo
+operator"" _Foo(unsigned long long int);
+
+Foo
+operator"" _Foo(long double);
+
+Foo
+operator"" _Foo(char);
+
+Foo
+operator"" _Foo(wchar_t);
+
+Foo
+operator"" _Foo(char16_t);
+
+Foo
+operator"" _Foo(char32_t);
+
+Foo
+operator"" _Foo(const char *, std::size_t);
+
+Foo
+operator"" _Foo(const wchar_t *, std::size_t);
+
+Foo
+operator"" _Foo(const char16_t *, std::size_t);
+
+Foo
+operator"" _Foo(const char32_t *, std::size_t);
Index: gcc/testsuite/g++.dg/cpp0x/udlit-declare-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-declare-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-declare-neg.C	(revision 0)
@@ -0,0 +1,15 @@
+// { dg-options "-std=c++0x" }
+
+//  Check that undeclared literal operator calls and literals give appropriate errors.
+
+int i = operator"" _Bar('x');  // { dg-error "was not declared in this scope" }
+int j = 'x'_Bar;  // { dg-error "unable to find user-defined character literal operator" }
+
+int ii = operator"" _BarCharStr("Howdy, Pardner!");  // { dg-error "was not declared in this scope" }
+int jj = "Howdy, Pardner!"_BarCharStr;  // { dg-error "unable to find user-defined string literal operator" }
+
+unsigned long long iULL = operator"" _BarULL(666ULL);  // { dg-error "was not declared in this scope" }
+unsigned long long jULL = 666_BarULL;  // { dg-error "unable to find user-defined numeric literal operator" }
+
+long double iLD = operator"" _BarLD(666.0L);  // { dg-error "was not declared in this scope" }
+long double jLD = 666.0_BarLD;  // { dg-error "unable to find user-defined numeric literal operator" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C	(revision 0)
@@ -0,0 +1,5 @@
+// { dg-options -std=c++0x }
+
+char32_t
+operator"" (char32_t C)	// { dg-error "expected suffix identifier" }
+{ return C; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test error on non-empty string after 'operator' keyword.
+
+double operator"hi" _badword(long double); // { dg-error "expected empty string after" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nospace-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nospace-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nospace-neg.C	(revision 0)
@@ -0,0 +1,3 @@
+// { dg-options "-std=c++0x" }
+
+float operator ""_abc(const char*); // { dg-error "missing space between|and suffix identifier" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-inline.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-inline.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-inline.C	(revision 0)
@@ -0,0 +1,22 @@
+// { dg-options "-std=c++0x" }
+
+//  Literal operators can be inline.
+
+inline int
+operator"" _thing1(char cc)
+{ return 42 * cc; }
+
+int operator"" _thing2(char cc);
+
+class Foo
+{
+  int
+  friend operator"" _thing2(char cc)
+  { return 42 * cc; }
+};
+
+int i = operator"" _thing1('x');
+int j = 'x'_thing1;
+
+int iF = operator"" _thing2('x');
+int jF = 'x'_thing2;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+extern "C"_badlinkage {	// { dg-error "expected unqualified-id before" }
+
+int foo();
+
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-friend.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-friend.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-friend.C	(revision 0)
@@ -0,0 +1,28 @@
+// { dg-options -std=c++0x }
+
+long double
+operator"" _Hertz(long double);
+
+class Foo
+{
+public:
+  Foo() { }
+
+  friend Foo operator"" _Bar(char);
+
+  friend long double
+  operator"" _Hertz(long double omega)
+  { return omega / 6.28318530717958648; }
+};
+
+Foo
+operator"" _Bar(char)
+{ return Foo(); }
+
+Foo f1 = operator"" _Bar('x');
+
+Foo f2 = 'x'_Bar;
+
+long double fm1 = operator"" _Hertz(552.92L);
+
+long double fm2 = 552.92_Hertz;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+#include <string>
+
+std::string operator"" _xxx(const char*, size_t);
+
+std::string operator"" _yyy(const char*, size_t);
+
+std::string concat = "Hello, "_xxx "World!"_yyy;	// { dg-error "inconsistent user-defined literal suffixes" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options -std=c++0x }
+
+class Foo { };
+
+template<char...>
+  Foo operator"" _Foo();
Index: gcc/testsuite/g++.dg/cpp0x/udlit-concat.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-concat.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-concat.C	(revision 0)
@@ -0,0 +1,24 @@
+// { dg-options "-std=c++0x" }
+
+#include <string>
+
+std::string operator"" _www(const char*, size_t);
+
+std::string concat01 = "Hello, " "World!"_www;
+
+std::string concat10 = "Hello, "_www "World!";
+
+std::string concat11 = "Hello, "_www "World!"_www;
+
+
+class Tachyon { };
+
+Tachyon operator"" _fast(const char*, size_t);
+
+int operator"" _fast(const char32_t*, size_t);
+
+int speedy01 = "Hello, " U"World!"_fast;
+
+int speedy10 = "Hello, "_fast U"World!";
+
+int speedy11 = "Hello, "_fast U"World!"_fast;
Index: gcc/cp/typeck.c
===================================================================
--- gcc/cp/typeck.c	(revision 180284)
+++ gcc/cp/typeck.c	(working copy)
@@ -8352,3 +8352,121 @@
   return 1;
 }
 
+/* Return true if a user-defined literal operator is a raw operator.  */
+
+bool
+check_raw_literal_operator (const_tree decl)
+{
+  tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
+  tree argtype;
+  int arity;
+  bool maybe_raw_p = false;
+
+  /* Count the number and type of arguments and check for ellipsis.  */
+  for (argtype = argtypes, arity = 0;
+       argtype && argtype != void_list_node;
+       ++arity, argtype = TREE_CHAIN (argtype))
+    {
+      tree t = TREE_VALUE (argtype);
+
+      if (same_type_p (t, const_string_type_node))
+	maybe_raw_p = true;
+    }
+  if (!argtype)
+    return false; /* Found ellipsis.  */
+
+  if (!maybe_raw_p || arity != 1)
+    return false;
+
+  return true;
+}
+
+
+/* Return true if a user-defined literal operator has one of the allowed
+   argument types.  */
+
+bool
+check_literal_operator_args (const_tree decl,
+			     bool *long_long_unsigned_p, bool *long_double_p)
+{
+  tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
+  if (processing_template_decl)
+    return (argtypes == NULL_TREE
+	    || same_type_p (TREE_VALUE (argtypes), void_type_node));
+  else
+    {
+      tree argtype;
+      int arity;
+      int max_arity = 2;
+      bool found_string_p = false;
+      bool maybe_raw_p = false;
+      bool found_size_p = false;
+      tree const_wchar_ptr_type_node
+	   = build_pointer_type (build_type_variant (wchar_type_node, 1, 0));
+      tree const_char16_ptr_type_node
+	   = build_pointer_type (build_type_variant (char16_type_node, 1, 0));
+      tree const_char32_ptr_type_node
+	   = build_pointer_type (build_type_variant (char32_type_node, 1, 0));
+
+      *long_long_unsigned_p = false;
+      *long_double_p = false;
+
+      /* Count the number and type of arguments and check for ellipsis.  */
+      for (argtype = argtypes, arity = 0;
+	   argtype && argtype != void_list_node;
+	   argtype = TREE_CHAIN (argtype))
+	{
+	  tree t = TREE_VALUE (argtype);
+	  ++arity;
+
+	  if (same_type_p (t, const_string_type_node))
+	    {
+	      found_string_p = true;
+	      maybe_raw_p = true;
+	    }
+	  else if (same_type_p (t, const_wchar_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, const_char16_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, const_char32_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, size_type_node))
+	    {
+	      if (!found_string_p)
+		return false;
+	      found_size_p = true;
+	    }
+	  else if (same_type_p (t, long_long_unsigned_type_node))
+	    {
+	      max_arity = 1;
+	      *long_long_unsigned_p = true;
+	    }
+	  else if (same_type_p (t, long_double_type_node))
+	    {
+	      max_arity = 1;
+	      *long_double_p = true;
+	    }
+	  else if (same_type_p (t, char_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, wchar_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, char16_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, char32_type_node))
+	    max_arity = 1;
+	  else
+	    return false;
+	}
+      if (!argtype)
+	return false; /* Found ellipsis.  */
+
+      if (arity > max_arity)
+	return false;
+
+      if (found_string_p && !maybe_raw_p && !found_size_p)
+	return false;
+
+      return true;
+    }
+}
+
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 180284)
+++ gcc/cp/decl.c	(working copy)
@@ -1203,6 +1203,21 @@
       || TREE_TYPE (olddecl) == error_mark_node)
     return error_mark_node;
 
+  if (UDLIT_OPER_P (DECL_NAME (newdecl))
+      && UDLIT_OPER_P (DECL_NAME (olddecl)))
+    {
+      if (TREE_CODE (newdecl) == TEMPLATE_DECL
+	  && TREE_CODE (olddecl) != TEMPLATE_DECL
+	  && check_raw_literal_operator (olddecl))
+	error ("literal operator template %q+D conflicts with"
+	       " raw literal operator %qD", newdecl, olddecl);
+      else if (TREE_CODE (newdecl) != TEMPLATE_DECL
+	       && TREE_CODE (olddecl) == TEMPLATE_DECL
+	       && check_raw_literal_operator (newdecl))
+	error ("raw literal operator %q+D conflicts with"
+	       " literal operator template %qD", newdecl, olddecl);
+    }
+
   if (DECL_P (olddecl)
       && TREE_CODE (newdecl) == FUNCTION_DECL
       && TREE_CODE (olddecl) == FUNCTION_DECL
@@ -7343,7 +7358,48 @@
   if (IDENTIFIER_OPNAME_P (DECL_NAME (decl))
       && !grok_op_properties (decl, /*complain=*/true))
     return NULL_TREE;
+  else if (UDLIT_OPER_P (DECL_NAME (decl)))
+    {
+      bool long_long_unsigned_p;
+      bool long_double_p;
+      const char *suffix = NULL;
+      /* [over.literal]/6: Literal operators shall not have C linkage. */
+      if (DECL_LANGUAGE (decl) == lang_c)
+	{
+	  error ("literal operator with C linkage");
+	  return NULL_TREE;
+	}
 
+      if (DECL_NAMESPACE_SCOPE_P (decl))
+	{
+	  if (!check_literal_operator_args (decl, &long_long_unsigned_p,
+					    &long_double_p))
+	    {
+	      error ("%qD has invalid argument list", decl);
+	      return NULL_TREE;
+	    }
+
+	  suffix = UDLIT_OP_SUFFIX (DECL_NAME (decl));
+	  if (long_long_unsigned_p)
+	    {
+	      if (cpp_interpret_int_suffix (suffix, strlen (suffix)))
+		warning (0, "integer suffix %<%s%>"
+			    " shadowed by implementation", suffix);
+	    }
+	  else if (long_double_p)
+	    {
+	      if (cpp_interpret_float_suffix (suffix, strlen (suffix)))
+		warning (0, "floating point suffix %<%s%>"
+			    " shadowed by implementation", suffix);
+	    }
+	}
+      else
+	{
+	  error ("%qD must be a non-member function", decl);
+	  return NULL_TREE;
+	}
+    }
+
   if (funcdef_flag)
     /* Make the init_value nonzero so pushdecl knows this is not
        tentative.  error_mark_node is replaced later with the BLOCK.  */
@@ -8534,6 +8590,15 @@
       error ("declaration of %qD as non-function", dname);
       return error_mark_node;
     }
+ 
+  if (dname
+      && TREE_CODE (dname) == IDENTIFIER_NODE
+      && UDLIT_OPER_P (dname)
+      && innermost_code != cdk_function)
+    {
+      error ("declaration of %qD as non-function", dname);
+      return error_mark_node;
+    }
 
   if (dname && IDENTIFIER_OPNAME_P (dname))
     {
@@ -13752,6 +13817,7 @@
     case TRAIT_EXPR:		return TS_CP_TRAIT_EXPR;
     case LAMBDA_EXPR:		return TS_CP_LAMBDA_EXPR;
     case TEMPLATE_INFO:		return TS_CP_TEMPLATE_INFO;
+    case USERDEF_LITERAL:	return TS_CP_USERDEF_LITERAL;
     default:			return TS_CP_GENERIC;
     }
 }
Index: gcc/cp/error.c
===================================================================
--- gcc/cp/error.c	(revision 180284)
+++ gcc/cp/error.c	(working copy)
@@ -1534,6 +1534,8 @@
     }
   else if (name && IDENTIFIER_OPNAME_P (name))
     pp_cxx_tree_identifier (cxx_pp, name);
+  else if (name && UDLIT_OPER_P (name))
+    pp_cxx_tree_identifier (cxx_pp, name);
   else
     dump_decl (name, flags);
 
@@ -1756,6 +1758,10 @@
       pp_constant (cxx_pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (cxx_pp, t);
+      break;
+
     case THROW_EXPR:
       /* While waiting for caret diagnostics, avoid printing
 	 __cxa_allocate_exception, __cxa_throw, and the like.  */
@@ -3233,7 +3239,7 @@
 	pedwarn (input_location, OPT_pedantic,
 		 "inline namespaces "
 		 "only available with -std=c++0x or -std=gnu++0x");
-	break;	
+	break;
       case CPP0X_OVERRIDE_CONTROLS:
 	pedwarn (input_location, 0,
 		 "override controls (override/final) "
@@ -3244,8 +3250,13 @@
 		 "non-static data member initializers "
 		 "only available with -std=c++0x or -std=gnu++0x");
         break;
+      case CPP0X_USER_DEFINED_LITERALS:
+	pedwarn (input_location, 0,
+		 "user-defined literals "
+		 "only available with -std=c++0x or -std=gnu++0x");
+	break;
       default:
-	gcc_unreachable();
+	gcc_unreachable ();
       }
 }
 
Index: gcc/cp/cxx-pretty-print.c
===================================================================
--- gcc/cp/cxx-pretty-print.c	(revision 180284)
+++ gcc/cp/cxx-pretty-print.c	(working copy)
@@ -367,6 +367,17 @@
     pp_cxx_unqualified_id (pp, t);
 }
 
+/* user-defined literal:
+      literal ud-suffix  */
+
+void
+pp_cxx_userdef_literal (cxx_pretty_printer *pp, tree t)
+{
+  pp_cxx_constant (pp, USERDEF_LITERAL_VALUE (t));
+  pp_cxx_id_expression (pp, USERDEF_LITERAL_SUFFIX_ID (t));
+}
+
+
 /* primary-expression:
      literal
      this
@@ -413,6 +424,10 @@
       pp_cxx_constant (pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (pp, t);
+      break;
+
     case BASELINK:
       t = BASELINK_FUNCTIONS (t);
     case VAR_DECL:
@@ -1024,6 +1039,10 @@
       pp_cxx_constant (pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (pp, t);
+      break;
+
     case RESULT_DECL:
       pp_cxx_unqualified_id (pp, t);
       break;
Index: gcc/cp/semantics.c
===================================================================
--- gcc/cp/semantics.c	(revision 180284)
+++ gcc/cp/semantics.c	(working copy)
@@ -7865,6 +7865,7 @@
     case TEMPLATE_PARM_INDEX:
     case TRAIT_EXPR:
     case IDENTIFIER_NODE:
+    case USERDEF_LITERAL:
       /* We can see a FIELD_DECL in a pointer-to-member expression.  */
     case FIELD_DECL:
     case PARM_DECL:
Index: gcc/cp/cxx-pretty-print.h
===================================================================
--- gcc/cp/cxx-pretty-print.h	(revision 180284)
+++ gcc/cp/cxx-pretty-print.h	(working copy)
@@ -74,5 +74,7 @@
 void pp_cxx_trait_expression (cxx_pretty_printer *, tree);
 void pp_cxx_va_arg_expression (cxx_pretty_printer *, tree);
 void pp_cxx_offsetof_expression (cxx_pretty_printer *, tree);
+void pp_cxx_userdef_literal (cxx_pretty_printer *, tree);
 
+
 #endif /* GCC_CXX_PRETTY_PRINT_H */
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 180284)
+++ gcc/cp/parser.c	(working copy)
@@ -225,6 +225,9 @@
 static void cp_parser_initial_pragma
   (cp_token *);
 
+static tree cp_literal_operator_id
+  (const char *);
+
 /* Manifest constants.  */
 #define CP_LEXER_BUFFER_SIZE ((256 * 1024) / sizeof (cp_token))
 #define CP_SAVED_TOKEN_STACK 5
@@ -1762,6 +1765,12 @@
   (cp_parser *);
 static tree cp_parser_string_literal
   (cp_parser *, bool, bool);
+static tree cp_parser_userdef_char_literal
+  (cp_parser *);
+static tree cp_parser_userdef_string_literal
+  (cp_token *);
+static tree cp_parser_userdef_numeric_literal
+  (cp_parser *);
 
 /* Basic concepts [gram.basic]  */
 
@@ -2270,6 +2279,8 @@
   (cp_parser *);
 static bool cp_parser_allow_gnu_extensions_p
   (cp_parser *);
+static bool cp_parser_is_pure_string_literal
+  (cp_token *);
 static bool cp_parser_is_string_literal
   (cp_token *);
 static bool cp_parser_is_keyword
@@ -2290,7 +2301,7 @@
 /* Returns nonzero if TOKEN is a string literal.  */
 
 static bool
-cp_parser_is_string_literal (cp_token* token)
+cp_parser_is_pure_string_literal (cp_token* token)
 {
   return (token->type == CPP_STRING ||
 	  token->type == CPP_STRING16 ||
@@ -2299,6 +2310,20 @@
 	  token->type == CPP_UTF8STRING);
 }
 
+/* Returns nonzero if TOKEN is a string literal
+   of a user-defined string literal.  */
+
+static bool
+cp_parser_is_string_literal (cp_token* token)
+{
+  return (cp_parser_is_pure_string_literal (token) ||
+	  token->type == CPP_STRING_USERDEF ||
+	  token->type == CPP_STRING16_USERDEF ||
+	  token->type == CPP_STRING32_USERDEF ||
+	  token->type == CPP_WSTRING_USERDEF ||
+	  token->type == CPP_UTF8STRING_USERDEF);
+}
+
 /* Returns nonzero if TOKEN is the indicated KEYWORD.  */
 
 static bool
@@ -3338,7 +3363,11 @@
   struct obstack str_ob;
   cpp_string str, istr, *strs;
   cp_token *tok;
-  enum cpp_ttype type;
+  enum cpp_ttype type, curr_type;
+  int have_suffix_p = 0;
+  tree string_tree;
+  tree suffix_id = NULL_TREE;
+  bool curr_tok_is_userdef_p = false;
 
   tok = cp_lexer_peek_token (parser->lexer);
   if (!cp_parser_is_string_literal (tok))
@@ -3347,7 +3376,18 @@
       return error_mark_node;
     }
 
-  type = tok->type;
+  if (cpp_userdef_string_p (tok->type))
+    {
+      string_tree = USERDEF_LITERAL_VALUE (tok->u.value);
+      curr_type = cpp_userdef_string_remove_type (tok->type);
+      curr_tok_is_userdef_p = true;
+    }
+  else
+    {
+      string_tree = tok->u.value;
+      curr_type = tok->type;
+    }
+  type = curr_type;
 
   /* Try to avoid the overhead of creating and destroying an obstack
      for the common case of just one string.  */
@@ -3356,10 +3396,19 @@
     {
       cp_lexer_consume_token (parser->lexer);
 
-      str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value);
-      str.len = TREE_STRING_LENGTH (tok->u.value);
+      str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree);
+      str.len = TREE_STRING_LENGTH (string_tree);
       count = 1;
 
+      if (curr_tok_is_userdef_p)
+	{
+	  suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value);
+	  have_suffix_p = 1;
+	  curr_type = cpp_userdef_string_remove_type (tok->type);
+	}
+      else
+	curr_type = tok->type;
+
       strs = &str;
     }
   else
@@ -3371,14 +3420,35 @@
 	{
 	  cp_lexer_consume_token (parser->lexer);
 	  count++;
-	  str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value);
-	  str.len = TREE_STRING_LENGTH (tok->u.value);
+	  str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree);
+	  str.len = TREE_STRING_LENGTH (string_tree);
 
-	  if (type != tok->type)
+	  if (curr_tok_is_userdef_p)
 	    {
+	      tree curr_suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value);
+	      if (have_suffix_p == 0)
+		{
+		  suffix_id = curr_suffix_id;
+		  have_suffix_p = 1;
+		}
+	      else if (have_suffix_p == 1
+		       && curr_suffix_id != suffix_id)
+		{
+		  error ("inconsistent user-defined literal suffixes"
+			 " %qD and %qD in string literal",
+			 suffix_id, curr_suffix_id);
+		  have_suffix_p = -1;
+		}
+	      curr_type = cpp_userdef_string_remove_type (tok->type);
+	    }
+	  else
+	    curr_type = tok->type;
+
+	  if (type != curr_type)
+	    {
 	      if (type == CPP_STRING)
-		type = tok->type;
-	      else if (tok->type != CPP_STRING)
+		type = curr_type;
+	      else if (curr_type != CPP_STRING)
 		error_at (tok->location,
 			  "unsupported non-standard concatenation "
 			  "of string literals");
@@ -3387,6 +3457,18 @@
 	  obstack_grow (&str_ob, &str, sizeof (cpp_string));
 
 	  tok = cp_lexer_peek_token (parser->lexer);
+	  if (cpp_userdef_string_p (tok->type))
+	    {
+	      string_tree = USERDEF_LITERAL_VALUE (tok->u.value);
+	      curr_type = cpp_userdef_string_remove_type (tok->type);
+	      curr_tok_is_userdef_p = true;
+	    }
+	  else
+	    {
+	      string_tree = tok->u.value;
+	      curr_type = tok->type;
+	      curr_tok_is_userdef_p = false;
+	    }
 	}
       while (cp_parser_is_string_literal (tok));
 
@@ -3424,6 +3506,13 @@
 	}
 
       value = fix_string_type (value);
+
+      if (have_suffix_p)
+	{
+	  tree literal = build_userdef_literal (suffix_id, value, NULL_TREE);
+	  tok->u.value = literal;
+	  return cp_parser_userdef_string_literal (tok);
+	}
     }
   else
     /* cpp_interpret_string has issued an error.  */
@@ -3435,7 +3524,187 @@
   return value;
 }
 
+/* Parse a user-defined char constant.  Returns a call to a user-defined
+   literal operator taking the character as an argument.  */
 
+static tree
+cp_parser_userdef_char_literal (cp_parser *parser)
+{
+  cp_token *token = NULL;
+  tree literal, suffix_id, value;
+  tree name, decl;
+  tree result;
+  VEC(tree,gc) *vec;
+
+  token = cp_lexer_consume_token (parser->lexer);
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  value = USERDEF_LITERAL_VALUE (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  vec = make_tree_vector ();
+  VEC_safe_push (tree, gc, vec, value);
+  decl = lookup_function_nonclass (name, vec, /*block_p=*/false);
+  if (!decl || decl == error_mark_node)
+    {
+      error ("unable to find user-defined character literal operator %qD",
+	     name);
+      release_tree_vector (vec);
+      return error_mark_node;
+    }
+  result = finish_call_expr (decl, &vec, false, true, tf_warning_or_error);
+  release_tree_vector (vec);
+
+  return result;
+}
+
+/* A subroutine of cp_parser_userdef_numeric_literal to
+   create a char... template parameter pack from a string node.  */
+
+static tree
+make_char_string_pack (tree value)
+{
+  tree charvec;
+  tree argpack = make_node (NONTYPE_ARGUMENT_PACK);
+  const char *str = TREE_STRING_POINTER (value);
+  int i, len = TREE_STRING_LENGTH (value) - 1;
+  tree argvec = make_tree_vec (1);
+
+  /* Fill in CHARVEC with all of the parameters.  */
+  charvec = make_tree_vec (len);
+  for (i = 0; i < len; ++i)
+    TREE_VEC_ELT (charvec, i) = build_int_cst (char_type_node, str[i]);
+
+  /* Build the argument packs.  */
+  SET_ARGUMENT_PACK_ARGS (argpack, charvec);
+  TREE_TYPE (argpack) = char_type_node;
+
+  TREE_VEC_ELT (argvec, 0) = argpack;
+
+  return argvec;
+}
+
+/* Parse a user-defined numeric constant.  returns a call to a user-defined
+   literal operator.  */
+
+static tree
+cp_parser_userdef_numeric_literal (cp_parser *parser)
+{
+  cp_token *token = NULL;
+  tree literal, suffix_id, value, num_string;
+  tree name, decl;
+  tree result = error_mark_node;
+  VEC(tree,gc) *args;
+
+  token = cp_lexer_consume_token (parser->lexer);
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  value = USERDEF_LITERAL_VALUE (literal);
+  num_string = USERDEF_LITERAL_NUM_STRING (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  /* Try to find the literal operator by finishing the call expression
+     with the numeric argument.  */
+  args = make_tree_vector ();
+  VEC_safe_push (tree, gc, args, value);
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl && decl != error_mark_node)
+    {
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  /* If the numeric argument didn't work, look for a raw literal
+     operator taking a const char* argument consisting of the number
+     in string format.  */
+  args = make_tree_vector ();
+  VEC_safe_push (tree, gc, args, num_string);
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl && decl != error_mark_node)
+    {
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  /* If the raw literal didn't work, look for a non-type template
+     function with parameter pack char....  Call the function with
+     template parameter characters representing the number.  */
+  args = make_tree_vector ();
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl && decl != error_mark_node)
+    {
+      tree tmpl_args = make_char_string_pack (num_string);
+      decl = lookup_template_function (decl, tmpl_args);
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  if (result == error_mark_node)
+    error ("unable to find user-defined numeric literal operator %qD", name);
+
+  return result;
+}
+
+/* Parse a user-defined string constant.  Returns a call to a user-defined
+   literal operator taking a character pointer and the length of the string
+   as arguments.  */
+static tree
+cp_parser_userdef_string_literal (cp_token *token)
+{
+  tree literal, suffix_id, value;
+  tree name, decl;
+  tree result;
+  VEC(tree,gc) *vec;
+  int len;
+
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+  value = USERDEF_LITERAL_VALUE (literal);
+  len = TREE_STRING_LENGTH (value) - 1;
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  vec = make_tree_vector ();
+  VEC_safe_push (tree, gc, vec, value);
+  VEC_safe_push (tree, gc, vec, build_int_cst (size_type_node, len));
+  decl = lookup_function_nonclass (name, vec, /*block_p=*/false);
+  if (!decl || decl == error_mark_node)
+    {
+      error ("unable to find user-defined string literal operator %qD", name);
+      release_tree_vector (vec);
+      return error_mark_node;
+    }
+  result = finish_call_expr (decl, &vec, false, true, tf_none);
+  if (result == error_mark_node)
+    error ("invalid string literal prefix %<\"%s\"%> for user-defined"
+	   " raw literal operator %qD.  Remove quotes.",
+	   TREE_STRING_POINTER (value), name);
+  release_tree_vector (vec);
+
+  return result;
+}
+
+
 /* Basic concepts [gram.basic]  */
 
 /* Parse a translation-unit.
@@ -3578,12 +3847,16 @@
 	   character-literal
 	   floating-literal
 	   string-literal
-	   boolean-literal  */
+	   boolean-literal
+	   pointer-literal
+	   user-defined-literal  */
     case CPP_CHAR:
     case CPP_CHAR16:
     case CPP_CHAR32:
     case CPP_WCHAR:
     case CPP_NUMBER:
+      if (TREE_CODE (token->u.value) == USERDEF_LITERAL)
+	return cp_parser_userdef_numeric_literal (parser);
       token = cp_lexer_consume_token (parser->lexer);
       if (TREE_CODE (token->u.value) == FIXED_CST)
 	{
@@ -3637,11 +3910,22 @@
 	}
       return token->u.value;
 
+    case CPP_CHAR_USERDEF:
+    case CPP_CHAR16_USERDEF:
+    case CPP_CHAR32_USERDEF:
+    case CPP_WCHAR_USERDEF:
+      return cp_parser_userdef_char_literal (parser);
+
     case CPP_STRING:
     case CPP_STRING16:
     case CPP_STRING32:
     case CPP_WSTRING:
     case CPP_UTF8STRING:
+    case CPP_STRING_USERDEF:
+    case CPP_STRING16_USERDEF:
+    case CPP_STRING32_USERDEF:
+    case CPP_WSTRING_USERDEF:
+    case CPP_UTF8STRING_USERDEF:
       /* ??? Should wide strings be allowed when parser->translate_strings_p
 	 is false (i.e. in attributes)?  If not, we can kill the third
 	 argument to cp_parser_string_literal.  */
@@ -4477,6 +4761,14 @@
 	  /* If that didn't work, try a conversion-function-id.  */
 	  if (!cp_parser_parse_definitely (parser))
 	    id = cp_parser_conversion_function_id (parser);
+	  else if (UDLIT_OPER_P (id))
+	    {
+	      /* 17.6.3.3.5  */
+	      const char *name = UDLIT_OP_SUFFIX (id);
+	      if (name[0] != '_' && !in_system_header)
+		warning (0, "literal operator suffixes not preceded by %<_%>"
+			    " are reserved for future standardization");
+	    }
 
 	  return id;
 	}
@@ -5119,7 +5411,7 @@
 	/* Restore the saved message.  */
 	parser->type_definition_forbidden_message = saved_message;
 	/* `typeid' may not appear in an integral constant expression.  */
-	if (cp_parser_non_integral_constant_expression(parser, NIC_TYPEID))
+	if (cp_parser_non_integral_constant_expression (parser, NIC_TYPEID))
 	  return error_mark_node;
       }
       break;
@@ -9739,7 +10031,7 @@
   /* If the next token is `extern' and the following token is a string
      literal, then we have a linkage specification.  */
   if (token1.keyword == RID_EXTERN
-      && cp_parser_is_string_literal (&token2))
+      && cp_parser_is_pure_string_literal (&token2))
     cp_parser_linkage_specification (parser);
   /* If the next token is `template', then we have either a template
      declaration, an explicit instantiation, or an explicit
@@ -11170,6 +11462,22 @@
   return cp_parser_operator (parser);
 }
 
+/* Return an identifier node for a user-defined literal operator.
+   The suffix identifier is chained to the operator name identifier.  */
+
+static tree
+cp_literal_operator_id (const char* name)
+{
+  tree identifier;
+  char *buffer = XNEWVEC (char, strlen (UDLIT_OP_ANSI_PREFIX)
+			      + strlen (name) + 10);
+  sprintf (buffer, UDLIT_OP_ANSI_FORMAT, name);
+  identifier = get_identifier (buffer);
+  /*IDENTIFIER_UDLIT_OPNAME_P (identifier) = 1; If we get a flag someday. */
+
+  return identifier;
+}
+
 /* Parse an operator.
 
    operator:
@@ -11389,6 +11697,37 @@
       cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE);
       return ansi_opname (ARRAY_REF);
 
+    case CPP_STRING:
+      if (cxx_dialect == cxx98)
+	maybe_warn_cpp0x (CPP0X_USER_DEFINED_LITERALS);
+      if (TREE_STRING_LENGTH (token->u.value) > 2)
+	{
+	  error ("expected empty string after %<operator%> keyword");
+	  return error_mark_node;
+	}
+      /* Consume the string.  */
+      cp_lexer_consume_token (parser->lexer);
+      /* Look for the suffix identifier.  */
+      token = cp_lexer_peek_token (parser->lexer);
+      if (token->type == CPP_NAME)
+	{
+	  id = cp_parser_identifier (parser);
+	  if (id != error_mark_node)
+	    {
+	      const char *name = IDENTIFIER_POINTER (id);
+	      return cp_literal_operator_id (name);
+	    }
+	}
+      else
+	{
+	  error ("expected suffix identifier");
+	  return error_mark_node;
+	}
+
+    case CPP_STRING_USERDEF:
+      error ("missing space between %<\"\"%> and suffix identifier");
+      return error_mark_node;
+
     default:
       /* Anything else is an error.  */
       break;
@@ -20583,6 +20922,33 @@
   /* Finish up.  */
   finish_template_decl (parameter_list);
 
+  /* Check the template arguments for a literal operator template.  */
+  if (decl
+      && (TREE_CODE (decl) == FUNCTION_DECL || DECL_FUNCTION_TEMPLATE_P (decl))
+      && UDLIT_OPER_P (DECL_NAME (decl)))
+    {
+      bool ok = true;
+      if (parameter_list == NULL_TREE)
+	ok = false;
+      else
+	{
+	  int num_parms = TREE_VEC_LENGTH (parameter_list);
+	  if (num_parms != 1)
+	    ok = false;
+	  else
+	    {
+	      tree parm_list = TREE_VEC_ELT (parameter_list, 0);
+	      tree parm = INNERMOST_TEMPLATE_PARMS (parm_list);
+	      if (TREE_TYPE (parm) != char_type_node
+		  || !TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (parm)))
+		ok = false;
+	    }
+	}
+      if (!ok)
+	error ("literal operator template %qD has invalid parameter list."
+	       "  Expected non-type template argument pack <char...>",
+	       decl);
+    }
   /* Register member declarations.  */
   if (member_p && !friend_p && decl && !DECL_CLASS_TEMPLATE_P (decl))
     finish_member_declaration (decl);
@@ -22891,7 +23257,8 @@
   /* If the next token is `extern' and the following token is a string
      literal, then we have a linkage specification.  */
   if (token->keyword == RID_EXTERN
-      && cp_parser_is_string_literal (cp_lexer_peek_nth_token (parser->lexer, 2)))
+      && cp_parser_is_pure_string_literal
+	 (cp_lexer_peek_nth_token (parser->lexer, 2)))
     cp_parser_linkage_specification (parser);
   /* Handle #pragma, if any.  */
   else if (token->type == CPP_PRAGMA)
Index: gcc/cp/cp-objcp-common.c
===================================================================
--- gcc/cp/cp-objcp-common.c	(revision 180284)
+++ gcc/cp/cp-objcp-common.c	(working copy)
@@ -100,6 +100,8 @@
 
     case TEMPLATE_INFO:         return sizeof (struct tree_template_info);
 
+    case USERDEF_LITERAL:	return sizeof (struct tree_userdef_literal);
+
     default:
       gcc_unreachable ();
     }
Index: gcc/cp/mangle.c
===================================================================
--- gcc/cp/mangle.c	(revision 180284)
+++ gcc/cp/mangle.c	(working copy)
@@ -181,6 +181,7 @@
 static void write_unqualified_name (const tree);
 static void write_conversion_operator_name (const tree);
 static void write_source_name (tree);
+static void write_literal_operator_name (tree);
 static void write_unnamed_type_name (const tree);
 static void write_closure_type_name (const tree);
 static int hwint_to_ascii (unsigned HOST_WIDE_INT, const unsigned int, char *,
@@ -1174,6 +1175,8 @@
 	  }
       write_string (mangled_name);
     }
+  else if (UDLIT_OPER_P (identifier))
+    write_literal_operator_name (identifier);
   else
     write_source_name (identifier);
 }
@@ -1227,6 +1230,8 @@
 
 	  write_string (oni[DECL_OVERLOADED_OPERATOR_P (decl)].mangled_name);
 	}
+      else if (UDLIT_OPER_P (DECL_NAME (decl)))
+	write_literal_operator_name (DECL_NAME (decl));
       else
 	found = false;
 
@@ -1286,6 +1291,21 @@
   write_identifier (IDENTIFIER_POINTER (identifier));
 }
 
+/* Write a user-defined literal operator.
+   IDENTIFIER is an LITERAL_IDENTIFIER_NODE.  */
+
+static void
+write_literal_operator_name (tree identifier)
+{
+  const char* suffix = UDLIT_OP_SUFFIX (identifier);
+  char* buffer = XNEWVEC (char, strlen (UDLIT_OP_MANGLED_PREFIX)
+			      + strlen (suffix) + 10);
+  sprintf (buffer, UDLIT_OP_MANGLED_FORMAT, suffix);
+
+  write_unsigned_number (strlen (buffer));
+  write_identifier (buffer);
+}
+
 /* Encode 0 as _, and 1+ as n-1_.  */
 
 static void
Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h	(revision 180284)
+++ gcc/cp/cp-tree.h	(working copy)
@@ -400,7 +400,9 @@
   /* override controls, override/final */
   CPP0X_OVERRIDE_CONTROLS,
   /* non-static data member initializers */
-  CPP0X_NSDMI
+  CPP0X_NSDMI,
+  /* user defined literals */
+  CPP0X_USER_DEFINED_LITERALS
 } cpp0x_warn_str;
   
 /* The various kinds of operation used by composite_pointer_type. */
@@ -740,6 +742,7 @@
   TS_CP_TRAIT_EXPR,
   TS_CP_LAMBDA_EXPR,
   TS_CP_TEMPLATE_INFO,
+  TS_CP_USERDEF_LITERAL,
   LAST_TS_CP_ENUM
 };
 
@@ -765,6 +768,8 @@
     lambda_expression;
   struct tree_template_info GTY ((tag ("TS_CP_TEMPLATE_INFO")))
     template_info;
+  struct tree_userdef_literal GTY ((tag ("TS_CP_USERDEF_LITERAL")))
+    userdef_literal;
 };
 
 \f
@@ -4228,6 +4233,17 @@
              LAMBDANAME_PREFIX, \
 	     sizeof (LAMBDANAME_PREFIX) - 1))
 
+#define UDLIT_OP_ANSI_PREFIX "operator\"\" "
+#define UDLIT_OP_ANSI_FORMAT UDLIT_OP_ANSI_PREFIX "%s"
+#define UDLIT_OP_MANGLED_PREFIX "li"
+#define UDLIT_OP_MANGLED_FORMAT UDLIT_OP_MANGLED_PREFIX "%s"
+#define UDLIT_OPER_P(ID_NODE) \
+  (!strncmp (IDENTIFIER_POINTER (ID_NODE), \
+             UDLIT_OP_ANSI_PREFIX, \
+	     sizeof (UDLIT_OP_ANSI_PREFIX) - 1))
+#define UDLIT_OP_SUFFIX(ID_NODE) \
+  (IDENTIFIER_POINTER (ID_NODE) + sizeof (UDLIT_OP_ANSI_PREFIX) - 1)
+
 #if !defined(NO_DOLLAR_IN_LABEL) || !defined(NO_DOT_IN_LABEL)
 
 #define VTABLE_NAME_P(ID_NODE) (IDENTIFIER_POINTER (ID_NODE)[1] == 'v' \
@@ -5758,6 +5774,8 @@
 extern int lvalue_or_else			(tree, enum lvalue_use,
                                                  tsubst_flags_t);
 extern void check_template_keyword		(tree);
+extern bool check_raw_literal_operator		(const_tree decl);
+extern bool check_literal_operator_args		(const_tree, bool *, bool *);
 
 /* in typeck2.c */
 extern void require_complete_eh_spec_types	(tree, tree);
Index: libcpp/include/cpplib.h
===================================================================
--- libcpp/include/cpplib.h	(revision 180284)
+++ libcpp/include/cpplib.h	(working copy)
@@ -131,6 +131,16 @@
   TK(OBJC_STRING,	LITERAL) /* @"string" - Objective-C */		\
   TK(HEADER_NAME,	LITERAL) /* <stdio.h> in #include */		\
 									\
+  TK(CHAR_USERDEF,	LITERAL) /* 'char'_suffix - C++-0x */		\
+  TK(WCHAR_USERDEF,	LITERAL) /* L'char'_suffix - C++-0x */		\
+  TK(CHAR16_USERDEF,	LITERAL) /* u'char'_suffix - C++-0x */		\
+  TK(CHAR32_USERDEF,	LITERAL) /* U'char'_suffix - C++-0x */		\
+  TK(STRING_USERDEF,	LITERAL) /* "string"_suffix - C++-0x */		\
+  TK(WSTRING_USERDEF,	LITERAL) /* L"string"_suffix - C++-0x */	\
+  TK(STRING16_USERDEF,	LITERAL) /* u"string"_suffix - C++-0x */	\
+  TK(STRING32_USERDEF,	LITERAL) /* U"string"_suffix - C++-0x */	\
+  TK(UTF8STRING_USERDEF,LITERAL) /* u8"string"_suffix - C++-0x */	\
+									\
   TK(COMMENT,		LITERAL) /* Only if output comments.  */	\
 				 /* SPELL_LITERAL happens to DTRT.  */	\
   TK(MACRO_ARG,		NONE)	 /* Macro argument.  */			\
@@ -414,6 +424,9 @@
   /* True for traditional preprocessing.  */
   unsigned char traditional;
 
+  /* Nonzero for C++ 2011 Standard user-defnied literals.  */
+  unsigned char user_literals;
+
   /* Holds the name of the target (execution) character set.  */
   const char *narrow_charset;
 
@@ -829,13 +842,22 @@
 #define CPP_N_FRACT	0x100000 /* Fract types.  */
 #define CPP_N_ACCUM	0x200000 /* Accum types.  */
 
+#define CPP_N_USERDEF	0x1000000 /* C++0x user-defined literal.  */
+
 /* Classify a CPP_NUMBER token.  The return value is a combination of
    the flags from the above sets.  */
-extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *);
+extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *,
+				     const char **);
 
+/* Return the classification flags for a float suffix.  */
+extern unsigned int cpp_interpret_float_suffix (const char *, size_t);
+
+/* Return the classification flags for an int suffix.  */
+extern unsigned int cpp_interpret_int_suffix (const char *, size_t);
+
 /* Evaluate a token classified as category CPP_N_INTEGER.  */
 extern cpp_num cpp_interpret_integer (cpp_reader *, const cpp_token *,
-				      unsigned int type);
+				      unsigned int);
 
 /* Sign extend a number, with PRECISION significant bits and all
    others assumed clear, to fill out a cpp_num structure.  */
@@ -1005,4 +1027,20 @@
 extern void cpp_force_token_locations (cpp_reader *, source_location *);
 extern void cpp_stop_forcing_token_locations (cpp_reader *);
 
+/* In expr.c */
+extern enum cpp_ttype cpp_userdef_string_remove_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_string_add_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_char_remove_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_char_add_type
+  (enum cpp_ttype type);
+extern bool cpp_userdef_string_p
+  (enum cpp_ttype type);
+extern bool cpp_userdef_char_p
+  (enum cpp_ttype type);
+extern const char * cpp_get_userdef_suffix
+  (const cpp_token *);
+
 #endif /* ! LIBCPP_CPPLIB_H */
Index: libcpp/init.c
===================================================================
--- libcpp/init.c	(revision 180284)
+++ libcpp/init.c	(working copy)
@@ -80,22 +80,23 @@
   char digraphs;
   char uliterals;
   char rliterals;
+  char user_literals;
 };
 
 static const struct lang_flags lang_defaults[] =
-{ /*              c99 c++ xnum xid std  //   digr ulit rlit */
-  /* GNUC89   */  { 0,  0,  1,   0,  0,   1,   1,   0,   0 },
-  /* GNUC99   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1 },
-  /* GNUC1X   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1 },
-  /* STDC89   */  { 0,  0,  0,   0,  1,   0,   0,   0,   0 },
-  /* STDC94   */  { 0,  0,  0,   0,  1,   0,   1,   0,   0 },
-  /* STDC99   */  { 1,  0,  1,   0,  1,   1,   1,   0,   0 },
-  /* STDC1X   */  { 1,  0,  1,   0,  1,   1,   1,   1,   0 },
-  /* GNUCXX   */  { 0,  1,  1,   0,  0,   1,   1,   0,   0 },
-  /* CXX98    */  { 0,  1,  1,   0,  1,   1,   1,   0,   0 },
-  /* GNUCXX0X */  { 1,  1,  1,   0,  0,   1,   1,   1,   1 },
-  /* CXX0X    */  { 1,  1,  1,   0,  1,   1,   1,   1,   1 },
-  /* ASM      */  { 0,  0,  1,   0,  0,   1,   0,   0,   0 }
+{ /*              c99 c++ xnum xid std  //   digr ulit rlit user_literals */
+  /* GNUC89   */  { 0,  0,  1,   0,  0,   1,   1,   0,   0,    0 },
+  /* GNUC99   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1,    0 },
+  /* GNUC1X   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1,    0 },
+  /* STDC89   */  { 0,  0,  0,   0,  1,   0,   0,   0,   0,    0 },
+  /* STDC94   */  { 0,  0,  0,   0,  1,   0,   1,   0,   0,    0 },
+  /* STDC99   */  { 1,  0,  1,   0,  1,   1,   1,   0,   0,    0 },
+  /* STDC1X   */  { 1,  0,  1,   0,  1,   1,   1,   1,   0,    0 },
+  /* GNUCXX   */  { 0,  1,  1,   0,  0,   1,   1,   0,   0,    0 },
+  /* CXX98    */  { 0,  1,  1,   0,  1,   1,   1,   0,   0,    0 },
+  /* GNUCXX0X */  { 1,  1,  1,   0,  0,   1,   1,   1,   1,    1 },
+  /* CXX0X    */  { 1,  1,  1,   0,  1,   1,   1,   1,   1,    1 },
+  /* ASM      */  { 0,  0,  1,   0,  0,   1,   0,   0,   0,    0 }
   /* xid should be 1 for GNUC99, STDC99, GNUCXX, CXX98, GNUCXX0X, and
      CXX0X when no longer experimental (when all uses of identifiers
      in the compiler have been audited for correct handling of
@@ -120,6 +121,7 @@
   CPP_OPTION (pfile, digraphs)			 = l->digraphs;
   CPP_OPTION (pfile, uliterals)			 = l->uliterals;
   CPP_OPTION (pfile, rliterals)			 = l->rliterals;
+  CPP_OPTION (pfile, user_literals)		 = l->user_literals;
 }
 
 /* Initialize library global state.  */
Index: libcpp/expr.c
===================================================================
--- libcpp/expr.c	(revision 180284)
+++ libcpp/expr.c	(working copy)
@@ -1,6 +1,6 @@
 /* Parse C expressions for cpplib.
    Copyright (C) 1987, 1992, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
-   2002, 2004, 2008, 2009, 2010 Free Software Foundation.
+   2002, 2004, 2008, 2009, 2010, 2011 Free Software Foundation.
    Contributed by Per Bothner, 1994.
 
 This program is free software; you can redistribute it and/or modify it
@@ -185,6 +185,13 @@
 	     q ? CPP_N_MD_Q : CPP_N_DEFAULT));
 }
 
+/* Return the classification flags for a float suffix.  */
+unsigned int
+cpp_interpret_float_suffix (const char *s, size_t len)
+{
+  return interpret_float_suffix ((const unsigned char *)s, len);
+}
+
 /* Subroutine of cpp_classify_number.  S points to an integer suffix
    of length LEN, possibly zero. Returns 0 for an invalid suffix, or a
    flag vector describing the suffix.  */
@@ -219,11 +226,143 @@
 	     : (l == 1) ? CPP_N_MEDIUM : CPP_N_LARGE));
 }
 
+/* Return the classification flags for an int suffix.  */
+unsigned int
+cpp_interpret_int_suffix (const char *s, size_t len)
+{
+  return interpret_int_suffix ((const unsigned char *)s, len);
+}
+
+/* Return the string type corresponding to the the input user-defined string
+   literal type.  If the input type is not a user-defined string literal
+   type return the input type.  */
+enum cpp_ttype
+cpp_userdef_string_remove_type (enum cpp_ttype type)
+{
+  if (type == CPP_STRING_USERDEF)
+    return CPP_STRING;
+  else if (type == CPP_WSTRING_USERDEF)
+    return CPP_WSTRING;
+  else if (type == CPP_STRING16_USERDEF)
+    return CPP_STRING16;
+  else if (type == CPP_STRING32_USERDEF)
+    return CPP_STRING32;
+  else if (type == CPP_UTF8STRING_USERDEF)
+    return CPP_UTF8STRING;
+  else
+    return type;
+}
+
+/* Return the user-defined string literal type corresponding to the input
+   string type.  If the input type is not a string type return the input
+   type.  */
+enum cpp_ttype
+cpp_userdef_string_add_type (enum cpp_ttype type)
+{
+  if (type == CPP_STRING)
+    return CPP_STRING_USERDEF;
+  else if (type == CPP_WSTRING)
+    return CPP_WSTRING_USERDEF;
+  else if (type == CPP_STRING16)
+    return CPP_STRING16_USERDEF;
+  else if (type == CPP_STRING32)
+    return CPP_STRING32_USERDEF;
+  else if (type == CPP_UTF8STRING)
+    return CPP_UTF8STRING_USERDEF;
+  else
+    return type;
+}
+
+/* Return the char type corresponding to the the input user-defined char
+   literal type.  If the input type is not a user-defined char literal
+   type return the input type.  */
+enum cpp_ttype
+cpp_userdef_char_remove_type (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR_USERDEF)
+    return CPP_CHAR;
+  else if (type == CPP_WCHAR_USERDEF)
+    return CPP_WCHAR;
+  else if (type == CPP_CHAR16_USERDEF)
+    return CPP_STRING16;
+  else if (type == CPP_CHAR32_USERDEF)
+    return CPP_STRING32;
+  else
+    return type;
+}
+
+/* Return the user-defined char literal type corresponding to the input
+   char type.  If the input type is not a char type return the input
+   type.  */
+enum cpp_ttype
+cpp_userdef_char_add_type (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR)
+    return CPP_CHAR_USERDEF;
+  else if (type == CPP_WCHAR)
+    return CPP_WCHAR_USERDEF;
+  else if (type == CPP_CHAR16)
+    return CPP_CHAR16_USERDEF;
+  else if (type == CPP_CHAR32)
+    return CPP_CHAR32_USERDEF;
+  else
+    return type;
+}
+
+/* Return true if the token type is a user-defined string literal.  */
+bool
+cpp_userdef_string_p (enum cpp_ttype type)
+{
+  if (type == CPP_STRING_USERDEF
+   || type == CPP_WSTRING_USERDEF
+   || type == CPP_STRING16_USERDEF
+   || type == CPP_STRING32_USERDEF
+   || type == CPP_UTF8STRING_USERDEF)
+    return true;
+  else
+    return false;
+}
+
+/* Return true if the token type is a user-defined char literal.  */
+bool
+cpp_userdef_char_p (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR_USERDEF
+   || type == CPP_WCHAR_USERDEF
+   || type == CPP_CHAR16_USERDEF
+   || type == CPP_CHAR32_USERDEF)
+    return true;
+  else
+    return false;
+}
+
+/* Extract the suffix from a user-defined literal string or char.  */
+const char *
+cpp_get_userdef_suffix (const cpp_token *tok)
+{
+  unsigned int len = tok->val.str.len;
+  const char *text = (const char *)tok->val.str.text;
+  char delim;
+  unsigned int i;
+  for (i = 0; i < len; ++i)
+    if (text[i] == '\'' || text[i] == '"')
+      break;
+  if (i == len)
+    return text + len;
+  delim = text[i];
+  for (i = len; i > 0; --i)
+    if (text[i - 1] == delim)
+      break;
+  return text + i;
+}
+
 /* Categorize numeric constants according to their field (integer,
    floating point, or invalid), radix (decimal, octal, hexadecimal),
-   and type suffixes.  */
+   and type suffixes.  In C++0X if UD_SUFFIX is non null it will be
+   assigned any unrecognized suffix for a user-defined literal.  */
 unsigned int
-cpp_classify_number (cpp_reader *pfile, const cpp_token *token)
+cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
+		     const char **ud_suffix)
 {
   const uchar *str = token->val.str.text;
   const uchar *limit;
@@ -231,6 +370,9 @@
   enum {NOT_FLOAT = 0, AFTER_POINT, AFTER_EXPON} float_flag;
   bool seen_digit;
 
+  if (ud_suffix)
+    *ud_suffix = NULL;
+
   /* If the lexer has done its job, length one can only be a single
      digit.  Fast-path this very common case.  */
   if (token->val.str.len == 1)
@@ -361,10 +503,19 @@
       result = interpret_float_suffix (str, limit - str);
       if (result == 0)
 	{
-	  cpp_error (pfile, CPP_DL_ERROR,
-		     "invalid suffix \"%.*s\" on floating constant",
-		     (int) (limit - str), str);
-	  return CPP_N_INVALID;
+	  if (CPP_OPTION (pfile, user_literals))
+	    {
+	      if (ud_suffix)
+		*ud_suffix = (const char *) str;
+	      result = CPP_N_LARGE | CPP_N_USERDEF;
+	    }
+	  else
+	    {
+	      cpp_error (pfile, CPP_DL_ERROR,
+			 "invalid suffix \"%.*s\" on floating constant",
+			 (int) (limit - str), str);
+	      return CPP_N_INVALID;
+	    }
 	}
 
       /* Traditional C didn't accept any floating suffixes.  */
@@ -406,10 +557,19 @@
       result = interpret_int_suffix (str, limit - str);
       if (result == 0)
 	{
-	  cpp_error (pfile, CPP_DL_ERROR,
-		     "invalid suffix \"%.*s\" on integer constant",
-		     (int) (limit - str), str);
-	  return CPP_N_INVALID;
+	  if (CPP_OPTION (pfile, user_literals))
+	    {
+	      if (ud_suffix)
+		*ud_suffix = (const char *) str;
+	      result = CPP_N_UNSIGNED | CPP_N_LARGE | CPP_N_USERDEF;
+	    }
+	  else
+	    {
+	      cpp_error (pfile, CPP_DL_ERROR,
+			 "invalid suffix \"%.*s\" on integer constant",
+			 (int) (limit - str), str);
+	      return CPP_N_INVALID;
+	    }
 	}
 
       /* Traditional C only accepted the 'L' suffix.
@@ -539,7 +699,7 @@
 	    }
 	}
 
-      if (overflow)
+      if (overflow && !(type & CPP_N_USERDEF))
 	cpp_error (pfile, CPP_DL_PEDWARN,
 		   "integer constant is too large for its type");
       /* If too big to be signed, consider it unsigned.  Only warn for
@@ -748,7 +908,10 @@
   switch (token->type)
     {
     case CPP_NUMBER:
-      temp = cpp_classify_number (pfile, token);
+      temp = cpp_classify_number (pfile, token, NULL);
+      if (temp & CPP_N_USERDEF)
+	cpp_error (pfile, CPP_DL_ERROR,
+		   "user-defined literal in preprocessor expression");
       switch (temp & CPP_N_CATEGORY)
 	{
 	case CPP_N_FLOATING:
Index: libcpp/lex.c
===================================================================
--- libcpp/lex.c	(revision 180284)
+++ libcpp/lex.c	(working copy)
@@ -1478,6 +1478,18 @@
     }
  break_outer_loop:
 
+  if (CPP_OPTION (pfile, user_literals))
+    {
+      /* Grab user defined literal suffix.  */
+      if (ISIDST (*cur))
+	{
+	  type = cpp_userdef_string_add_type (type);
+	  ++cur;
+	}
+      while (ISIDNUM (*cur))
+	++cur;
+    }
+
   pfile->buffer->cur = cur;
   if (first_buff == NULL)
     create_literal (pfile, token, base, cur - base, type);
@@ -1581,6 +1593,19 @@
     cpp_error (pfile, CPP_DL_PEDWARN, "missing terminating %c character",
 	       (int) terminator);
 
+  if (CPP_OPTION (pfile, user_literals))
+    {
+      /* Grab user defined literal suffix.  */
+      if (ISIDST (*cur))
+	{
+	  type = cpp_userdef_char_add_type (type);
+	  type = cpp_userdef_string_add_type (type);
+          ++cur;
+	}
+      while (ISIDNUM (*cur))
+	++cur;
+    }
+
   pfile->buffer->cur = cur;
   create_literal (pfile, token, base, cur - base, type);
 }

[-- Attachment #3: CL_udlit_gcc_c-family --]
[-- Type: text/plain, Size: 346 bytes --]

2011-10-25  Ed Smith-Rowland  <3dw4rd@verizon.net>

	Implement C++11 user-defined literals.
	* c-common.c (build_userdef_literal): New.
	* c-common.def: New tree code.
	* c-common.h (tree_userdef_literal): New tree struct and accessors.
	* c-lex.c (interpret_integer, interpret_float): Return suffixes.
	(c_lex_with_flags): Build literal tokens.

[-- Attachment #4: CL_udlit_gcc_cp --]
[-- Type: text/plain, Size: 1321 bytes --]

2011-10-25  Ed Smith-Rowland  <3dw4rd@verizon.net>

	Implement C++11 user-defined literals.
	* cp-objcp-common.c: (cp_tree_size) Return size of USERDEF_LITERAL tree.
	* cp-tree.h: (UDLIT_OP_*, UDLIT_OPER_P): Literal operator
	name tools. New tree code for user-defined literals.
	* gcc/cp/cxx-pretty-print.h: (pp_cxx_userdef_literal) New.
	* gcc/cp/cxx-pretty-print.c: (pp_cxx_userdef_literal) New.
	(pp_cxx_primary_expression, pp_cxx_expression): Use it.
	* gcc/cp/decl.c: (cp_tree_node_structure): Return new tree code.
	(duplicate_decls): Check for raw vs. template operator conflicts.
	(grokfndecl, grokdeclarator): New checks for literal operators.
	* gcc/cp/error.c: (dump_expr): Warn about user-defined literals
	in C++98 mode. (dump_function_name): Pretty printing.
	* gcc/cp/mangle.c: (write_literal_operator_name): New.
	(write_unqualified_id, write_unqualified_name): Use it.
	* gcc/cp/parser.c: (cp_parser_operator): Handle operator"".
	(cp_parser_userdef_char_literal, cp_parser_userdef_numeric_literal,
	cp_parser_userdef_string_literal): New.
	(cp_parser_primary_expression): Handle new user-defined literal tokens
	with new functions.
	* gcc/cp/semantics.c: (potential_constant_expression_1): Add
	user-defined literals.
	* gcc/cp/typeck.c (check_raw_literal_operator,
	check_literal_operator_args): New.

[-- Attachment #5: CL_udlit_gcc_testsuite --]
[-- Type: text/plain, Size: 1346 bytes --]

2011-10-25  Ed Smith-Rowland  <3dw4rd@verizon.net>

	Implement C++11 user-defined literals.
	* g++.dg/cpp0x/udlit-addr.C: New.
	* g++.dg/cpp0x/udlit-args.C: New.
	* g++.dg/cpp0x/udlit-args-neg.C: New.
	* g++.dg/cpp0x/udlit-clink-neg.C: New.
	* g++.dg/cpp0x/udlit-concat.C: New.
	* g++.dg/cpp0x/udlit-concat-neg.C: New.
	* g++.dg/cpp0x/udlit-constexpr.C: New.
	* g++.dg/cpp0x/udlit-cpp98-neg.C: New.
	* g++.dg/cpp0x/udlit-declare-neg.C: New.
	* g++.dg/cpp0x/udlit-friend.C: New.
	* g++.dg/cpp0x/udlit-general.C: New.
	* g++.dg/cpp0x/udlit-inline.C: New.
	* g++.dg/cpp0x/udlit-linkage-neg.C: New.
	* g++.dg/cpp0x/udlit-member-neg.C: New.
	* g++.dg/cpp0x/udlit-namespace.C: New.
	* g++.dg/cpp0x/udlit-nofunc-neg.C: New.
	* g++.dg/cpp0x/udlit-nonempty-str-neg.C: New.
	* g++.dg/cpp0x/udlit-nospace-neg.C: New.
	* g++.dg/cpp0x/udlit-nosuffix-neg.C: New.
	* g++.dg/cpp0x/udlit-nounder-neg.C: New.
	* g++.dg/cpp0x/udlit-operator-neg.C: New.
	* g++.dg/cpp0x/udlit-raw-str.C: New.
	* g++.dg/cpp0x/udlit-shadow-neg.C: New.
	* g++.dg/cpp0x/udlit-suffix-neg.C: New.
	* g++.dg/cpp0x/udlit-systemheader.C: New.
	* g++.dg/cpp0x/udlit-template.C: New.
	* g++.dg/cpp0x/udlit-tmpl-arg.C: New.
	* g++.dg/cpp0x/udlit-tmpl-arg-neg.C: New.
	* g++.dg/cpp0x/udlit-tmpl-parms.C: New.
	* g++.dg/cpp0x/udlit-tmpl-parms-neg.C: New.
	* g++.dg/cpp0x/udlit_system_header: New.

[-- Attachment #6: CL_udlit_libcpp --]
[-- Type: text/plain, Size: 662 bytes --]

2011-10-25  Ed Smith-Rowland  <3dw4rd@verizon.net>

	Implement C++11 user-defined literals.
	* expr.c: (cpp_interpret_float_suffix, cpp_interpret_int_suffix,
	cpp_userdef_string_remove_type, cpp_userdef_string_add_type,
	cpp_userdef_char_remove_type, cpp_userdef_char_add_type,
	cpp_userdef_string_p, cpp_userdef_char_p, cpp_get_userdef_suffix): New.
	(cpp_classify_number): Classify unrecognized tokens as user-defined literals.
	* include/cpplib.h: Add new tokens for user-defined literals.
	* init.c: Add new preprocessor flag (cxx11).
	* lex.c: (lex_string, lex_raw_string): Handle user-defined literals
	including concatenation and promotion with suffixes.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-24 15:41         ` Ed Smith-Rowland
@ 2011-10-25 23:38           ` Jason Merrill
  2011-10-26  9:16             ` Ed Smith-Rowland
  0 siblings, 1 reply; 36+ messages in thread
From: Jason Merrill @ 2011-10-25 23:38 UTC (permalink / raw)
  To: Ed Smith-Rowland; +Cc: Tom Tromey, gcc-patches

On 10/24/2011 10:53 AM, Ed Smith-Rowland wrote:
>> Concerning this error, the only way to get here is to mis-use a raw
>> literal operator by giving it a quoted string. The prefix must be
>> interpretable as a number of some kind. I think I'll tell the user to
>> drop the quotes.

It seems more likely to me that the user intends to make a string 
literal, and just doesn't understand that an operator with a single 
const char * parameter is a raw literal operator which is unsuitable for 
a string literal.

Incidentally, in a string literal, the prefix is an initial u8R or 
whatever; the "Boo!" is not a prefix, though there doesn't seem to be a 
good term to use for it.

> For both the raw literal and the literal template I use num_string which
> ultimately comes from build_string in tree.c line 1531.
> It looks like this function null terminates the buffer - i.e. the length
> is len + 1. Yet when I have two user-defined literals in sequence the
> first sees both strings concatenated.

Did you figure out what was causing this?  It looks like your latest 
patch tries to avoid this by modifying the string in the token, which I 
don't think we want to do.

It certainly seems to me that as you said, build_string should 
null-terminate the string itself.

Jason

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-25 23:38           ` Jason Merrill
@ 2011-10-26  9:16             ` Ed Smith-Rowland
  2011-10-26 20:13               ` Jason Merrill
  0 siblings, 1 reply; 36+ messages in thread
From: Ed Smith-Rowland @ 2011-10-26  9:16 UTC (permalink / raw)
  To: Jason Merrill; +Cc: Tom Tromey, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 2235 bytes --]

On 10/25/2011 06:06 PM, Jason Merrill wrote:
> On 10/24/2011 10:53 AM, Ed Smith-Rowland wrote:
>>> Concerning this error, the only way to get here is to mis-use a raw
>>> literal operator by giving it a quoted string. The prefix must be
>>> interpretable as a number of some kind. I think I'll tell the user to
>>> drop the quotes.
>
> It seems more likely to me that the user intends to make a string 
> literal, and just doesn't understand that an operator with a single 
> const char * parameter is a raw literal operator which is unsuitable 
> for a string literal.
I was drifting to this conclusion too.  It's difficult to predict what 
mistakes people will make though.
>
> Incidentally, in a string literal, the prefix is an initial u8R or 
> whatever; the "Boo!" is not a prefix, though there doesn't seem to be 
> a good term to use for it.
>
>> For both the raw literal and the literal template I use num_string which
>> ultimately comes from build_string in tree.c line 1531.
>> It looks like this function null terminates the buffer - i.e. the length
>> is len + 1. Yet when I have two user-defined literals in sequence the
>> first sees both strings concatenated.
>
> Did you figure out what was causing this?  It looks like your latest 
> patch tries to avoid this by modifying the string in the token, which 
> I don't think we want to do.
>
> It certainly seems to me that as you said, build_string should 
> null-terminate the string itself.
This took a bit of research.  :-)  build_string does terminate with a 
null.  This is done so that even (char[4])"abcd" doesn't overrun.  
However there are several cases where build_string is called with 
(len=strlen(something) + 1, something).  So I guess there are two nulls 
in that case.  The string of numeric digits does not have a null 
terminator.  So to use this function to create a const string literal 
you should add a null.  I'm looking at ways to do this without 
clobbering the token which I agree is potentially dangerous.

Anyway, I now create the numeric string (with an extra character for the 
null) and edit *that* instead of the token.

I also changed that error message.
>
> Jason
>
The patch was bootstrapped and regtested on x86_64-linux-gnu.

Ed



[-- Attachment #2: patch33 --]
[-- Type: text/plain, Size: 77235 bytes --]

Index: gcc/c-family/c-common.c
===================================================================
--- gcc/c-family/c-common.c	(revision 180284)
+++ gcc/c-family/c-common.c	(working copy)
@@ -9923,4 +9923,17 @@
   MARK_TS_TYPED (EXCESS_PRECISION_EXPR);
 }
 
+/* Build a user-defined numeric literal out of an integer constant type VALUE
+   with identifier SUFFIX.  */
+
+tree
+build_userdef_literal (tree suffix_id, tree value, tree num_string)
+{
+  tree literal = make_node (USERDEF_LITERAL);
+  USERDEF_LITERAL_SUFFIX_ID (literal) = suffix_id;
+  USERDEF_LITERAL_VALUE (literal) = value;
+  USERDEF_LITERAL_NUM_STRING (literal) = num_string;
+  return literal;
+}
+
 #include "gt-c-family-c-common.h"
Index: gcc/c-family/c-lex.c
===================================================================
--- gcc/c-family/c-lex.c	(revision 180284)
+++ gcc/c-family/c-lex.c	(working copy)
@@ -44,8 +44,8 @@
 int pending_lang_change; /* If we need to switch languages - C++ only */
 int c_header_level;	 /* depth in C headers - C++ only */
 
-static tree interpret_integer (const cpp_token *, unsigned int);
-static tree interpret_float (const cpp_token *, unsigned int);
+static tree interpret_integer (const cpp_token *, unsigned int, const char *);
+static tree interpret_float (const cpp_token *, unsigned int, const char *);
 static tree interpret_fixed (const cpp_token *, unsigned int);
 static enum integer_type_kind narrowest_unsigned_type
 	(unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned int);
@@ -314,7 +314,8 @@
 
     case CPP_NUMBER:
       {
-	unsigned int flags = cpp_classify_number (parse_in, tok);
+	const char *suffix = NULL;
+	unsigned int flags = cpp_classify_number (parse_in, tok, &suffix);
 
 	switch (flags & CPP_N_CATEGORY)
 	  {
@@ -328,16 +329,31 @@
 	       Set PURE_ZERO to pass this information to the C++ parser.  */
 	    if (tok->val.str.len == 1 && *tok->val.str.text == '0')
 	      add_flags = PURE_ZERO;
-	    *value = interpret_integer (tok, flags);
+	    *value = interpret_integer (tok, flags, suffix);
 	    break;
 
 	  case CPP_N_FLOATING:
-	    *value = interpret_float (tok, flags);
+	    *value = interpret_float (tok, flags, suffix);
 	    break;
 
 	  default:
 	    gcc_unreachable ();
 	  }
+
+	if (flags & CPP_N_USERDEF)
+	  {
+	    tree suffix_id = get_identifier (suffix);
+	    int len = tok->val.str.len - strlen (suffix);
+	    tree num_string = build_string (len + 1,
+					    (const char *) tok->val.str.text);
+	    TREE_TYPE (num_string) = char_array_type_node;
+	    num_string = fix_string_type (num_string);
+	    char *str = CONST_CAST (char *, TREE_STRING_POINTER (num_string));
+	    str[len] = '\0';
+	    tree literal = build_userdef_literal (suffix_id, *value,
+						  num_string);
+	    *value = literal;
+	  }
       }
       break;
 
@@ -415,6 +431,22 @@
       }
       goto retry;
 
+    case CPP_CHAR_USERDEF:
+    case CPP_WCHAR_USERDEF:
+    case CPP_CHAR16_USERDEF:
+    case CPP_CHAR32_USERDEF:
+      {
+	tree literal;
+	cpp_token temp_tok = *tok;
+	const char *suffix = cpp_get_userdef_suffix (tok);
+	temp_tok.val.str.len -= strlen (suffix);
+	temp_tok.type = cpp_userdef_char_remove_type (type);
+	literal = build_userdef_literal (get_identifier (suffix),
+					 lex_charconst (&temp_tok), NULL_TREE);
+	*value = literal;
+      }
+      break;
+
     case CPP_CHAR:
     case CPP_WCHAR:
     case CPP_CHAR16:
@@ -422,6 +454,22 @@
       *value = lex_charconst (tok);
       break;
 
+    case CPP_STRING_USERDEF:
+    case CPP_WSTRING_USERDEF:
+    case CPP_STRING16_USERDEF:
+    case CPP_STRING32_USERDEF:
+    case CPP_UTF8STRING_USERDEF:
+      {
+	tree literal, string;
+	const char *suffix = cpp_get_userdef_suffix (tok);
+	string = build_string (tok->val.str.len - strlen (suffix),
+			       (const char *) tok->val.str.text);
+	literal = build_userdef_literal (get_identifier (suffix),
+					 string, NULL_TREE);
+	*value = literal;
+      }
+      break;
+
     case CPP_STRING:
     case CPP_WSTRING:
     case CPP_STRING16:
@@ -536,9 +584,11 @@
   return itk_none;
 }
 
-/* Interpret TOKEN, an integer with FLAGS as classified by cpplib.  */
+/* Interpret TOKEN, an integer with FLAGS as classified by cpplib.
+   For C++0X SUFFIX may contain a user-defined literal suffix.  */
 static tree
-interpret_integer (const cpp_token *token, unsigned int flags)
+interpret_integer (const cpp_token *token, unsigned int flags,
+		   const char *suffix)
 {
   tree value, type;
   enum integer_type_kind itk;
@@ -621,9 +671,10 @@
 }
 
 /* Interpret TOKEN, a floating point number with FLAGS as classified
-   by cpplib.  */
+   by cpplib.  For C++0X SUFFIX may contain a user-defined literal suffix.  */
 static tree
-interpret_float (const cpp_token *token, unsigned int flags)
+interpret_float (const cpp_token *token, unsigned int flags,
+		 const char *suffix)
 {
   tree type;
   tree const_type;
@@ -702,7 +753,9 @@
      has any suffixes, cut them off; REAL_VALUE_ATOF/ REAL_VALUE_HTOF
      can't handle them.  */
   copylen = token->val.str.len;
-  if (flags & CPP_N_DFLOAT)
+  if (flags & CPP_N_USERDEF)
+    copylen -= strlen (suffix);
+  else if (flags & CPP_N_DFLOAT)
     copylen -= 2;
   else
     {
Index: gcc/c-family/c-common.h
===================================================================
--- gcc/c-family/c-common.h	(revision 180284)
+++ gcc/c-family/c-common.h	(working copy)
@@ -1067,4 +1067,27 @@
   return NULL;
 }
 
+/* A suffix-identifier value doublet that represents user-defined literals
+   for C++-0x.  */
+struct GTY(()) tree_userdef_literal {
+  struct tree_base base;
+  tree suffix_id;
+  tree value;
+  tree num_string;
+};
+
+#define USERDEF_LITERAL_SUFFIX_ID(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->suffix_id)
+
+#define USERDEF_LITERAL_VALUE(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->value)
+
+#define USERDEF_LITERAL_NUM_STRING(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->num_string)
+
+#define USERDEF_LITERAL_TYPE(NODE) \
+  (TREE_TYPE (USERDEF_LITERAL_VALUE (NODE)))
+
+extern tree build_userdef_literal (tree suffix_id, tree value, tree num_string);
+
 #endif /* ! GCC_C_COMMON_H */
Index: gcc/c-family/c-common.def
===================================================================
--- gcc/c-family/c-common.def	(revision 180284)
+++ gcc/c-family/c-common.def	(working copy)
@@ -47,6 +47,12 @@
    evaluated.  */
 DEFTREECODE (EXCESS_PRECISION_EXPR, "excess_precision_expr", tcc_expression, 1)
 
+/* Used to represent a user-defined literal.
+   The operands are an IDENTIFIER for the suffix, the VALUE of the literal,
+   and for numeric literals the original string representation of the
+   number.  */
+DEFTREECODE (USERDEF_LITERAL, "userdef_literal", tcc_exceptional, 3)
+
 /*
 Local variables:
 mode:c
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C	(revision 0)
@@ -0,0 +1,4 @@
+// { dg-options -std=c++0x }
+
+template<char...>
+  int operator"" _xyz(unsigned long long);	// { dg-error "has invalid argument list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit_system_header
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit_system_header	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit_system_header	(revision 0)
@@ -0,0 +1,6 @@
+
+#pragma GCC system_header
+
+char
+operator"" stdsuffix(char __c)
+{ return __c/2; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C	(revision 0)
@@ -0,0 +1,42 @@
+// { dg-options "-std=c++0x" }
+
+//  Can't have *both* literal operator template and raw literal operator.
+
+int
+operator"" _abc(const char*)
+  {
+    return 42;
+  }
+
+template<char...>
+  int
+  operator"" _abc() // { dg-error "literal operator template|conflicts with raw literal operator" }
+  {
+    return 13;
+  }
+
+template<char...>
+  int
+  operator"" _def()
+  {
+    return 12;
+  }
+
+int
+operator"" _def(const char*) // { dg-error "raw literal operator|conflicts with literal operator template" }
+  {
+    return 43;
+  }
+
+int
+operator"" _ghi(long double)
+  {
+    return 42;
+  }
+
+template<char...>
+  int
+  operator"" _ghi() // OK
+  {
+    return 13;
+  }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C	(revision 0)
@@ -0,0 +1,43 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test simple operator declaration and definition in namespaces.
+
+#include <cmath>
+#include <limits>
+
+namespace Long
+{
+  long double operator"" _LL(long double);
+}
+
+namespace Short
+{
+  short
+  operator"" _SS(long double x)
+  { return std::fmod(x, static_cast<long double>(std::numeric_limits<short>::max())); }
+}
+
+void
+test1()
+{
+  long double x = Long::operator "" _LL(1.2L);
+
+  using namespace Short;
+  short s = operator"" _SS(1.2L);
+  short s2 = 1.2_SS;
+}
+
+int
+main()
+{
+  test1();
+}
+
+namespace Long
+{
+  long double
+  operator"" _LL(long double x)
+  { return x + 2.0L; }
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-raw-op-string-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-raw-op-string-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-raw-op-string-neg.C	(revision 0)
@@ -0,0 +1,8 @@
+// { dg-options "-std=c++0x" }
+
+//  Make sure handing a string to a raw literal generates a sensible error message.
+
+int operator"" _embedraw(const char*)
+{ return 41; };
+
+int k = "Boo!"_embedraw;  //  { dg-error "unable to find valid user-defined string literal operator" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-embed-quote.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-embed-quote.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-embed-quote.C	(revision 0)
@@ -0,0 +1,34 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+//  Make sure embedded quotes are not a problem for string and char literals.
+
+#include <cstdint>
+#include <cassert>
+
+int operator"" _embedchar(char)
+{ return 41; };
+
+int operator"" _embedstr(const char*, std::size_t len)
+{ return 42 + len; };
+
+void
+test()
+{
+  int i = '\''_embedchar;
+
+  int j = "\""_embedstr;
+  assert(j == 43);
+
+  int k = "foo\""_embedstr;
+  assert(k == 46);
+
+  int l = "\"bar"_embedstr;
+  assert(l == 46);
+}
+
+int
+main()
+{
+  test();
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C	(revision 0)
@@ -0,0 +1,15 @@
+// { dg-options -std=c++0x }
+
+class Foo
+{
+public:
+  Foo() { }
+  int operator"" _Bar(char32_t);  // { dg-error "must be a non-member function" }
+};
+
+int i = operator"" _Bar(U'x');  // { dg-error "was not declared in this scope" }
+int j = U'x'_Bar;  // { dg-error "unable to find user-defined character literal operator" }
+
+int
+Foo::operator"" _Bar(char32_t)  // { dg-error "must be a non-member function" }
+{ return 42; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C	(revision 0)
@@ -0,0 +1,38 @@
+// { dg-options -std=c++0x }
+
+#include <cstddef>
+
+class Foo { };
+
+Foo
+operator"" _Foo(int *);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(unsigned long int);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(double);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const float *, std::size_t);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const wchar_t *, int);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const char16_t *);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(char...);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(unsigned long long int, char);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const char *, std::size_t, int);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(long double &);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(std::size_t, const char16_t *);	// { dg-error "has invalid argument list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C	(revision 0)
@@ -0,0 +1,17 @@
+// { dg-options "-std=c++98" }
+
+#include <cstddef>
+
+int
+operator"" _mm(long double m)	// { dg-warning "user-defined literals only available with" }
+{ return int(1000.0L * m); }
+
+int in = 0.0254_mm;	// { dg-error "invalid suffix" }
+
+int
+operator"" _Q(const char *, std::size_t)	// { dg-warning "user-defined literals only available with" }
+{ return 42; }
+
+int x = "Hello"_Q;	// { dg-error "invalid conversion from" }
+
+// { dg-error "expected" "" { target *-*-* } 15 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C	(revision 0)
@@ -0,0 +1,5 @@
+// { dg-options -std=c++0x }
+
+#include <string>
+
+std::string operator"" 5X(const char*, std::size_t);	// { dg-error "expected suffix identifier" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-raw-op.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-raw-op.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-raw-op.C	(revision 0)
@@ -0,0 +1,21 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+#include <cassert>
+#include <cstring>
+
+int
+operator"" _raw_umber(const char * str)
+{
+  return strlen(str);
+}
+
+int
+main()
+{
+  int i = 0123012301230123012301230123012301230123012301230123012301230123_raw_umber;
+  assert( i == 64 );
+
+  int j = 90123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789_raw_umber;
+  assert( j == 101 );
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+constexpr unsigned long long
+operator"" _grow(unsigned long long n)
+{ return 2 * n; }
+
+double buffer[25_grow];
Index: gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C	(revision 0)
@@ -0,0 +1,49 @@
+// { dg-options -std=c++0x }
+
+//  Test that the standard suffixes shadow any user-defined suffixes of the same name.
+long double
+operator"" L(long double x)  // { dg-warning "floating point suffix|shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ULL(unsigned long long int k)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return k; }
+
+long double
+operator"" l(long double x)  // { dg-warning "floating point suffix|shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ull(unsigned long long int k)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return k; }
+
+//  Namespaces are no hiding place.
+namespace Long
+{
+
+long double
+operator"" L(long double x)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ULL(unsigned long long int k)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return k; }
+
+long double
+operator"" l(long double x)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ull(unsigned long long int k)  // { dg-warning "integer suffix|shadowed by implementation" }
+{ return k; }
+
+}
+
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 5 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 9 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 13 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 17 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 25 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 29 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 33 }
+// { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 37 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test warning on declaration without leading underscore.
+
+long double operator"" nounder(long double); // { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" }
+
+template<char...>
+  int operator"" nounder(); // { dg-warning "literal operator suffixes not preceded by|are reserved for future standardization" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C	(revision 0)
@@ -0,0 +1,12 @@
+// { dg-options -std=c++0x }
+
+class Foo { };
+
+template<wchar_t...>
+  Foo operator"" _Foo(); // { dg-error "literal operator template|has invalid parameter list" }
+
+template<char>
+  Foo operator"" _Bar(); // { dg-error "literal operator template|has invalid parameter list" }
+
+template<typename... Type>
+  Foo operator"" _Bar(); // { dg-error "literal operator template|has invalid parameter list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-general.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-general.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-general.C	(revision 0)
@@ -0,0 +1,52 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test simple operator declaration and definition.
+
+#include <cstring>
+#include <string>
+#include <complex>
+#include <cassert>
+
+long double operator"" _v(long double);
+std::string operator"" _w(const char16_t*, size_t);
+unsigned operator"" _w(const char*);
+
+std::complex<double>
+operator"" _i(long double y)
+{ return std::complex<double>(0.0L, y); }
+
+void
+test1()
+{
+  long double x = operator"" _v(1.2L);
+  assert(x == 2.2L);
+
+  std::string s = operator"" _w(u"one", 3);
+  assert(s == "boo");
+
+  unsigned u = operator"" _w("Hello, World!");
+  assert(u == 13U);
+
+  std::complex<double> i = operator"" _i(2.0);
+  assert(i == std::complex<double>(0.0, 2.0));
+}
+
+int
+main()
+{
+  test1();
+}
+
+long double
+operator"" _v(long double x)
+{ return x + 1.0L; }
+
+std::string
+operator"" _w(const char16_t*, size_t)
+{ return std::string("boo"); }
+
+unsigned
+operator"" _w(const char* str)
+{ return strlen(str); }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C	(revision 0)
@@ -0,0 +1,3 @@
+// { dg-options -std=c++0x }
+
+#include "udlit_system_header"
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test error on non-function declaration.
+
+double operator"" _baddecl; // { dg-error "as non-function" }
+
+template<char...>
+  int operator"" _badtmpldecl; // { dg-error "as non-function" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C	(revision 0)
@@ -0,0 +1,15 @@
+// { dg-options -std=c++0x }
+
+#include <string>
+
+std::string operator"" _i18n(const char*, std::size_t);
+
+std::string vogon_poem = R"V0G0N(
+                O freddled gruntbuggly thy micturations are to me
+                    As plured gabbleblochits on a lurgid bee.
+                 Groop, I implore thee my foonting turlingdromes.   
+              And hooptiously drangle me with crinkly bindlewurdles,
+  Or I will rend thee in the gobberwarts with my blurlecruncheon, see if I don't.
+
+                    (by Prostetnic Vogon Jeltz; see p. 56/57)
+)V0G0N"_i18n;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-addr.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-addr.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-addr.C	(revision 0)
@@ -0,0 +1,10 @@
+// { dg-options "-std=c++0x" }
+
+#include <cstddef>
+
+bool operator"" _yn(const char*, size_t);
+
+typedef bool (*pfunk)(const char*, size_t);
+pfunk p = &operator"" _yn;
+
+bool tf = p("Hello,\0 World!", 14);
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C	(revision 0)
@@ -0,0 +1,4 @@
+// { dg-options -std=c++0x }
+
+template<char...>
+  int operator"" _abc();
Index: gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C	(revision 0)
@@ -0,0 +1,8 @@
+// { dg-options -std=c++0x }
+
+extern "C" {
+
+int
+operator"" _badclinkage(unsigned long long);	// { dg-error "operator with C linkage" }
+
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-template.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-template.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-template.C	(revision 0)
@@ -0,0 +1,51 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test template operator declaration and definition.
+
+#include <cassert>
+
+template<char...>
+  int operator"" _abc();
+
+template<>
+  int
+  operator"" _abc<>()
+  { return -1; }
+
+template<>
+  int
+  operator"" _abc<'L','U','E'>()
+  { return 42; }
+
+template<>
+  int
+  operator"" _abc<'6','6','6'>()
+  { return 21; }
+
+int
+test1()
+{
+  int i = operator"" _abc<'1','2','3'>();
+  assert(i == 45);
+  int universal_meaning = operator"" _abc<'L','U','E'>();
+  assert(universal_meaning == 42);
+  int b = operator"" _abc<'6','6','6'>();
+  int z = operator"" _abc<>();
+  assert(z == -1);
+  int j = 123_abc;
+  assert(j == i);
+  int jb = 666_abc;
+  assert(jb == b);
+}
+
+int
+main()
+{
+  test1();
+}
+
+template<char... Chars>
+  int operator"" _abc()
+  { return 42 + sizeof...(Chars); }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-preproc-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-preproc-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-preproc-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+int
+operator"" _badpreproc(const char *str)
+{ return 0; }
+
+#if 123_badpreproc  //  { dg-error "user-defined literal in preprocessor expression" }
+#  error ("user-defined literal in preprocessor expression")  //  { dg-error "user-defined literal in preprocessor expression" }
+#endif
Index: gcc/testsuite/g++.dg/cpp0x/udlit-args.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-args.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-args.C	(revision 0)
@@ -0,0 +1,38 @@
+// { dg-options -std=c++0x }
+
+#include <cstddef>
+
+class Foo { };
+
+Foo
+operator"" _Foo(const char *);
+
+Foo
+operator"" _Foo(unsigned long long int);
+
+Foo
+operator"" _Foo(long double);
+
+Foo
+operator"" _Foo(char);
+
+Foo
+operator"" _Foo(wchar_t);
+
+Foo
+operator"" _Foo(char16_t);
+
+Foo
+operator"" _Foo(char32_t);
+
+Foo
+operator"" _Foo(const char *, std::size_t);
+
+Foo
+operator"" _Foo(const wchar_t *, std::size_t);
+
+Foo
+operator"" _Foo(const char16_t *, std::size_t);
+
+Foo
+operator"" _Foo(const char32_t *, std::size_t);
Index: gcc/testsuite/g++.dg/cpp0x/udlit-declare-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-declare-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-declare-neg.C	(revision 0)
@@ -0,0 +1,15 @@
+// { dg-options "-std=c++0x" }
+
+//  Check that undeclared literal operator calls and literals give appropriate errors.
+
+int i = operator"" _Bar('x');  // { dg-error "was not declared in this scope" }
+int j = 'x'_Bar;  // { dg-error "unable to find user-defined character literal operator" }
+
+int ii = operator"" _BarCharStr("Howdy, Pardner!");  // { dg-error "was not declared in this scope" }
+int jj = "Howdy, Pardner!"_BarCharStr;  // { dg-error "unable to find user-defined string literal operator" }
+
+unsigned long long iULL = operator"" _BarULL(666ULL);  // { dg-error "was not declared in this scope" }
+unsigned long long jULL = 666_BarULL;  // { dg-error "unable to find user-defined numeric literal operator" }
+
+long double iLD = operator"" _BarLD(666.0L);  // { dg-error "was not declared in this scope" }
+long double jLD = 666.0_BarLD;  // { dg-error "unable to find user-defined numeric literal operator" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C	(revision 0)
@@ -0,0 +1,5 @@
+// { dg-options -std=c++0x }
+
+char32_t
+operator"" (char32_t C)	// { dg-error "expected suffix identifier" }
+{ return C; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test error on non-empty string after 'operator' keyword.
+
+double operator"hi" _badword(long double); // { dg-error "expected empty string after" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nospace-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nospace-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nospace-neg.C	(revision 0)
@@ -0,0 +1,3 @@
+// { dg-options "-std=c++0x" }
+
+float operator ""_abc(const char*); // { dg-error "missing space between|and suffix identifier" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-inline.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-inline.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-inline.C	(revision 0)
@@ -0,0 +1,22 @@
+// { dg-options "-std=c++0x" }
+
+//  Literal operators can be inline.
+
+inline int
+operator"" _thing1(char cc)
+{ return 42 * cc; }
+
+int operator"" _thing2(char cc);
+
+class Foo
+{
+  int
+  friend operator"" _thing2(char cc)
+  { return 42 * cc; }
+};
+
+int i = operator"" _thing1('x');
+int j = 'x'_thing1;
+
+int iF = operator"" _thing2('x');
+int jF = 'x'_thing2;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+extern "C"_badlinkage {	// { dg-error "expected unqualified-id before" }
+
+int foo();
+
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-friend.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-friend.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-friend.C	(revision 0)
@@ -0,0 +1,28 @@
+// { dg-options -std=c++0x }
+
+long double
+operator"" _Hertz(long double);
+
+class Foo
+{
+public:
+  Foo() { }
+
+  friend Foo operator"" _Bar(char);
+
+  friend long double
+  operator"" _Hertz(long double omega)
+  { return omega / 6.28318530717958648; }
+};
+
+Foo
+operator"" _Bar(char)
+{ return Foo(); }
+
+Foo f1 = operator"" _Bar('x');
+
+Foo f2 = 'x'_Bar;
+
+long double fm1 = operator"" _Hertz(552.92L);
+
+long double fm2 = 552.92_Hertz;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+#include <string>
+
+std::string operator"" _xxx(const char*, size_t);
+
+std::string operator"" _yyy(const char*, size_t);
+
+std::string concat = "Hello, "_xxx "World!"_yyy;	// { dg-error "inconsistent user-defined literal suffixes" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options -std=c++0x }
+
+class Foo { };
+
+template<char...>
+  Foo operator"" _Foo();
Index: gcc/testsuite/g++.dg/cpp0x/udlit-concat.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-concat.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-concat.C	(revision 0)
@@ -0,0 +1,24 @@
+// { dg-options "-std=c++0x" }
+
+#include <string>
+
+std::string operator"" _www(const char*, size_t);
+
+std::string concat01 = "Hello, " "World!"_www;
+
+std::string concat10 = "Hello, "_www "World!";
+
+std::string concat11 = "Hello, "_www "World!"_www;
+
+
+class Tachyon { };
+
+Tachyon operator"" _fast(const char*, size_t);
+
+int operator"" _fast(const char32_t*, size_t);
+
+int speedy01 = "Hello, " U"World!"_fast;
+
+int speedy10 = "Hello, "_fast U"World!";
+
+int speedy11 = "Hello, "_fast U"World!"_fast;
Index: gcc/cp/typeck.c
===================================================================
--- gcc/cp/typeck.c	(revision 180284)
+++ gcc/cp/typeck.c	(working copy)
@@ -8352,3 +8352,121 @@
   return 1;
 }
 
+/* Return true if a user-defined literal operator is a raw operator.  */
+
+bool
+check_raw_literal_operator (const_tree decl)
+{
+  tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
+  tree argtype;
+  int arity;
+  bool maybe_raw_p = false;
+
+  /* Count the number and type of arguments and check for ellipsis.  */
+  for (argtype = argtypes, arity = 0;
+       argtype && argtype != void_list_node;
+       ++arity, argtype = TREE_CHAIN (argtype))
+    {
+      tree t = TREE_VALUE (argtype);
+
+      if (same_type_p (t, const_string_type_node))
+	maybe_raw_p = true;
+    }
+  if (!argtype)
+    return false; /* Found ellipsis.  */
+
+  if (!maybe_raw_p || arity != 1)
+    return false;
+
+  return true;
+}
+
+
+/* Return true if a user-defined literal operator has one of the allowed
+   argument types.  */
+
+bool
+check_literal_operator_args (const_tree decl,
+			     bool *long_long_unsigned_p, bool *long_double_p)
+{
+  tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
+  if (processing_template_decl)
+    return (argtypes == NULL_TREE
+	    || same_type_p (TREE_VALUE (argtypes), void_type_node));
+  else
+    {
+      tree argtype;
+      int arity;
+      int max_arity = 2;
+      bool found_string_p = false;
+      bool maybe_raw_p = false;
+      bool found_size_p = false;
+      tree const_wchar_ptr_type_node
+	   = build_pointer_type (build_type_variant (wchar_type_node, 1, 0));
+      tree const_char16_ptr_type_node
+	   = build_pointer_type (build_type_variant (char16_type_node, 1, 0));
+      tree const_char32_ptr_type_node
+	   = build_pointer_type (build_type_variant (char32_type_node, 1, 0));
+
+      *long_long_unsigned_p = false;
+      *long_double_p = false;
+
+      /* Count the number and type of arguments and check for ellipsis.  */
+      for (argtype = argtypes, arity = 0;
+	   argtype && argtype != void_list_node;
+	   argtype = TREE_CHAIN (argtype))
+	{
+	  tree t = TREE_VALUE (argtype);
+	  ++arity;
+
+	  if (same_type_p (t, const_string_type_node))
+	    {
+	      found_string_p = true;
+	      maybe_raw_p = true;
+	    }
+	  else if (same_type_p (t, const_wchar_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, const_char16_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, const_char32_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, size_type_node))
+	    {
+	      if (!found_string_p)
+		return false;
+	      found_size_p = true;
+	    }
+	  else if (same_type_p (t, long_long_unsigned_type_node))
+	    {
+	      max_arity = 1;
+	      *long_long_unsigned_p = true;
+	    }
+	  else if (same_type_p (t, long_double_type_node))
+	    {
+	      max_arity = 1;
+	      *long_double_p = true;
+	    }
+	  else if (same_type_p (t, char_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, wchar_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, char16_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, char32_type_node))
+	    max_arity = 1;
+	  else
+	    return false;
+	}
+      if (!argtype)
+	return false; /* Found ellipsis.  */
+
+      if (arity > max_arity)
+	return false;
+
+      if (found_string_p && !maybe_raw_p && !found_size_p)
+	return false;
+
+      return true;
+    }
+}
+
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 180284)
+++ gcc/cp/decl.c	(working copy)
@@ -1203,6 +1203,21 @@
       || TREE_TYPE (olddecl) == error_mark_node)
     return error_mark_node;
 
+  if (UDLIT_OPER_P (DECL_NAME (newdecl))
+      && UDLIT_OPER_P (DECL_NAME (olddecl)))
+    {
+      if (TREE_CODE (newdecl) == TEMPLATE_DECL
+	  && TREE_CODE (olddecl) != TEMPLATE_DECL
+	  && check_raw_literal_operator (olddecl))
+	error ("literal operator template %q+D conflicts with"
+	       " raw literal operator %qD", newdecl, olddecl);
+      else if (TREE_CODE (newdecl) != TEMPLATE_DECL
+	       && TREE_CODE (olddecl) == TEMPLATE_DECL
+	       && check_raw_literal_operator (newdecl))
+	error ("raw literal operator %q+D conflicts with"
+	       " literal operator template %qD", newdecl, olddecl);
+    }
+
   if (DECL_P (olddecl)
       && TREE_CODE (newdecl) == FUNCTION_DECL
       && TREE_CODE (olddecl) == FUNCTION_DECL
@@ -7343,7 +7358,48 @@
   if (IDENTIFIER_OPNAME_P (DECL_NAME (decl))
       && !grok_op_properties (decl, /*complain=*/true))
     return NULL_TREE;
+  else if (UDLIT_OPER_P (DECL_NAME (decl)))
+    {
+      bool long_long_unsigned_p;
+      bool long_double_p;
+      const char *suffix = NULL;
+      /* [over.literal]/6: Literal operators shall not have C linkage. */
+      if (DECL_LANGUAGE (decl) == lang_c)
+	{
+	  error ("literal operator with C linkage");
+	  return NULL_TREE;
+	}
 
+      if (DECL_NAMESPACE_SCOPE_P (decl))
+	{
+	  if (!check_literal_operator_args (decl, &long_long_unsigned_p,
+					    &long_double_p))
+	    {
+	      error ("%qD has invalid argument list", decl);
+	      return NULL_TREE;
+	    }
+
+	  suffix = UDLIT_OP_SUFFIX (DECL_NAME (decl));
+	  if (long_long_unsigned_p)
+	    {
+	      if (cpp_interpret_int_suffix (suffix, strlen (suffix)))
+		warning (0, "integer suffix %<%s%>"
+			    " shadowed by implementation", suffix);
+	    }
+	  else if (long_double_p)
+	    {
+	      if (cpp_interpret_float_suffix (suffix, strlen (suffix)))
+		warning (0, "floating point suffix %<%s%>"
+			    " shadowed by implementation", suffix);
+	    }
+	}
+      else
+	{
+	  error ("%qD must be a non-member function", decl);
+	  return NULL_TREE;
+	}
+    }
+
   if (funcdef_flag)
     /* Make the init_value nonzero so pushdecl knows this is not
        tentative.  error_mark_node is replaced later with the BLOCK.  */
@@ -8534,6 +8590,15 @@
       error ("declaration of %qD as non-function", dname);
       return error_mark_node;
     }
+ 
+  if (dname
+      && TREE_CODE (dname) == IDENTIFIER_NODE
+      && UDLIT_OPER_P (dname)
+      && innermost_code != cdk_function)
+    {
+      error ("declaration of %qD as non-function", dname);
+      return error_mark_node;
+    }
 
   if (dname && IDENTIFIER_OPNAME_P (dname))
     {
@@ -13752,6 +13817,7 @@
     case TRAIT_EXPR:		return TS_CP_TRAIT_EXPR;
     case LAMBDA_EXPR:		return TS_CP_LAMBDA_EXPR;
     case TEMPLATE_INFO:		return TS_CP_TEMPLATE_INFO;
+    case USERDEF_LITERAL:	return TS_CP_USERDEF_LITERAL;
     default:			return TS_CP_GENERIC;
     }
 }
Index: gcc/cp/error.c
===================================================================
--- gcc/cp/error.c	(revision 180284)
+++ gcc/cp/error.c	(working copy)
@@ -1534,6 +1534,8 @@
     }
   else if (name && IDENTIFIER_OPNAME_P (name))
     pp_cxx_tree_identifier (cxx_pp, name);
+  else if (name && UDLIT_OPER_P (name))
+    pp_cxx_tree_identifier (cxx_pp, name);
   else
     dump_decl (name, flags);
 
@@ -1756,6 +1758,10 @@
       pp_constant (cxx_pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (cxx_pp, t);
+      break;
+
     case THROW_EXPR:
       /* While waiting for caret diagnostics, avoid printing
 	 __cxa_allocate_exception, __cxa_throw, and the like.  */
@@ -3233,7 +3239,7 @@
 	pedwarn (input_location, OPT_pedantic,
 		 "inline namespaces "
 		 "only available with -std=c++0x or -std=gnu++0x");
-	break;	
+	break;
       case CPP0X_OVERRIDE_CONTROLS:
 	pedwarn (input_location, 0,
 		 "override controls (override/final) "
@@ -3244,8 +3250,13 @@
 		 "non-static data member initializers "
 		 "only available with -std=c++0x or -std=gnu++0x");
         break;
+      case CPP0X_USER_DEFINED_LITERALS:
+	pedwarn (input_location, 0,
+		 "user-defined literals "
+		 "only available with -std=c++0x or -std=gnu++0x");
+	break;
       default:
-	gcc_unreachable();
+	gcc_unreachable ();
       }
 }
 
Index: gcc/cp/cxx-pretty-print.c
===================================================================
--- gcc/cp/cxx-pretty-print.c	(revision 180284)
+++ gcc/cp/cxx-pretty-print.c	(working copy)
@@ -367,6 +367,17 @@
     pp_cxx_unqualified_id (pp, t);
 }
 
+/* user-defined literal:
+      literal ud-suffix  */
+
+void
+pp_cxx_userdef_literal (cxx_pretty_printer *pp, tree t)
+{
+  pp_cxx_constant (pp, USERDEF_LITERAL_VALUE (t));
+  pp_cxx_id_expression (pp, USERDEF_LITERAL_SUFFIX_ID (t));
+}
+
+
 /* primary-expression:
      literal
      this
@@ -413,6 +424,10 @@
       pp_cxx_constant (pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (pp, t);
+      break;
+
     case BASELINK:
       t = BASELINK_FUNCTIONS (t);
     case VAR_DECL:
@@ -1024,6 +1039,10 @@
       pp_cxx_constant (pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (pp, t);
+      break;
+
     case RESULT_DECL:
       pp_cxx_unqualified_id (pp, t);
       break;
Index: gcc/cp/semantics.c
===================================================================
--- gcc/cp/semantics.c	(revision 180284)
+++ gcc/cp/semantics.c	(working copy)
@@ -7865,6 +7865,7 @@
     case TEMPLATE_PARM_INDEX:
     case TRAIT_EXPR:
     case IDENTIFIER_NODE:
+    case USERDEF_LITERAL:
       /* We can see a FIELD_DECL in a pointer-to-member expression.  */
     case FIELD_DECL:
     case PARM_DECL:
Index: gcc/cp/cxx-pretty-print.h
===================================================================
--- gcc/cp/cxx-pretty-print.h	(revision 180284)
+++ gcc/cp/cxx-pretty-print.h	(working copy)
@@ -74,5 +74,7 @@
 void pp_cxx_trait_expression (cxx_pretty_printer *, tree);
 void pp_cxx_va_arg_expression (cxx_pretty_printer *, tree);
 void pp_cxx_offsetof_expression (cxx_pretty_printer *, tree);
+void pp_cxx_userdef_literal (cxx_pretty_printer *, tree);
 
+
 #endif /* GCC_CXX_PRETTY_PRINT_H */
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 180284)
+++ gcc/cp/parser.c	(working copy)
@@ -225,6 +225,9 @@
 static void cp_parser_initial_pragma
   (cp_token *);
 
+static tree cp_literal_operator_id
+  (const char *);
+
 /* Manifest constants.  */
 #define CP_LEXER_BUFFER_SIZE ((256 * 1024) / sizeof (cp_token))
 #define CP_SAVED_TOKEN_STACK 5
@@ -1762,6 +1765,12 @@
   (cp_parser *);
 static tree cp_parser_string_literal
   (cp_parser *, bool, bool);
+static tree cp_parser_userdef_char_literal
+  (cp_parser *);
+static tree cp_parser_userdef_string_literal
+  (cp_token *);
+static tree cp_parser_userdef_numeric_literal
+  (cp_parser *);
 
 /* Basic concepts [gram.basic]  */
 
@@ -2270,6 +2279,8 @@
   (cp_parser *);
 static bool cp_parser_allow_gnu_extensions_p
   (cp_parser *);
+static bool cp_parser_is_pure_string_literal
+  (cp_token *);
 static bool cp_parser_is_string_literal
   (cp_token *);
 static bool cp_parser_is_keyword
@@ -2290,7 +2301,7 @@
 /* Returns nonzero if TOKEN is a string literal.  */
 
 static bool
-cp_parser_is_string_literal (cp_token* token)
+cp_parser_is_pure_string_literal (cp_token* token)
 {
   return (token->type == CPP_STRING ||
 	  token->type == CPP_STRING16 ||
@@ -2299,6 +2310,20 @@
 	  token->type == CPP_UTF8STRING);
 }
 
+/* Returns nonzero if TOKEN is a string literal
+   of a user-defined string literal.  */
+
+static bool
+cp_parser_is_string_literal (cp_token* token)
+{
+  return (cp_parser_is_pure_string_literal (token) ||
+	  token->type == CPP_STRING_USERDEF ||
+	  token->type == CPP_STRING16_USERDEF ||
+	  token->type == CPP_STRING32_USERDEF ||
+	  token->type == CPP_WSTRING_USERDEF ||
+	  token->type == CPP_UTF8STRING_USERDEF);
+}
+
 /* Returns nonzero if TOKEN is the indicated KEYWORD.  */
 
 static bool
@@ -3338,7 +3363,11 @@
   struct obstack str_ob;
   cpp_string str, istr, *strs;
   cp_token *tok;
-  enum cpp_ttype type;
+  enum cpp_ttype type, curr_type;
+  int have_suffix_p = 0;
+  tree string_tree;
+  tree suffix_id = NULL_TREE;
+  bool curr_tok_is_userdef_p = false;
 
   tok = cp_lexer_peek_token (parser->lexer);
   if (!cp_parser_is_string_literal (tok))
@@ -3347,7 +3376,18 @@
       return error_mark_node;
     }
 
-  type = tok->type;
+  if (cpp_userdef_string_p (tok->type))
+    {
+      string_tree = USERDEF_LITERAL_VALUE (tok->u.value);
+      curr_type = cpp_userdef_string_remove_type (tok->type);
+      curr_tok_is_userdef_p = true;
+    }
+  else
+    {
+      string_tree = tok->u.value;
+      curr_type = tok->type;
+    }
+  type = curr_type;
 
   /* Try to avoid the overhead of creating and destroying an obstack
      for the common case of just one string.  */
@@ -3356,10 +3396,19 @@
     {
       cp_lexer_consume_token (parser->lexer);
 
-      str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value);
-      str.len = TREE_STRING_LENGTH (tok->u.value);
+      str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree);
+      str.len = TREE_STRING_LENGTH (string_tree);
       count = 1;
 
+      if (curr_tok_is_userdef_p)
+	{
+	  suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value);
+	  have_suffix_p = 1;
+	  curr_type = cpp_userdef_string_remove_type (tok->type);
+	}
+      else
+	curr_type = tok->type;
+
       strs = &str;
     }
   else
@@ -3371,14 +3420,35 @@
 	{
 	  cp_lexer_consume_token (parser->lexer);
 	  count++;
-	  str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value);
-	  str.len = TREE_STRING_LENGTH (tok->u.value);
+	  str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree);
+	  str.len = TREE_STRING_LENGTH (string_tree);
 
-	  if (type != tok->type)
+	  if (curr_tok_is_userdef_p)
 	    {
+	      tree curr_suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value);
+	      if (have_suffix_p == 0)
+		{
+		  suffix_id = curr_suffix_id;
+		  have_suffix_p = 1;
+		}
+	      else if (have_suffix_p == 1
+		       && curr_suffix_id != suffix_id)
+		{
+		  error ("inconsistent user-defined literal suffixes"
+			 " %qD and %qD in string literal",
+			 suffix_id, curr_suffix_id);
+		  have_suffix_p = -1;
+		}
+	      curr_type = cpp_userdef_string_remove_type (tok->type);
+	    }
+	  else
+	    curr_type = tok->type;
+
+	  if (type != curr_type)
+	    {
 	      if (type == CPP_STRING)
-		type = tok->type;
-	      else if (tok->type != CPP_STRING)
+		type = curr_type;
+	      else if (curr_type != CPP_STRING)
 		error_at (tok->location,
 			  "unsupported non-standard concatenation "
 			  "of string literals");
@@ -3387,6 +3457,18 @@
 	  obstack_grow (&str_ob, &str, sizeof (cpp_string));
 
 	  tok = cp_lexer_peek_token (parser->lexer);
+	  if (cpp_userdef_string_p (tok->type))
+	    {
+	      string_tree = USERDEF_LITERAL_VALUE (tok->u.value);
+	      curr_type = cpp_userdef_string_remove_type (tok->type);
+	      curr_tok_is_userdef_p = true;
+	    }
+	  else
+	    {
+	      string_tree = tok->u.value;
+	      curr_type = tok->type;
+	      curr_tok_is_userdef_p = false;
+	    }
 	}
       while (cp_parser_is_string_literal (tok));
 
@@ -3424,6 +3506,13 @@
 	}
 
       value = fix_string_type (value);
+
+      if (have_suffix_p)
+	{
+	  tree literal = build_userdef_literal (suffix_id, value, NULL_TREE);
+	  tok->u.value = literal;
+	  return cp_parser_userdef_string_literal (tok);
+	}
     }
   else
     /* cpp_interpret_string has issued an error.  */
@@ -3435,7 +3524,187 @@
   return value;
 }
 
+/* Parse a user-defined char constant.  Returns a call to a user-defined
+   literal operator taking the character as an argument.  */
 
+static tree
+cp_parser_userdef_char_literal (cp_parser *parser)
+{
+  cp_token *token = NULL;
+  tree literal, suffix_id, value;
+  tree name, decl;
+  tree result;
+  VEC(tree,gc) *vec;
+
+  token = cp_lexer_consume_token (parser->lexer);
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  value = USERDEF_LITERAL_VALUE (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  vec = make_tree_vector ();
+  VEC_safe_push (tree, gc, vec, value);
+  decl = lookup_function_nonclass (name, vec, /*block_p=*/false);
+  if (!decl || decl == error_mark_node)
+    {
+      error ("unable to find user-defined character literal operator %qD",
+	     name);
+      release_tree_vector (vec);
+      return error_mark_node;
+    }
+  result = finish_call_expr (decl, &vec, false, true, tf_warning_or_error);
+  release_tree_vector (vec);
+
+  return result;
+}
+
+/* A subroutine of cp_parser_userdef_numeric_literal to
+   create a char... template parameter pack from a string node.  */
+
+static tree
+make_char_string_pack (tree value)
+{
+  tree charvec;
+  tree argpack = make_node (NONTYPE_ARGUMENT_PACK);
+  const char *str = TREE_STRING_POINTER (value);
+  int i, len = TREE_STRING_LENGTH (value) - 1;
+  tree argvec = make_tree_vec (1);
+
+  /* Fill in CHARVEC with all of the parameters.  */
+  charvec = make_tree_vec (len);
+  for (i = 0; i < len; ++i)
+    TREE_VEC_ELT (charvec, i) = build_int_cst (char_type_node, str[i]);
+
+  /* Build the argument packs.  */
+  SET_ARGUMENT_PACK_ARGS (argpack, charvec);
+  TREE_TYPE (argpack) = char_type_node;
+
+  TREE_VEC_ELT (argvec, 0) = argpack;
+
+  return argvec;
+}
+
+/* Parse a user-defined numeric constant.  returns a call to a user-defined
+   literal operator.  */
+
+static tree
+cp_parser_userdef_numeric_literal (cp_parser *parser)
+{
+  cp_token *token = NULL;
+  tree literal, suffix_id, value, num_string;
+  tree name, decl;
+  tree result = error_mark_node;
+  VEC(tree,gc) *args;
+
+  token = cp_lexer_consume_token (parser->lexer);
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  value = USERDEF_LITERAL_VALUE (literal);
+  num_string = USERDEF_LITERAL_NUM_STRING (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  /* Try to find the literal operator by finishing the call expression
+     with the numeric argument.  */
+  args = make_tree_vector ();
+  VEC_safe_push (tree, gc, args, value);
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl && decl != error_mark_node)
+    {
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  /* If the numeric argument didn't work, look for a raw literal
+     operator taking a const char* argument consisting of the number
+     in string format.  */
+  args = make_tree_vector ();
+  VEC_safe_push (tree, gc, args, num_string);
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl && decl != error_mark_node)
+    {
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  /* If the raw literal didn't work, look for a non-type template
+     function with parameter pack char....  Call the function with
+     template parameter characters representing the number.  */
+  args = make_tree_vector ();
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl && decl != error_mark_node)
+    {
+      tree tmpl_args = make_char_string_pack (num_string);
+      decl = lookup_template_function (decl, tmpl_args);
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  if (result == error_mark_node)
+    error ("unable to find user-defined numeric literal operator %qD", name);
+
+  return result;
+}
+
+/* Parse a user-defined string constant.  Returns a call to a user-defined
+   literal operator taking a character pointer and the length of the string
+   as arguments.  */
+static tree
+cp_parser_userdef_string_literal (cp_token *token)
+{
+  tree literal, suffix_id, value;
+  tree name, decl;
+  tree result;
+  VEC(tree,gc) *vec;
+  int len;
+
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+  value = USERDEF_LITERAL_VALUE (literal);
+  len = TREE_STRING_LENGTH (value) - 1;
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  vec = make_tree_vector ();
+  VEC_safe_push (tree, gc, vec, value);
+  VEC_safe_push (tree, gc, vec, build_int_cst (size_type_node, len));
+  decl = lookup_function_nonclass (name, vec, /*block_p=*/false);
+  if (!decl || decl == error_mark_node)
+    {
+      error ("unable to find user-defined string literal operator %qD", name);
+      release_tree_vector (vec);
+      return error_mark_node;
+    }
+  result = finish_call_expr (decl, &vec, false, true, tf_none);
+  if (result == error_mark_node)
+    error ("unable to find valid user-defined string literal operator %qD."
+	   "  Possible missing length argument in string literal operator.",
+	   name);
+  release_tree_vector (vec);
+
+  return result;
+}
+
+
 /* Basic concepts [gram.basic]  */
 
 /* Parse a translation-unit.
@@ -3578,12 +3847,16 @@
 	   character-literal
 	   floating-literal
 	   string-literal
-	   boolean-literal  */
+	   boolean-literal
+	   pointer-literal
+	   user-defined-literal  */
     case CPP_CHAR:
     case CPP_CHAR16:
     case CPP_CHAR32:
     case CPP_WCHAR:
     case CPP_NUMBER:
+      if (TREE_CODE (token->u.value) == USERDEF_LITERAL)
+	return cp_parser_userdef_numeric_literal (parser);
       token = cp_lexer_consume_token (parser->lexer);
       if (TREE_CODE (token->u.value) == FIXED_CST)
 	{
@@ -3637,11 +3910,22 @@
 	}
       return token->u.value;
 
+    case CPP_CHAR_USERDEF:
+    case CPP_CHAR16_USERDEF:
+    case CPP_CHAR32_USERDEF:
+    case CPP_WCHAR_USERDEF:
+      return cp_parser_userdef_char_literal (parser);
+
     case CPP_STRING:
     case CPP_STRING16:
     case CPP_STRING32:
     case CPP_WSTRING:
     case CPP_UTF8STRING:
+    case CPP_STRING_USERDEF:
+    case CPP_STRING16_USERDEF:
+    case CPP_STRING32_USERDEF:
+    case CPP_WSTRING_USERDEF:
+    case CPP_UTF8STRING_USERDEF:
       /* ??? Should wide strings be allowed when parser->translate_strings_p
 	 is false (i.e. in attributes)?  If not, we can kill the third
 	 argument to cp_parser_string_literal.  */
@@ -4477,6 +4761,14 @@
 	  /* If that didn't work, try a conversion-function-id.  */
 	  if (!cp_parser_parse_definitely (parser))
 	    id = cp_parser_conversion_function_id (parser);
+	  else if (UDLIT_OPER_P (id))
+	    {
+	      /* 17.6.3.3.5  */
+	      const char *name = UDLIT_OP_SUFFIX (id);
+	      if (name[0] != '_' && !in_system_header)
+		warning (0, "literal operator suffixes not preceded by %<_%>"
+			    " are reserved for future standardization");
+	    }
 
 	  return id;
 	}
@@ -5119,7 +5411,7 @@
 	/* Restore the saved message.  */
 	parser->type_definition_forbidden_message = saved_message;
 	/* `typeid' may not appear in an integral constant expression.  */
-	if (cp_parser_non_integral_constant_expression(parser, NIC_TYPEID))
+	if (cp_parser_non_integral_constant_expression (parser, NIC_TYPEID))
 	  return error_mark_node;
       }
       break;
@@ -9739,7 +10031,7 @@
   /* If the next token is `extern' and the following token is a string
      literal, then we have a linkage specification.  */
   if (token1.keyword == RID_EXTERN
-      && cp_parser_is_string_literal (&token2))
+      && cp_parser_is_pure_string_literal (&token2))
     cp_parser_linkage_specification (parser);
   /* If the next token is `template', then we have either a template
      declaration, an explicit instantiation, or an explicit
@@ -11170,6 +11462,22 @@
   return cp_parser_operator (parser);
 }
 
+/* Return an identifier node for a user-defined literal operator.
+   The suffix identifier is chained to the operator name identifier.  */
+
+static tree
+cp_literal_operator_id (const char* name)
+{
+  tree identifier;
+  char *buffer = XNEWVEC (char, strlen (UDLIT_OP_ANSI_PREFIX)
+			      + strlen (name) + 10);
+  sprintf (buffer, UDLIT_OP_ANSI_FORMAT, name);
+  identifier = get_identifier (buffer);
+  /*IDENTIFIER_UDLIT_OPNAME_P (identifier) = 1; If we get a flag someday. */
+
+  return identifier;
+}
+
 /* Parse an operator.
 
    operator:
@@ -11389,6 +11697,37 @@
       cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE);
       return ansi_opname (ARRAY_REF);
 
+    case CPP_STRING:
+      if (cxx_dialect == cxx98)
+	maybe_warn_cpp0x (CPP0X_USER_DEFINED_LITERALS);
+      if (TREE_STRING_LENGTH (token->u.value) > 2)
+	{
+	  error ("expected empty string after %<operator%> keyword");
+	  return error_mark_node;
+	}
+      /* Consume the string.  */
+      cp_lexer_consume_token (parser->lexer);
+      /* Look for the suffix identifier.  */
+      token = cp_lexer_peek_token (parser->lexer);
+      if (token->type == CPP_NAME)
+	{
+	  id = cp_parser_identifier (parser);
+	  if (id != error_mark_node)
+	    {
+	      const char *name = IDENTIFIER_POINTER (id);
+	      return cp_literal_operator_id (name);
+	    }
+	}
+      else
+	{
+	  error ("expected suffix identifier");
+	  return error_mark_node;
+	}
+
+    case CPP_STRING_USERDEF:
+      error ("missing space between %<\"\"%> and suffix identifier");
+      return error_mark_node;
+
     default:
       /* Anything else is an error.  */
       break;
@@ -20583,6 +20922,33 @@
   /* Finish up.  */
   finish_template_decl (parameter_list);
 
+  /* Check the template arguments for a literal operator template.  */
+  if (decl
+      && (TREE_CODE (decl) == FUNCTION_DECL || DECL_FUNCTION_TEMPLATE_P (decl))
+      && UDLIT_OPER_P (DECL_NAME (decl)))
+    {
+      bool ok = true;
+      if (parameter_list == NULL_TREE)
+	ok = false;
+      else
+	{
+	  int num_parms = TREE_VEC_LENGTH (parameter_list);
+	  if (num_parms != 1)
+	    ok = false;
+	  else
+	    {
+	      tree parm_list = TREE_VEC_ELT (parameter_list, 0);
+	      tree parm = INNERMOST_TEMPLATE_PARMS (parm_list);
+	      if (TREE_TYPE (parm) != char_type_node
+		  || !TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (parm)))
+		ok = false;
+	    }
+	}
+      if (!ok)
+	error ("literal operator template %qD has invalid parameter list."
+	       "  Expected non-type template argument pack <char...>",
+	       decl);
+    }
   /* Register member declarations.  */
   if (member_p && !friend_p && decl && !DECL_CLASS_TEMPLATE_P (decl))
     finish_member_declaration (decl);
@@ -22891,7 +23257,8 @@
   /* If the next token is `extern' and the following token is a string
      literal, then we have a linkage specification.  */
   if (token->keyword == RID_EXTERN
-      && cp_parser_is_string_literal (cp_lexer_peek_nth_token (parser->lexer, 2)))
+      && cp_parser_is_pure_string_literal
+	 (cp_lexer_peek_nth_token (parser->lexer, 2)))
     cp_parser_linkage_specification (parser);
   /* Handle #pragma, if any.  */
   else if (token->type == CPP_PRAGMA)
Index: gcc/cp/cp-objcp-common.c
===================================================================
--- gcc/cp/cp-objcp-common.c	(revision 180284)
+++ gcc/cp/cp-objcp-common.c	(working copy)
@@ -100,6 +100,8 @@
 
     case TEMPLATE_INFO:         return sizeof (struct tree_template_info);
 
+    case USERDEF_LITERAL:	return sizeof (struct tree_userdef_literal);
+
     default:
       gcc_unreachable ();
     }
Index: gcc/cp/mangle.c
===================================================================
--- gcc/cp/mangle.c	(revision 180284)
+++ gcc/cp/mangle.c	(working copy)
@@ -181,6 +181,7 @@
 static void write_unqualified_name (const tree);
 static void write_conversion_operator_name (const tree);
 static void write_source_name (tree);
+static void write_literal_operator_name (tree);
 static void write_unnamed_type_name (const tree);
 static void write_closure_type_name (const tree);
 static int hwint_to_ascii (unsigned HOST_WIDE_INT, const unsigned int, char *,
@@ -1174,6 +1175,8 @@
 	  }
       write_string (mangled_name);
     }
+  else if (UDLIT_OPER_P (identifier))
+    write_literal_operator_name (identifier);
   else
     write_source_name (identifier);
 }
@@ -1227,6 +1230,8 @@
 
 	  write_string (oni[DECL_OVERLOADED_OPERATOR_P (decl)].mangled_name);
 	}
+      else if (UDLIT_OPER_P (DECL_NAME (decl)))
+	write_literal_operator_name (DECL_NAME (decl));
       else
 	found = false;
 
@@ -1286,6 +1291,21 @@
   write_identifier (IDENTIFIER_POINTER (identifier));
 }
 
+/* Write a user-defined literal operator.
+   IDENTIFIER is an LITERAL_IDENTIFIER_NODE.  */
+
+static void
+write_literal_operator_name (tree identifier)
+{
+  const char* suffix = UDLIT_OP_SUFFIX (identifier);
+  char* buffer = XNEWVEC (char, strlen (UDLIT_OP_MANGLED_PREFIX)
+			      + strlen (suffix) + 10);
+  sprintf (buffer, UDLIT_OP_MANGLED_FORMAT, suffix);
+
+  write_unsigned_number (strlen (buffer));
+  write_identifier (buffer);
+}
+
 /* Encode 0 as _, and 1+ as n-1_.  */
 
 static void
Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h	(revision 180284)
+++ gcc/cp/cp-tree.h	(working copy)
@@ -400,7 +400,9 @@
   /* override controls, override/final */
   CPP0X_OVERRIDE_CONTROLS,
   /* non-static data member initializers */
-  CPP0X_NSDMI
+  CPP0X_NSDMI,
+  /* user defined literals */
+  CPP0X_USER_DEFINED_LITERALS
 } cpp0x_warn_str;
   
 /* The various kinds of operation used by composite_pointer_type. */
@@ -740,6 +742,7 @@
   TS_CP_TRAIT_EXPR,
   TS_CP_LAMBDA_EXPR,
   TS_CP_TEMPLATE_INFO,
+  TS_CP_USERDEF_LITERAL,
   LAST_TS_CP_ENUM
 };
 
@@ -765,6 +768,8 @@
     lambda_expression;
   struct tree_template_info GTY ((tag ("TS_CP_TEMPLATE_INFO")))
     template_info;
+  struct tree_userdef_literal GTY ((tag ("TS_CP_USERDEF_LITERAL")))
+    userdef_literal;
 };
 
 \f
@@ -4228,6 +4233,17 @@
              LAMBDANAME_PREFIX, \
 	     sizeof (LAMBDANAME_PREFIX) - 1))
 
+#define UDLIT_OP_ANSI_PREFIX "operator\"\" "
+#define UDLIT_OP_ANSI_FORMAT UDLIT_OP_ANSI_PREFIX "%s"
+#define UDLIT_OP_MANGLED_PREFIX "li"
+#define UDLIT_OP_MANGLED_FORMAT UDLIT_OP_MANGLED_PREFIX "%s"
+#define UDLIT_OPER_P(ID_NODE) \
+  (!strncmp (IDENTIFIER_POINTER (ID_NODE), \
+             UDLIT_OP_ANSI_PREFIX, \
+	     sizeof (UDLIT_OP_ANSI_PREFIX) - 1))
+#define UDLIT_OP_SUFFIX(ID_NODE) \
+  (IDENTIFIER_POINTER (ID_NODE) + sizeof (UDLIT_OP_ANSI_PREFIX) - 1)
+
 #if !defined(NO_DOLLAR_IN_LABEL) || !defined(NO_DOT_IN_LABEL)
 
 #define VTABLE_NAME_P(ID_NODE) (IDENTIFIER_POINTER (ID_NODE)[1] == 'v' \
@@ -5758,6 +5774,8 @@
 extern int lvalue_or_else			(tree, enum lvalue_use,
                                                  tsubst_flags_t);
 extern void check_template_keyword		(tree);
+extern bool check_raw_literal_operator		(const_tree decl);
+extern bool check_literal_operator_args		(const_tree, bool *, bool *);
 
 /* in typeck2.c */
 extern void require_complete_eh_spec_types	(tree, tree);
Index: libcpp/include/cpplib.h
===================================================================
--- libcpp/include/cpplib.h	(revision 180284)
+++ libcpp/include/cpplib.h	(working copy)
@@ -131,6 +131,16 @@
   TK(OBJC_STRING,	LITERAL) /* @"string" - Objective-C */		\
   TK(HEADER_NAME,	LITERAL) /* <stdio.h> in #include */		\
 									\
+  TK(CHAR_USERDEF,	LITERAL) /* 'char'_suffix - C++-0x */		\
+  TK(WCHAR_USERDEF,	LITERAL) /* L'char'_suffix - C++-0x */		\
+  TK(CHAR16_USERDEF,	LITERAL) /* u'char'_suffix - C++-0x */		\
+  TK(CHAR32_USERDEF,	LITERAL) /* U'char'_suffix - C++-0x */		\
+  TK(STRING_USERDEF,	LITERAL) /* "string"_suffix - C++-0x */		\
+  TK(WSTRING_USERDEF,	LITERAL) /* L"string"_suffix - C++-0x */	\
+  TK(STRING16_USERDEF,	LITERAL) /* u"string"_suffix - C++-0x */	\
+  TK(STRING32_USERDEF,	LITERAL) /* U"string"_suffix - C++-0x */	\
+  TK(UTF8STRING_USERDEF,LITERAL) /* u8"string"_suffix - C++-0x */	\
+									\
   TK(COMMENT,		LITERAL) /* Only if output comments.  */	\
 				 /* SPELL_LITERAL happens to DTRT.  */	\
   TK(MACRO_ARG,		NONE)	 /* Macro argument.  */			\
@@ -414,6 +424,9 @@
   /* True for traditional preprocessing.  */
   unsigned char traditional;
 
+  /* Nonzero for C++ 2011 Standard user-defnied literals.  */
+  unsigned char user_literals;
+
   /* Holds the name of the target (execution) character set.  */
   const char *narrow_charset;
 
@@ -829,13 +842,22 @@
 #define CPP_N_FRACT	0x100000 /* Fract types.  */
 #define CPP_N_ACCUM	0x200000 /* Accum types.  */
 
+#define CPP_N_USERDEF	0x1000000 /* C++0x user-defined literal.  */
+
 /* Classify a CPP_NUMBER token.  The return value is a combination of
    the flags from the above sets.  */
-extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *);
+extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *,
+				     const char **);
 
+/* Return the classification flags for a float suffix.  */
+extern unsigned int cpp_interpret_float_suffix (const char *, size_t);
+
+/* Return the classification flags for an int suffix.  */
+extern unsigned int cpp_interpret_int_suffix (const char *, size_t);
+
 /* Evaluate a token classified as category CPP_N_INTEGER.  */
 extern cpp_num cpp_interpret_integer (cpp_reader *, const cpp_token *,
-				      unsigned int type);
+				      unsigned int);
 
 /* Sign extend a number, with PRECISION significant bits and all
    others assumed clear, to fill out a cpp_num structure.  */
@@ -1005,4 +1027,20 @@
 extern void cpp_force_token_locations (cpp_reader *, source_location *);
 extern void cpp_stop_forcing_token_locations (cpp_reader *);
 
+/* In expr.c */
+extern enum cpp_ttype cpp_userdef_string_remove_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_string_add_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_char_remove_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_char_add_type
+  (enum cpp_ttype type);
+extern bool cpp_userdef_string_p
+  (enum cpp_ttype type);
+extern bool cpp_userdef_char_p
+  (enum cpp_ttype type);
+extern const char * cpp_get_userdef_suffix
+  (const cpp_token *);
+
 #endif /* ! LIBCPP_CPPLIB_H */
Index: libcpp/init.c
===================================================================
--- libcpp/init.c	(revision 180284)
+++ libcpp/init.c	(working copy)
@@ -80,22 +80,23 @@
   char digraphs;
   char uliterals;
   char rliterals;
+  char user_literals;
 };
 
 static const struct lang_flags lang_defaults[] =
-{ /*              c99 c++ xnum xid std  //   digr ulit rlit */
-  /* GNUC89   */  { 0,  0,  1,   0,  0,   1,   1,   0,   0 },
-  /* GNUC99   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1 },
-  /* GNUC1X   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1 },
-  /* STDC89   */  { 0,  0,  0,   0,  1,   0,   0,   0,   0 },
-  /* STDC94   */  { 0,  0,  0,   0,  1,   0,   1,   0,   0 },
-  /* STDC99   */  { 1,  0,  1,   0,  1,   1,   1,   0,   0 },
-  /* STDC1X   */  { 1,  0,  1,   0,  1,   1,   1,   1,   0 },
-  /* GNUCXX   */  { 0,  1,  1,   0,  0,   1,   1,   0,   0 },
-  /* CXX98    */  { 0,  1,  1,   0,  1,   1,   1,   0,   0 },
-  /* GNUCXX0X */  { 1,  1,  1,   0,  0,   1,   1,   1,   1 },
-  /* CXX0X    */  { 1,  1,  1,   0,  1,   1,   1,   1,   1 },
-  /* ASM      */  { 0,  0,  1,   0,  0,   1,   0,   0,   0 }
+{ /*              c99 c++ xnum xid std  //   digr ulit rlit user_literals */
+  /* GNUC89   */  { 0,  0,  1,   0,  0,   1,   1,   0,   0,    0 },
+  /* GNUC99   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1,    0 },
+  /* GNUC1X   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1,    0 },
+  /* STDC89   */  { 0,  0,  0,   0,  1,   0,   0,   0,   0,    0 },
+  /* STDC94   */  { 0,  0,  0,   0,  1,   0,   1,   0,   0,    0 },
+  /* STDC99   */  { 1,  0,  1,   0,  1,   1,   1,   0,   0,    0 },
+  /* STDC1X   */  { 1,  0,  1,   0,  1,   1,   1,   1,   0,    0 },
+  /* GNUCXX   */  { 0,  1,  1,   0,  0,   1,   1,   0,   0,    0 },
+  /* CXX98    */  { 0,  1,  1,   0,  1,   1,   1,   0,   0,    0 },
+  /* GNUCXX0X */  { 1,  1,  1,   0,  0,   1,   1,   1,   1,    1 },
+  /* CXX0X    */  { 1,  1,  1,   0,  1,   1,   1,   1,   1,    1 },
+  /* ASM      */  { 0,  0,  1,   0,  0,   1,   0,   0,   0,    0 }
   /* xid should be 1 for GNUC99, STDC99, GNUCXX, CXX98, GNUCXX0X, and
      CXX0X when no longer experimental (when all uses of identifiers
      in the compiler have been audited for correct handling of
@@ -120,6 +121,7 @@
   CPP_OPTION (pfile, digraphs)			 = l->digraphs;
   CPP_OPTION (pfile, uliterals)			 = l->uliterals;
   CPP_OPTION (pfile, rliterals)			 = l->rliterals;
+  CPP_OPTION (pfile, user_literals)		 = l->user_literals;
 }
 
 /* Initialize library global state.  */
Index: libcpp/expr.c
===================================================================
--- libcpp/expr.c	(revision 180284)
+++ libcpp/expr.c	(working copy)
@@ -1,6 +1,6 @@
 /* Parse C expressions for cpplib.
    Copyright (C) 1987, 1992, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
-   2002, 2004, 2008, 2009, 2010 Free Software Foundation.
+   2002, 2004, 2008, 2009, 2010, 2011 Free Software Foundation.
    Contributed by Per Bothner, 1994.
 
 This program is free software; you can redistribute it and/or modify it
@@ -185,6 +185,13 @@
 	     q ? CPP_N_MD_Q : CPP_N_DEFAULT));
 }
 
+/* Return the classification flags for a float suffix.  */
+unsigned int
+cpp_interpret_float_suffix (const char *s, size_t len)
+{
+  return interpret_float_suffix ((const unsigned char *)s, len);
+}
+
 /* Subroutine of cpp_classify_number.  S points to an integer suffix
    of length LEN, possibly zero. Returns 0 for an invalid suffix, or a
    flag vector describing the suffix.  */
@@ -219,11 +226,143 @@
 	     : (l == 1) ? CPP_N_MEDIUM : CPP_N_LARGE));
 }
 
+/* Return the classification flags for an int suffix.  */
+unsigned int
+cpp_interpret_int_suffix (const char *s, size_t len)
+{
+  return interpret_int_suffix ((const unsigned char *)s, len);
+}
+
+/* Return the string type corresponding to the the input user-defined string
+   literal type.  If the input type is not a user-defined string literal
+   type return the input type.  */
+enum cpp_ttype
+cpp_userdef_string_remove_type (enum cpp_ttype type)
+{
+  if (type == CPP_STRING_USERDEF)
+    return CPP_STRING;
+  else if (type == CPP_WSTRING_USERDEF)
+    return CPP_WSTRING;
+  else if (type == CPP_STRING16_USERDEF)
+    return CPP_STRING16;
+  else if (type == CPP_STRING32_USERDEF)
+    return CPP_STRING32;
+  else if (type == CPP_UTF8STRING_USERDEF)
+    return CPP_UTF8STRING;
+  else
+    return type;
+}
+
+/* Return the user-defined string literal type corresponding to the input
+   string type.  If the input type is not a string type return the input
+   type.  */
+enum cpp_ttype
+cpp_userdef_string_add_type (enum cpp_ttype type)
+{
+  if (type == CPP_STRING)
+    return CPP_STRING_USERDEF;
+  else if (type == CPP_WSTRING)
+    return CPP_WSTRING_USERDEF;
+  else if (type == CPP_STRING16)
+    return CPP_STRING16_USERDEF;
+  else if (type == CPP_STRING32)
+    return CPP_STRING32_USERDEF;
+  else if (type == CPP_UTF8STRING)
+    return CPP_UTF8STRING_USERDEF;
+  else
+    return type;
+}
+
+/* Return the char type corresponding to the the input user-defined char
+   literal type.  If the input type is not a user-defined char literal
+   type return the input type.  */
+enum cpp_ttype
+cpp_userdef_char_remove_type (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR_USERDEF)
+    return CPP_CHAR;
+  else if (type == CPP_WCHAR_USERDEF)
+    return CPP_WCHAR;
+  else if (type == CPP_CHAR16_USERDEF)
+    return CPP_STRING16;
+  else if (type == CPP_CHAR32_USERDEF)
+    return CPP_STRING32;
+  else
+    return type;
+}
+
+/* Return the user-defined char literal type corresponding to the input
+   char type.  If the input type is not a char type return the input
+   type.  */
+enum cpp_ttype
+cpp_userdef_char_add_type (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR)
+    return CPP_CHAR_USERDEF;
+  else if (type == CPP_WCHAR)
+    return CPP_WCHAR_USERDEF;
+  else if (type == CPP_CHAR16)
+    return CPP_CHAR16_USERDEF;
+  else if (type == CPP_CHAR32)
+    return CPP_CHAR32_USERDEF;
+  else
+    return type;
+}
+
+/* Return true if the token type is a user-defined string literal.  */
+bool
+cpp_userdef_string_p (enum cpp_ttype type)
+{
+  if (type == CPP_STRING_USERDEF
+   || type == CPP_WSTRING_USERDEF
+   || type == CPP_STRING16_USERDEF
+   || type == CPP_STRING32_USERDEF
+   || type == CPP_UTF8STRING_USERDEF)
+    return true;
+  else
+    return false;
+}
+
+/* Return true if the token type is a user-defined char literal.  */
+bool
+cpp_userdef_char_p (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR_USERDEF
+   || type == CPP_WCHAR_USERDEF
+   || type == CPP_CHAR16_USERDEF
+   || type == CPP_CHAR32_USERDEF)
+    return true;
+  else
+    return false;
+}
+
+/* Extract the suffix from a user-defined literal string or char.  */
+const char *
+cpp_get_userdef_suffix (const cpp_token *tok)
+{
+  unsigned int len = tok->val.str.len;
+  const char *text = (const char *)tok->val.str.text;
+  char delim;
+  unsigned int i;
+  for (i = 0; i < len; ++i)
+    if (text[i] == '\'' || text[i] == '"')
+      break;
+  if (i == len)
+    return text + len;
+  delim = text[i];
+  for (i = len; i > 0; --i)
+    if (text[i - 1] == delim)
+      break;
+  return text + i;
+}
+
 /* Categorize numeric constants according to their field (integer,
    floating point, or invalid), radix (decimal, octal, hexadecimal),
-   and type suffixes.  */
+   and type suffixes.  In C++0X if UD_SUFFIX is non null it will be
+   assigned any unrecognized suffix for a user-defined literal.  */
 unsigned int
-cpp_classify_number (cpp_reader *pfile, const cpp_token *token)
+cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
+		     const char **ud_suffix)
 {
   const uchar *str = token->val.str.text;
   const uchar *limit;
@@ -231,6 +370,9 @@
   enum {NOT_FLOAT = 0, AFTER_POINT, AFTER_EXPON} float_flag;
   bool seen_digit;
 
+  if (ud_suffix)
+    *ud_suffix = NULL;
+
   /* If the lexer has done its job, length one can only be a single
      digit.  Fast-path this very common case.  */
   if (token->val.str.len == 1)
@@ -361,10 +503,19 @@
       result = interpret_float_suffix (str, limit - str);
       if (result == 0)
 	{
-	  cpp_error (pfile, CPP_DL_ERROR,
-		     "invalid suffix \"%.*s\" on floating constant",
-		     (int) (limit - str), str);
-	  return CPP_N_INVALID;
+	  if (CPP_OPTION (pfile, user_literals))
+	    {
+	      if (ud_suffix)
+		*ud_suffix = (const char *) str;
+	      result = CPP_N_LARGE | CPP_N_USERDEF;
+	    }
+	  else
+	    {
+	      cpp_error (pfile, CPP_DL_ERROR,
+			 "invalid suffix \"%.*s\" on floating constant",
+			 (int) (limit - str), str);
+	      return CPP_N_INVALID;
+	    }
 	}
 
       /* Traditional C didn't accept any floating suffixes.  */
@@ -406,10 +557,19 @@
       result = interpret_int_suffix (str, limit - str);
       if (result == 0)
 	{
-	  cpp_error (pfile, CPP_DL_ERROR,
-		     "invalid suffix \"%.*s\" on integer constant",
-		     (int) (limit - str), str);
-	  return CPP_N_INVALID;
+	  if (CPP_OPTION (pfile, user_literals))
+	    {
+	      if (ud_suffix)
+		*ud_suffix = (const char *) str;
+	      result = CPP_N_UNSIGNED | CPP_N_LARGE | CPP_N_USERDEF;
+	    }
+	  else
+	    {
+	      cpp_error (pfile, CPP_DL_ERROR,
+			 "invalid suffix \"%.*s\" on integer constant",
+			 (int) (limit - str), str);
+	      return CPP_N_INVALID;
+	    }
 	}
 
       /* Traditional C only accepted the 'L' suffix.
@@ -539,7 +699,7 @@
 	    }
 	}
 
-      if (overflow)
+      if (overflow && !(type & CPP_N_USERDEF))
 	cpp_error (pfile, CPP_DL_PEDWARN,
 		   "integer constant is too large for its type");
       /* If too big to be signed, consider it unsigned.  Only warn for
@@ -748,7 +908,10 @@
   switch (token->type)
     {
     case CPP_NUMBER:
-      temp = cpp_classify_number (pfile, token);
+      temp = cpp_classify_number (pfile, token, NULL);
+      if (temp & CPP_N_USERDEF)
+	cpp_error (pfile, CPP_DL_ERROR,
+		   "user-defined literal in preprocessor expression");
       switch (temp & CPP_N_CATEGORY)
 	{
 	case CPP_N_FLOATING:
Index: libcpp/lex.c
===================================================================
--- libcpp/lex.c	(revision 180284)
+++ libcpp/lex.c	(working copy)
@@ -1478,6 +1478,18 @@
     }
  break_outer_loop:
 
+  if (CPP_OPTION (pfile, user_literals))
+    {
+      /* Grab user defined literal suffix.  */
+      if (ISIDST (*cur))
+	{
+	  type = cpp_userdef_string_add_type (type);
+	  ++cur;
+	}
+      while (ISIDNUM (*cur))
+	++cur;
+    }
+
   pfile->buffer->cur = cur;
   if (first_buff == NULL)
     create_literal (pfile, token, base, cur - base, type);
@@ -1581,6 +1593,19 @@
     cpp_error (pfile, CPP_DL_PEDWARN, "missing terminating %c character",
 	       (int) terminator);
 
+  if (CPP_OPTION (pfile, user_literals))
+    {
+      /* Grab user defined literal suffix.  */
+      if (ISIDST (*cur))
+	{
+	  type = cpp_userdef_char_add_type (type);
+	  type = cpp_userdef_string_add_type (type);
+          ++cur;
+	}
+      while (ISIDNUM (*cur))
+	++cur;
+    }
+
   pfile->buffer->cur = cur;
   create_literal (pfile, token, base, cur - base, type);
 }

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-26  9:16             ` Ed Smith-Rowland
@ 2011-10-26 20:13               ` Jason Merrill
  2011-10-27 19:15                 ` Ed Smith-Rowland
  2011-10-27 19:55                 ` Ed Smith-Rowland
  0 siblings, 2 replies; 36+ messages in thread
From: Jason Merrill @ 2011-10-26 20:13 UTC (permalink / raw)
  To: Ed Smith-Rowland; +Cc: Tom Tromey, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1110 bytes --]

On 10/26/2011 02:00 AM, Ed Smith-Rowland wrote:
> The patch was bootstrapped and regtested on x86_64-linux-gnu.

Really?  I ran into a warning about the unused "suffix" parameter to 
interpret_integer.  So I've fixed that error.  I also added a couple of 
comments, and implemented the change to check_literal_operator_args that 
I wondered about a while back.  And checked it all in.

But we aren't quite done, I think: I notice that the lookup of operators 
doesn't match what's in 2.14.8.  For instance, I don't think this should 
be accepted:

double operator"" _foo (long long unsigned);
double d = 1.2_foo;

The lookup described in 2.14.8 involves looking through the overload set 
for a particular signature before doing normal overload resolution.

Also, we don't need to worry about argument-dependent lookup for these 
operators, since none of the arguments can have associated namespaces. 
So I think we can use lookup_name rather than lookup_function_nonclass, 
only look it up once in cp_userdef_numeric_literal, and then only build 
one call depending on the contents of the overload set.

Jason

[-- Attachment #2: interpret-int.patch --]
[-- Type: text/x-patch, Size: 1745 bytes --]

commit e2fe821867bdc55a300f400fe8340a8d7168fb46
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Oct 26 13:38:05 2011 -0400

    interpret_int

diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c
index 46c0340..baee8eb 100644
--- a/gcc/c-family/c-lex.c
+++ b/gcc/c-family/c-lex.c
@@ -44,7 +44,7 @@ static splay_tree file_info_tree;
 int pending_lang_change; /* If we need to switch languages - C++ only */
 int c_header_level;	 /* depth in C headers - C++ only */
 
-static tree interpret_integer (const cpp_token *, unsigned int, const char *);
+static tree interpret_integer (const cpp_token *, unsigned int);
 static tree interpret_float (const cpp_token *, unsigned int, const char *);
 static tree interpret_fixed (const cpp_token *, unsigned int);
 static enum integer_type_kind narrowest_unsigned_type
@@ -329,7 +329,7 @@ c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags,
 	       Set PURE_ZERO to pass this information to the C++ parser.  */
 	    if (tok->val.str.len == 1 && *tok->val.str.text == '0')
 	      add_flags = PURE_ZERO;
-	    *value = interpret_integer (tok, flags, suffix);
+	    *value = interpret_integer (tok, flags);
 	    break;
 
 	  case CPP_N_FLOATING:
@@ -584,11 +584,9 @@ narrowest_signed_type (unsigned HOST_WIDE_INT low,
   return itk_none;
 }
 
-/* Interpret TOKEN, an integer with FLAGS as classified by cpplib.
-   For C++0X SUFFIX may contain a user-defined literal suffix.  */
+/* Interpret TOKEN, an integer with FLAGS as classified by cpplib.  */
 static tree
-interpret_integer (const cpp_token *token, unsigned int flags,
-		   const char *suffix)
+interpret_integer (const cpp_token *token, unsigned int flags)
 {
   tree value, type;
   enum integer_type_kind itk;

[-- Attachment #3: udl-comment.patch --]
[-- Type: text/x-patch, Size: 1985 bytes --]

commit 9c14fb264df67fdc3a28b47c67991345af634d85
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Oct 26 12:36:58 2011 -0400

    build_string comments

diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c
index baee8eb..7b220ab 100644
--- a/gcc/c-family/c-lex.c
+++ b/gcc/c-family/c-lex.c
@@ -344,6 +344,8 @@ c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags,
 	  {
 	    tree suffix_id = get_identifier (suffix);
 	    int len = tok->val.str.len - strlen (suffix);
+	    /* If this is going to be used as a C string to pass to a
+	       raw literal operator, we need to add a trailing NUL.  */
 	    tree num_string = build_string (len + 1,
 					    (const char *) tok->val.str.text);
 	    TREE_TYPE (num_string) = char_array_type_node;
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 5ba5008..860556c 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -8592,7 +8592,7 @@ grokdeclarator (const cp_declarator *declarator,
       error ("declaration of %qD as non-function", dname);
       return error_mark_node;
     }
- 
+
   if (dname
       && TREE_CODE (dname) == IDENTIFIER_NODE
       && UDLIT_OPER_P (dname)
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 840a30d..090482c 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -3667,6 +3667,7 @@ cp_parser_userdef_numeric_literal (cp_parser *parser)
 /* Parse a user-defined string constant.  Returns a call to a user-defined
    literal operator taking a character pointer and the length of the string
    as arguments.  */
+
 static tree
 cp_parser_userdef_string_literal (cp_token *token)
 {
diff --git a/gcc/tree.c b/gcc/tree.c
index 64c4968..2cbd68b 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -1525,6 +1525,7 @@ build_real_from_int_cst (tree type, const_tree i)
 
 /* Return a newly constructed STRING_CST node whose value is
    the LEN characters at STR.
+   Note that for a C string literal, LEN should include the trailing NUL.
    The TREE_TYPE is not initialized.  */
 
 tree

[-- Attachment #4: udl-check.patch --]
[-- Type: text/x-patch, Size: 2023 bytes --]

commit d083a0d7f94fb0fe3605d499366b1b637e169c17
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Oct 26 12:37:32 2011 -0400

    	* typeck.c (check_literal_operator_args): Avoid building types.

diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 59e1357..ec14934 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -8405,12 +8405,6 @@ check_literal_operator_args (const_tree decl,
       bool found_string_p = false;
       bool maybe_raw_p = false;
       bool found_size_p = false;
-      tree const_wchar_ptr_type_node
-	   = build_pointer_type (build_type_variant (wchar_type_node, 1, 0));
-      tree const_char16_ptr_type_node
-	   = build_pointer_type (build_type_variant (char16_type_node, 1, 0));
-      tree const_char32_ptr_type_node
-	   = build_pointer_type (build_type_variant (char32_type_node, 1, 0));
 
       *long_long_unsigned_p = false;
       *long_double_p = false;
@@ -8423,17 +8417,26 @@ check_literal_operator_args (const_tree decl,
 	  tree t = TREE_VALUE (argtype);
 	  ++arity;
 
-	  if (same_type_p (t, const_string_type_node))
+	  if (TREE_CODE (t) == POINTER_TYPE)
 	    {
-	      found_string_p = true;
-	      maybe_raw_p = true;
+	      t = TREE_TYPE (t);
+	      if (cp_type_quals (t) != TYPE_QUAL_CONST)
+		return false;
+	      t = TYPE_MAIN_VARIANT (t);
+	      if (same_type_p (t, char_type_node))
+		{
+		  found_string_p = true;
+		  maybe_raw_p = true;
+		}
+	      else if (same_type_p (t, wchar_type_node))
+		found_string_p = true;
+	      else if (same_type_p (t, char16_type_node))
+		found_string_p = true;
+	      else if (same_type_p (t, char32_type_node))
+		found_string_p = true;
+	      else
+		return false;
 	    }
-	  else if (same_type_p (t, const_wchar_ptr_type_node))
-	    found_string_p = true;
-	  else if (same_type_p (t, const_char16_ptr_type_node))
-	    found_string_p = true;
-	  else if (same_type_p (t, const_char32_ptr_type_node))
-	    found_string_p = true;
 	  else if (same_type_p (t, size_type_node))
 	    {
 	      if (!found_string_p)

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-26 20:13               ` Jason Merrill
@ 2011-10-27 19:15                 ` Ed Smith-Rowland
  2011-10-27 19:55                 ` Ed Smith-Rowland
  1 sibling, 0 replies; 36+ messages in thread
From: Ed Smith-Rowland @ 2011-10-27 19:15 UTC (permalink / raw)
  To: Jason Merrill; +Cc: Tom Tromey, gcc-patches

On 10/26/2011 03:38 PM, Jason Merrill wrote:
> On 10/26/2011 02:00 AM, Ed Smith-Rowland wrote:
>> The patch was bootstrapped and regtested on x86_64-linux-gnu.
>
> Really?  I ran into a warning about the unused "suffix" parameter to 
> interpret_integer.  So I've fixed that error.  I also added a couple 
> of comments, and implemented the change to check_literal_operator_args 
> that I wondered about a while back.  And checked it all in.
>
> But we aren't quite done, I think: I notice that the lookup of 
> operators doesn't match what's in 2.14.8.  For instance, I don't think 
> this should be accepted:
>
> double operator"" _foo (long long unsigned);
> double d = 1.2_foo;
I'm on it.
It looks like these incorrectly pass too:

int operator"" _char(char);
int operator"" _wchar_t(wchar_t);
int operator"" _char16_t(char16_t);
int operator"" _char32_t(char32_t);

int cwc = 'c'_wchar_t;
int cc16 = 'c'_char16_t;
int cc32 = 'c'_char32_t;

int wcc = L'c'_char;
int wcc16 = L'c'_char16_t;
int wcc31 = L'c'_char32_t;

etc.

I'm guessing pointer conversion errors would prevent something similar 
happening to raw and string operators but I'll check and repair.
>
> The lookup described in 2.14.8 involves looking through the overload 
> set for a particular signature before doing normal overload resolution.
>
> Also, we don't need to worry about argument-dependent lookup for these 
> operators, since none of the arguments can have associated namespaces. 
> So I think we can use lookup_name rather than 
> lookup_function_nonclass, only look it up once in 
> cp_userdef_numeric_literal, and then only build one call depending on 
> the contents of the overload set.
>
> Jason

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-26 20:13               ` Jason Merrill
  2011-10-27 19:15                 ` Ed Smith-Rowland
@ 2011-10-27 19:55                 ` Ed Smith-Rowland
  2011-10-27 20:37                   ` Jason Merrill
  1 sibling, 1 reply; 36+ messages in thread
From: Ed Smith-Rowland @ 2011-10-27 19:55 UTC (permalink / raw)
  To: Jason Merrill; +Cc: Tom Tromey, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1879 bytes --]

On 10/26/2011 03:38 PM, Jason Merrill wrote:
> On 10/26/2011 02:00 AM, Ed Smith-Rowland wrote:
>> The patch was bootstrapped and regtested on x86_64-linux-gnu.
>
> Really? I ran into a warning about the unused "suffix" parameter to 
> interpret_integer. So I've fixed that error. I also added a couple of 
> comments, and implemented the change to check_literal_operator_args 
> that I wondered about a while back. And checked it all in.
>
> But we aren't quite done, I think: I notice that the lookup of 
> operators doesn't match what's in 2.14.8. For instance, I don't think 
> this should be accepted:
>
> double operator"" _foo (long long unsigned);
> double d = 1.2_foo;
>
> The lookup described in 2.14.8 involves looking through the overload 
> set for a particular signature before doing normal overload resolution.
>
> Also, we don't need to worry about argument-dependent lookup for these 
> operators, since none of the arguments can have associated namespaces. 
> So I think we can use lookup_name rather than 
> lookup_function_nonclass, only look it up once in 
> cp_userdef_numeric_literal, and then only build one call depending on 
> the contents of the overload set.
>
> Jason
Jason,

Here is a patch that prevents the conversions outlined above and also 
for char types.
I also changed the name lookup to use the simpler and correct lookup_name().
There is a new testcase.

Now for the weirdness. When I try to make test cases with char16_t or 
char32_t it's like the u or U prefix is ignored and the character 
argument is of type char. I don't really use these character widths so 
my test cases could be wonky.

char16_t operator"" _rot(char16_t c) { return 127 - c; }

char16_t c = u'x'_rot;

$ char16.cpp:6:14: error: unable to find operator ‘operator"" _rot’ with 
‘char’ argument

Ideas? I'll try and see if there is a lexing error somewhere.

Ed


[-- Attachment #2: patch_udlit --]
[-- Type: text/plain, Size: 6715 bytes --]

Index: gcc/testsuite/g++.dg/cpp0x/udlit-implicit-conv-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-implicit-conv-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-implicit-conv-neg.C	(revision 0)
@@ -0,0 +1,33 @@
+// { dg-options -std=c++0x }
+
+int operator"" _bar (long double);
+
+double operator"" _foo (long long unsigned);
+
+int i = 12_bar; // { dg-error "unable to find|with|argument" }
+
+double d = 1.2_foo; // { dg-error "unable to find|with|argument" }
+
+int operator"" _char(char);
+
+int operator"" _wchar_t(wchar_t);
+
+int operator"" _char16_t(char16_t);
+
+int operator"" _char32_t(char32_t);
+
+int cwc = 'c'_wchar_t; // { dg-error "unable to find|with|argument" }
+int cc16 = 'c'_char16_t; // { dg-error "unable to find|with|argument" }
+int cc32 = 'c'_char32_t; // { dg-error "unable to find|with|argument" }
+
+int wcc = L'c'_char; // { dg-error "unable to find|with|argument" }
+int wcc16 = L'c'_char16_t; // { dg-error "unable to find|with|argument" }
+int wcc32 = L'c'_char32_t; // { dg-error "unable to find|with|argument" }
+
+int c16c = u'c'_char; // { dg-error "unable to find|with|argument" }
+int c16wc = u'c'_wchar_t; // { dg-error "unable to find|with|argument" }
+int c16c32 = u'c'_char32_t; // { dg-error "unable to find|with|argument" }
+
+int c32c = U'c'_char; // { dg-error "unable to find|with|argument" }
+int c32wc = U'c'_wchar_t; // { dg-error "unable to find|with|argument" }
+int c32c16 = U'c'_char16_t; // { dg-error "unable to find|with|argument" }
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 180556)
+++ gcc/cp/parser.c	(working copy)
@@ -3532,7 +3532,7 @@
 {
   cp_token *token = NULL;
   tree literal, suffix_id, value;
-  tree name, decl;
+  tree name, decl, argtypes = NULL_TREE;
   tree result;
   VEC(tree,gc) *vec;
 
@@ -3546,7 +3546,7 @@
   /* Lookup the name we got back from the id-expression.  */
   vec = make_tree_vector ();
   VEC_safe_push (tree, gc, vec, value);
-  decl = lookup_function_nonclass (name, vec, /*block_p=*/false);
+  decl = lookup_name (name);
   if (!decl || decl == error_mark_node)
     {
       error ("unable to find user-defined character literal operator %qD",
@@ -3554,6 +3554,17 @@
       release_tree_vector (vec);
       return error_mark_node;
     }
+
+  if (TREE_CODE (TREE_TYPE (decl)) != LANG_TYPE)
+    argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
+  if (argtypes != NULL_TREE
+      && TREE_VALUE (argtypes) != TREE_TYPE (value))
+    {
+      error ("unable to find operator %qD with %qT argument",
+	     name, TREE_TYPE (value));
+      return error_mark_node;
+    }
+
   result = finish_call_expr (decl, &vec, false, true, tf_warning_or_error);
   release_tree_vector (vec);
 
@@ -3594,7 +3605,7 @@
 {
   cp_token *token = NULL;
   tree literal, suffix_id, value, num_string;
-  tree name, decl;
+  tree name, decl, argtypes = NULL_TREE;
   tree result = error_mark_node;
   VEC(tree,gc) *args;
 
@@ -3605,21 +3616,47 @@
   num_string = USERDEF_LITERAL_NUM_STRING (literal);
   name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
 
+  decl = lookup_name (name);
+  if (!decl || decl == error_mark_node)
+    {
+      error ("unable to find user-defined numeric literal operator %qD", name);
+      return error_mark_node;
+    }
+
+  if (TREE_CODE (TREE_TYPE (decl)) != LANG_TYPE)
+    argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
+
+  if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE)
+    {
+      if (argtypes != NULL_TREE
+	  && TREE_CODE (TREE_VALUE (argtypes)) == REAL_TYPE)
+	{
+	  error ("unable to find %qD with %<unsigned long long int%> argument",
+		 name);
+	  return error_mark_node;
+	}
+    }
+  else if (TREE_CODE (TREE_TYPE (value)) == REAL_TYPE)
+    {
+      if (argtypes != NULL_TREE
+	  && TREE_CODE (TREE_VALUE (argtypes)) == INTEGER_TYPE)
+	{
+	  error ("unable to find %qD with %<long double%> argument", name);
+	  return error_mark_node;
+	}
+    }
+
   /* Build up a call to the user-defined operator  */
   /* Lookup the name we got back from the id-expression.  */
   /* Try to find the literal operator by finishing the call expression
      with the numeric argument.  */
   args = make_tree_vector ();
   VEC_safe_push (tree, gc, args, value);
-  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
-  if (decl && decl != error_mark_node)
+  result = finish_call_expr (decl, &args, false, true, tf_none);
+  if (result != error_mark_node)
     {
-      result = finish_call_expr (decl, &args, false, true, tf_none);
-      if (result != error_mark_node)
-	{
-	  release_tree_vector (args);
-	  return result;
-	}
+      release_tree_vector (args);
+      return result;
     }
   release_tree_vector (args);
 
@@ -3628,15 +3665,11 @@
      in string format.  */
   args = make_tree_vector ();
   VEC_safe_push (tree, gc, args, num_string);
-  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
-  if (decl && decl != error_mark_node)
+  result = finish_call_expr (decl, &args, false, true, tf_none);
+  if (result != error_mark_node)
     {
-      result = finish_call_expr (decl, &args, false, true, tf_none);
-      if (result != error_mark_node)
-	{
-	  release_tree_vector (args);
-	  return result;
-	}
+      release_tree_vector (args);
+      return result;
     }
   release_tree_vector (args);
 
@@ -3644,17 +3677,13 @@
      function with parameter pack char....  Call the function with
      template parameter characters representing the number.  */
   args = make_tree_vector ();
-  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
-  if (decl && decl != error_mark_node)
+  tree tmpl_args = make_char_string_pack (num_string);
+  decl = lookup_template_function (decl, tmpl_args);
+  result = finish_call_expr (decl, &args, false, true, tf_none);
+  if (result != error_mark_node)
     {
-      tree tmpl_args = make_char_string_pack (num_string);
-      decl = lookup_template_function (decl, tmpl_args);
-      result = finish_call_expr (decl, &args, false, true, tf_none);
-      if (result != error_mark_node)
-	{
-	  release_tree_vector (args);
-	  return result;
-	}
+      release_tree_vector (args);
+      return result;
     }
   release_tree_vector (args);
 
@@ -3688,7 +3717,7 @@
   vec = make_tree_vector ();
   VEC_safe_push (tree, gc, vec, value);
   VEC_safe_push (tree, gc, vec, build_int_cst (size_type_node, len));
-  decl = lookup_function_nonclass (name, vec, /*block_p=*/false);
+  decl = lookup_name (name);
   if (!decl || decl == error_mark_node)
     {
       error ("unable to find user-defined string literal operator %qD", name);

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-27 19:55                 ` Ed Smith-Rowland
@ 2011-10-27 20:37                   ` Jason Merrill
  2011-10-30 19:10                     ` Ed Smith-Rowland
  0 siblings, 1 reply; 36+ messages in thread
From: Jason Merrill @ 2011-10-27 20:37 UTC (permalink / raw)
  To: Ed Smith-Rowland; +Cc: Tom Tromey, gcc-patches

On 10/27/2011 03:32 PM, Ed Smith-Rowland wrote:
> +  if (TREE_CODE (TREE_TYPE (decl)) != LANG_TYPE)
> +    argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));

If you have multiple overloaded operator"" _foo, you need to iterate 
over them looking for the one (or ones, in the case of numeric literals) 
you want.

> +  if (argtypes != NULL_TREE
> +      && TREE_VALUE (argtypes) != TREE_TYPE (value))

I think you want

  if (argtypes == NULL_TREE
      || !same_type_p (TREE_VALUE (argtypes), TREE_TYPE (value)))

> +  if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE)
> +    {
> +      if (argtypes != NULL_TREE
> +	  && TREE_CODE (TREE_VALUE (argtypes)) == REAL_TYPE)
> +	{
> +	  error ("unable to find %qD with %<unsigned long long int%> argument",
> +		 name);
> +	  return error_mark_node;
> +	}
> +    }
> +  else if (TREE_CODE (TREE_TYPE (value)) == REAL_TYPE)
> +    {
> +      if (argtypes != NULL_TREE
> +	  && TREE_CODE (TREE_VALUE (argtypes)) == INTEGER_TYPE)
> +	{
> +	  error ("unable to find %qD with %<long double%> argument", name);
> +	  return error_mark_node;
> +	}
> +    }

This looks like it will break raw operators.

Jason

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-27 20:37                   ` Jason Merrill
@ 2011-10-30 19:10                     ` Ed Smith-Rowland
  2011-10-31 17:52                       ` Jason Merrill
  0 siblings, 1 reply; 36+ messages in thread
From: Ed Smith-Rowland @ 2011-10-30 19:10 UTC (permalink / raw)
  To: Jason Merrill; +Cc: Tom Tromey, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1876 bytes --]

On 10/27/2011 03:47 PM, Jason Merrill wrote:
> On 10/27/2011 03:32 PM, Ed Smith-Rowland wrote:
>> +  if (TREE_CODE (TREE_TYPE (decl)) != LANG_TYPE)
>> +    argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
>
> If you have multiple overloaded operator"" _foo, you need to iterate 
> over them looking for the one (or ones, in the case of numeric 
> literals) you want.
>
>> +  if (argtypes != NULL_TREE
>> + && TREE_VALUE (argtypes) != TREE_TYPE (value))
>
> I think you want
>
>  if (argtypes == NULL_TREE
>      || !same_type_p (TREE_VALUE (argtypes), TREE_TYPE (value)))
>
>> +  if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE)
>> +    {
>> +      if (argtypes != NULL_TREE
>> + && TREE_CODE (TREE_VALUE (argtypes)) == REAL_TYPE)
>> +    {
>> +      error ("unable to find %qD with %<unsigned long long int%> 
>> argument",
>> +         name);
>> +      return error_mark_node;
>> +    }
>> +    }
>> +  else if (TREE_CODE (TREE_TYPE (value)) == REAL_TYPE)
>> +    {
>> +      if (argtypes != NULL_TREE
>> + && TREE_CODE (TREE_VALUE (argtypes)) == INTEGER_TYPE)
>> +    {
>> +      error ("unable to find %qD with %<long double%> argument", name);
>> +      return error_mark_node;
>> +    }
>> +    }
>
> This looks like it will break raw operators.
>
> Jason
>
Here is a new patch that I think addresses these issues.
Basically, I am looping through all operators with the required suffix 
and looking for a perfectly matching argument for the given literal.

There are two issues.  One I think is just dg.  There are two FAILs but 
the error message comes out like I think it should.  I attached the sum 
and the log.  This is in udlit-implicit-conv-neg.C.  I tried for the 
life of me to copy the exact message from the terminal.  All the others 
work.

Also, as seen in udlit-resolve.C the version of an operator brought in 
by using a namespaced operator will win.

Ed


[-- Attachment #2: CL_udlit --]
[-- Type: text/plain, Size: 525 bytes --]

2011-10-30  Ed Smith-Rowland  <3dw4rd@verizon.net>

	gcc/testsuite/g++.dg/cpp0x/udlit-implicit-conv-neg.C: New.
	gcc/testsuite/g++.dg/cpp0x/udlit-resolve.C: New.

	gcc/cp/parser.c: (cp_parser_userdef_char_literal,
	cp_parser_userdef_numeric_literal, cp_parser_userdef_string_literal):
	Loop through the possible functions looking for exact argument type
	matches to resolve literal operator call.  Use lookup_name instead of
	lookup_function_nonclass.

	libcpp/expr.c: (cpp_userdef_char_remove_type): Fix boneheaded paste-o.

[-- Attachment #3: patch_udlit --]
[-- Type: text/plain, Size: 14925 bytes --]

Index: gcc/testsuite/g++.dg/cpp0x/udlit-implicit-conv-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-implicit-conv-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-implicit-conv-neg.C	(revision 0)
@@ -0,0 +1,59 @@
+// { dg-options -std=c++0x }
+
+#include <cstdint>
+
+int operator"" _bar (long double);
+
+double operator"" _foo (long long unsigned);
+
+int i = 12_bar; // { dg-error "unable to find numeric literal operator|with|argument" }
+
+double d = 1.2_foo; // { dg-error "unable to find numeric literal operator|with|argument" }
+
+int operator"" _char(char);
+
+int operator"" _wchar_t(wchar_t);
+
+int operator"" _char16_t(char16_t);
+
+int operator"" _char32_t(char32_t);
+
+int cwc = 'c'_wchar_t; // { dg-error "unable to find character literal operator|with|argument" }
+int cc16 = 'c'_char16_t; // { dg-error "unable to find character literal operator|with|argument" }
+int cc32 = 'c'_char32_t; // { dg-error "unable to find character literal operator|with|argument" }
+
+int wcc = L'c'_char; // { dg-error "unable to find character literal operator|with|argument" }
+int wcc16 = L'c'_char16_t; // { dg-error "unable to find character literal operator|with|argument" }
+int wcc32 = L'c'_char32_t; // { dg-error "unable to find character literal operator|with|argument" }
+
+int c16c = u'c'_char; // { dg-error "unable to find character literal operator|with|argument" }
+int c16wc = u'c'_wchar_t; // { dg-error "unable to find character literal operator|with|argument" }
+int c16c32 = u'c'_char32_t; // { dg-error "unable to find character literal operator|with|argument" }
+
+int c32c = U'c'_char; // { dg-error "unable to find character literal operator|with|argument" }
+int c32wc = U'c'_wchar_t; // { dg-error "unable to find character literal operator|with|argument" }
+int c32c16 = U'c'_char16_t; // { dg-error "unable to find character literal operator|with|argument" }
+
+int operator"" _char_str(const char*, std::size_t);
+
+int operator"" _wchar_t_str(const wchar_t*, std::size_t);
+
+int operator"" _char16_t_str(const char16_t*, std::size_t);
+
+int operator"" _char32_t_str(const char32_t*, std::size_t);
+
+int strwstr = "str"_wchar_t_str; // { dg-error "unable to find string literal operator|with|arguments" }
+int strstr16 = "str"_char16_t_str; // { dg-error "unable to find string literal operator|with|arguments" }
+int strstr32 = "str"_char32_t_str; // { dg-error "unable to find string literal operator|with|arguments" }
+
+int wstrstr = L"str"_char_str; // { dg-error "unable to find string literal operator|with|arguments" }
+int wstrstr16 = L"str"_char16_t_str; // { dg-error "unable to find string literal operator|with|arguments" }
+int wstrstr32 = L"str"_char32_t_str; // { dg-error "unable to find string literal operator|with|arguments" }
+
+int str16str = u"str"_char_str; // { dg-error "unable to find string literal operator|with|arguments" }
+int str16wstr = u"str"_wchar_t_str; // { dg-error "unable to find string literal operator|with|arguments" }
+int str16str32 = u"str"_char32_t_str; // { dg-error "unable to find string literal operator|with|arguments" }
+
+int str32str = U"str"_char_str; // { dg-error "unable to find string literal operator|with|arguments" }
+int str32wstr = U"str"_wchar_t_str; // { dg-error "unable to find string literal operator|with|arguments" }
+int str32str16 = U"str"_char16_t_str; // { dg-error "unable to find string literal operator string operator|with|arguments" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-resolve.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-resolve.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-resolve.C	(revision 0)
@@ -0,0 +1,43 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+#include <cstdint>
+#include <cassert>
+
+int operator"" _foo(const char*)                  { return 0; }
+int operator"" _foo(unsigned long long int)       { return 1; }
+int operator"" _foo(long double)                  { return 2; }
+int operator"" _foo(char)                         { return 3; }
+int operator"" _foo(wchar_t)                      { return 4; }
+int operator"" _foo(char16_t)                     { return 5; }
+int operator"" _foo(char32_t)                     { return 6; }
+int operator"" _foo(const char*, std::size_t)     { return 7; }
+int operator"" _foo(const wchar_t*, std::size_t)  { return 8; }
+int operator"" _foo(const char16_t*, std::size_t) { return 9; }
+int operator"" _foo(const char32_t*, std::size_t) { return 10; }
+template<char...> int operator"" _foo2()          { return 20; }
+int operator"" _foo2(unsigned long long int)      { return 21; }
+
+namespace bar {
+int operator"" _foo(unsigned long long int)       { return 101; }
+}
+using namespace bar;
+
+int
+main()
+{
+  //assert(123_foo == 0);
+  //assert(123_foo == 1);
+  assert(123_foo == 101);
+  assert(0.123_foo == 2);
+  assert('c'_foo == 3);
+  assert(L'c'_foo == 4);
+  assert(u'c'_foo == 5);
+  assert(U'c'_foo == 6);
+  assert("abc"_foo == 7);
+  assert(L"abc"_foo == 8);
+  assert(u"abc"_foo == 9);
+  assert(U"abc"_foo == 10);
+  assert(123_foo2 == 21);
+  //assert(_foo == );
+}
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 180680)
+++ gcc/cp/parser.c	(working copy)
@@ -3532,9 +3532,7 @@
 {
   cp_token *token = NULL;
   tree literal, suffix_id, value;
-  tree name, decl;
-  tree result;
-  VEC(tree,gc) *vec;
+  tree name, decl, fns;
 
   token = cp_lexer_consume_token (parser->lexer);
   literal = token->u.value;
@@ -3544,20 +3542,37 @@
 
   /* Build up a call to the user-defined operator  */
   /* Lookup the name we got back from the id-expression.  */
-  vec = make_tree_vector ();
-  VEC_safe_push (tree, gc, vec, value);
-  decl = lookup_function_nonclass (name, vec, /*block_p=*/false);
+  decl = lookup_name (name);
   if (!decl || decl == error_mark_node)
     {
       error ("unable to find user-defined character literal operator %qD",
 	     name);
-      release_tree_vector (vec);
       return error_mark_node;
     }
-  result = finish_call_expr (decl, &vec, false, true, tf_warning_or_error);
-  release_tree_vector (vec);
+  fns = decl;
+  while (fns)
+    {
+      tree fn = OVL_CURRENT (fns);
+      tree argtypes = NULL_TREE;
+      if (TREE_CODE (TREE_TYPE (fn)) != LANG_TYPE)
+	argtypes = TYPE_ARG_TYPES (TREE_TYPE (fn));
+      if (argtypes != NULL_TREE
+	  && same_type_p (TREE_VALUE (argtypes), TREE_TYPE (value)))
+	{
+          tree result;
+          VEC(tree,gc) *vec = make_tree_vector ();
+          VEC_safe_push (tree, gc, vec, value);
+	  result = finish_call_expr (fn, &vec, false, true, tf_warning_or_error);
+	  release_tree_vector (vec);
+	  if (result != error_mark_node)
+	    return result;
+	}
+      fns = OVL_NEXT (fns);
+    }
 
-  return result;
+  error ("unable to find character literal operator %qD with %qT argument",
+	 name, TREE_TYPE (value));
+  return error_mark_node;
 }
 
 /* A subroutine of cp_parser_userdef_numeric_literal to
@@ -3594,9 +3609,7 @@
 {
   cp_token *token = NULL;
   tree literal, suffix_id, value, num_string;
-  tree name, decl;
-  tree result = error_mark_node;
-  VEC(tree,gc) *args;
+  tree name, decl, fns;
 
   token = cp_lexer_consume_token (parser->lexer);
   literal = token->u.value;
@@ -3605,63 +3618,87 @@
   num_string = USERDEF_LITERAL_NUM_STRING (literal);
   name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
 
-  /* Build up a call to the user-defined operator  */
-  /* Lookup the name we got back from the id-expression.  */
-  /* Try to find the literal operator by finishing the call expression
-     with the numeric argument.  */
-  args = make_tree_vector ();
-  VEC_safe_push (tree, gc, args, value);
-  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
-  if (decl && decl != error_mark_node)
+  decl = lookup_name (name);
+  if (!decl || decl == error_mark_node)
     {
-      result = finish_call_expr (decl, &args, false, true, tf_none);
-      if (result != error_mark_node)
+      error ("unable to find user-defined numeric literal operator %qD", name);
+      return error_mark_node;
+    }
+
+  /* Look for a literal operator taking the exact type of numeric argument
+     as the literal value.  */
+  fns = decl;
+  while (fns)
+    {
+      tree fn = OVL_CURRENT (fns);
+      tree argtypes = NULL_TREE;
+      if (TREE_CODE (TREE_TYPE (fn)) != LANG_TYPE)
+	argtypes = TYPE_ARG_TYPES (TREE_TYPE (fn));
+      if (argtypes != NULL_TREE
+	  && same_type_p (TREE_VALUE (argtypes), TREE_TYPE (value)))
 	{
+          tree result;
+	  VEC(tree,gc) *args = make_tree_vector ();
+	  VEC_safe_push (tree, gc, args, value);
+	  result = finish_call_expr (fn, &args, false, true, tf_none);
 	  release_tree_vector (args);
-	  return result;
+	  if (result != error_mark_node)
+	    return result;
 	}
+      fns = OVL_NEXT (fns);
     }
-  release_tree_vector (args);
 
   /* If the numeric argument didn't work, look for a raw literal
      operator taking a const char* argument consisting of the number
      in string format.  */
-  args = make_tree_vector ();
-  VEC_safe_push (tree, gc, args, num_string);
-  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
-  if (decl && decl != error_mark_node)
+  fns = decl;
+  while (fns)
     {
-      result = finish_call_expr (decl, &args, false, true, tf_none);
-      if (result != error_mark_node)
+      tree fn = OVL_CURRENT (fns);
+      tree argtypes = NULL_TREE;
+      if (TREE_CODE (TREE_TYPE (fn)) != LANG_TYPE)
+	argtypes = TYPE_ARG_TYPES (TREE_TYPE (fn));
+      if (argtypes != NULL_TREE
+	  && same_type_p (TREE_VALUE (argtypes), const_string_type_node))
 	{
+          tree result;
+	  VEC(tree,gc) *args = make_tree_vector ();
+	  VEC_safe_push (tree, gc, args, num_string);
+	  result = finish_call_expr (fn, &args, false, true, tf_none);
 	  release_tree_vector (args);
-	  return result;
+	  if (result != error_mark_node)
+	    return result;
 	}
+      fns = OVL_NEXT (fns);
     }
-  release_tree_vector (args);
 
   /* If the raw literal didn't work, look for a non-type template
      function with parameter pack char....  Call the function with
      template parameter characters representing the number.  */
-  args = make_tree_vector ();
-  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
-  if (decl && decl != error_mark_node)
+  fns = decl;
+  while (fns)
     {
       tree tmpl_args = make_char_string_pack (num_string);
-      decl = lookup_template_function (decl, tmpl_args);
-      result = finish_call_expr (decl, &args, false, true, tf_none);
-      if (result != error_mark_node)
+      tree fn = OVL_CURRENT (fns);
+      tree argtypes = NULL_TREE;
+      if (TREE_CODE (TREE_TYPE (fn)) != LANG_TYPE)
+	argtypes = TYPE_ARG_TYPES (TREE_TYPE (fn));
+      if (argtypes != NULL_TREE
+	  && same_type_p (TREE_VALUE (argtypes), void_type_node))
 	{
+	  tree result;
+	  VEC(tree,gc) *args = make_tree_vector ();
+	  fn = lookup_template_function (fn, tmpl_args);
+	  result = finish_call_expr (fn, &args, false, true, tf_none);
 	  release_tree_vector (args);
-	  return result;
+	  if (result != error_mark_node)
+	    return result;
 	}
+      fns = OVL_NEXT (fns);
     }
-  release_tree_vector (args);
 
-  if (result == error_mark_node)
-    error ("unable to find user-defined numeric literal operator %qD", name);
-
-  return result;
+  error ("unable to find numeric literal operator %qD", name);
+  return error_mark_node;
 }
 
 /* Parse a user-defined string constant.  Returns a call to a user-defined
@@ -3671,38 +3708,60 @@
 static tree
 cp_parser_userdef_string_literal (cp_token *token)
 {
-  tree literal, suffix_id, value;
-  tree name, decl;
-  tree result;
-  VEC(tree,gc) *vec;
-  int len;
+  tree literal = token->u.value;
+  tree suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  tree name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+  tree value = USERDEF_LITERAL_VALUE (literal);
+  int len = TREE_STRING_LENGTH (value) - 1;
+  tree fns;
+  bool have_size = false;
 
-  literal = token->u.value;
-  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
-  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
-  value = USERDEF_LITERAL_VALUE (literal);
-  len = TREE_STRING_LENGTH (value) - 1;
-
   /* Build up a call to the user-defined operator  */
   /* Lookup the name we got back from the id-expression.  */
-  vec = make_tree_vector ();
-  VEC_safe_push (tree, gc, vec, value);
-  VEC_safe_push (tree, gc, vec, build_int_cst (size_type_node, len));
-  decl = lookup_function_nonclass (name, vec, /*block_p=*/false);
+  tree decl = lookup_name (name);
   if (!decl || decl == error_mark_node)
     {
       error ("unable to find user-defined string literal operator %qD", name);
-      release_tree_vector (vec);
       return error_mark_node;
     }
-  result = finish_call_expr (decl, &vec, false, true, tf_none);
-  if (result == error_mark_node)
+  fns = decl;
+  while (fns)
+    {
+      tree fn = OVL_CURRENT (fns);
+      tree argtypes = NULL_TREE;
+      if (TREE_CODE (TREE_TYPE (fn)) != LANG_TYPE)
+	argtypes = TYPE_ARG_TYPES (TREE_TYPE (fn));
+      if (argtypes != NULL_TREE && TREE_CHAIN (argtypes) != NULL_TREE)
+	{
+	  tree tsize = TREE_CHAIN (argtypes);
+	  if (tsize && same_type_p (TREE_VALUE (tsize), size_type_node))
+	    have_size = true;
+	  if (TREE_CODE (TREE_VALUE (argtypes)) == POINTER_TYPE
+	      && same_type_p (TREE_TYPE (TREE_VALUE (argtypes)),
+			      TREE_TYPE (TREE_TYPE (value))))
+	    {
+	      tree result;
+	      VEC(tree,gc) *vec = make_tree_vector ();
+	      VEC_safe_push (tree, gc, vec, value);
+	      VEC_safe_push (tree, gc, vec,
+			     build_int_cst (size_type_node, len));
+	      result = finish_call_expr (fn, &vec, false, true, tf_none);
+	      release_tree_vector (vec);
+	      if (result != error_mark_node)
+		return result;
+	    }
+	}
+      fns = OVL_NEXT (fns);
+    }
+
+  if (have_size)
+    error ("unable to find string literal operator %qD with %qT, %qT arguments",
+	   name, TREE_TYPE (value), size_type_node);
+  else
     error ("unable to find valid user-defined string literal operator %qD."
 	   "  Possible missing length argument in string literal operator.",
 	   name);
-  release_tree_vector (vec);
-
-  return result;
+  return error_mark_node;
 }
 
 
Index: libcpp/expr.c
===================================================================
--- libcpp/expr.c	(revision 180680)
+++ libcpp/expr.c	(working copy)
@@ -284,9 +284,9 @@
   else if (type == CPP_WCHAR_USERDEF)
     return CPP_WCHAR;
   else if (type == CPP_CHAR16_USERDEF)
-    return CPP_STRING16;
+    return CPP_CHAR16;
   else if (type == CPP_CHAR32_USERDEF)
-    return CPP_STRING32;
+    return CPP_CHAR32;
   else
     return type;
 }

[-- Attachment #4: g++.log.bz2 --]
[-- Type: application/x-bzip, Size: 4372 bytes --]

[-- Attachment #5: g++.sum.bz2 --]
[-- Type: application/x-bzip, Size: 992 bytes --]

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-30 19:10                     ` Ed Smith-Rowland
@ 2011-10-31 17:52                       ` Jason Merrill
  0 siblings, 0 replies; 36+ messages in thread
From: Jason Merrill @ 2011-10-31 17:52 UTC (permalink / raw)
  To: Ed Smith-Rowland; +Cc: gcc-patches

On 10/30/2011 01:13 PM, Ed Smith-Rowland wrote:
> +  /* Look for a literal operator taking the exact type of numeric argument
> +     as the literal value.  */

Is this right?  Do numeric literals only get here with type unsigned 
long long or long double?

> +  while (fns)
>      {
>        tree tmpl_args = make_char_string_pack (num_string);
> -      decl = lookup_template_function (decl, tmpl_args);
> -      result = finish_call_expr (decl, &args, false, true, tf_none);
> -      if (result != error_mark_node)
> +      tree fn = OVL_CURRENT (fns);
> +      tree argtypes = NULL_TREE;
> +      if (TREE_CODE (TREE_TYPE (fn)) != LANG_TYPE)
> +	argtypes = TYPE_ARG_TYPES (TREE_TYPE (fn));
> +      if (argtypes != NULL_TREE
> +	  && same_type_p (TREE_VALUE (argtypes), void_type_node))

Let's wait to make the pack until we find a template.  Also, you should 
be able to just check for TEMPLATE_DECL since we won't accept a literal 
operator template with different parameter types.

For string and character literals, we can still just build up a call; we 
only need to walk the overload list here for numeric literals.

Jason

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-31 17:58 3dw4rd
@ 2011-10-31 20:20 ` Jason Merrill
  0 siblings, 0 replies; 36+ messages in thread
From: Jason Merrill @ 2011-10-31 20:20 UTC (permalink / raw)
  To: 3dw4rd; +Cc: gcc-patches

On 10/31/2011 12:44 PM, 3dw4rd@verizon.net wrote:
>> For string and character literals, we can still just build up a call; we
>> only need to walk the overload list here for numeric literals.
>
> I found that if you don't walk the overload list for chars, a char could be routed to the operator taking wchar_t for example.

Ah, yes, I was overlooking the bit in the standard that says "S shall 
contain a literal operator (13.5.8) whose only parameter has the type ch".

The paragraph for string literals doesn't have a similar restriction.

Jason

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-26 20:33 3dw4rd
@ 2011-10-26 20:46 ` Jason Merrill
  0 siblings, 0 replies; 36+ messages in thread
From: Jason Merrill @ 2011-10-26 20:46 UTC (permalink / raw)
  To: 3dw4rd; +Cc: tromey, gcc-patches

On 10/26/2011 04:11 PM, 3dw4rd@verizon.net wrote:
> Thank you Jason and Tom for your help in getting this together an putting up with my slowness.

Thanks for all your work on this!

Jason

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
@ 2011-10-21 17:04 3dw4rd
  0 siblings, 0 replies; 36+ messages in thread
From: 3dw4rd @ 2011-10-21 17:04 UTC (permalink / raw)
  To: jason; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 98 bytes --]

Jason,

I split the changelog into four parts and tweaked some of the content and formatting.

Ed

[-- Attachment #2: CL_udlit_gcc_c-family --]
[-- Type: application/octet-stream, Size: 346 bytes --]

2011-10-21  Ed Smith-Rowland  <3dw4rd@verizon.net>

	Implement C++11 user-defined literals.
	* c-common.c (build_userdef_literal): New.
	* c-common.def: New tree code.
	* c-common.h (tree_userdef_literal): New tree struct and accessors.
	* c-lex.c (interpret_integer, interpret_float): Return suffixes.
	(c_lex_with_flags): Build literal tokens.

[-- Attachment #3: CL_udlit_gcc_cp --]
[-- Type: application/octet-stream, Size: 1321 bytes --]

2011-10-21  Ed Smith-Rowland  <3dw4rd@verizon.net>

	Implement C++11 user-defined literals.
	* cp-objcp-common.c: (cp_tree_size) Return size of USERDEF_LITERAL tree.
	* cp-tree.h: (UDLIT_OP_*, UDLIT_OPER_P): Literal operator
	name tools. New tree code for user-defined literals.
	* gcc/cp/cxx-pretty-print.h: (pp_cxx_userdef_literal) New.
	* gcc/cp/cxx-pretty-print.c: (pp_cxx_userdef_literal) New.
	(pp_cxx_primary_expression, pp_cxx_expression): Use it.
	* gcc/cp/decl.c: (cp_tree_node_structure): Return new tree code.
	(duplicate_decls): Check for raw vs. template operator conflicts.
	(grokfndecl, grokdeclarator): New checks for literal operators.
	* gcc/cp/error.c: (dump_expr): Warn about user-defined literals
	in C++98 mode. (dump_function_name): Pretty printing.
	* gcc/cp/mangle.c: (write_literal_operator_name): New.
	(write_unqualified_id, write_unqualified_name): Use it.
	* gcc/cp/parser.c: (cp_parser_operator): Handle operator"".
	(cp_parser_userdef_char_literal, cp_parser_userdef_numeric_literal,
	cp_parser_userdef_string_literal): New.
	(cp_parser_primary_expression): Handle new user-defined literal tokens
	with new functions.
	* gcc/cp/semantics.c: (potential_constant_expression_1): Add
	user-defined literals.
	* gcc/cp/typeck.c (check_raw_literal_operator,
	check_literal_operator_args): New.

[-- Attachment #4: CL_udlit_gcc_testsuite --]
[-- Type: application/octet-stream, Size: 1346 bytes --]

2011-10-21  Ed Smith-Rowland  <3dw4rd@verizon.net>

	Implement C++11 user-defined literals.
	* g++.dg/cpp0x/udlit-addr.C: New.
	* g++.dg/cpp0x/udlit-args.C: New.
	* g++.dg/cpp0x/udlit-args-neg.C: New.
	* g++.dg/cpp0x/udlit-clink-neg.C: New.
	* g++.dg/cpp0x/udlit-concat.C: New.
	* g++.dg/cpp0x/udlit-concat-neg.C: New.
	* g++.dg/cpp0x/udlit-constexpr.C: New.
	* g++.dg/cpp0x/udlit-cpp98-neg.C: New.
	* g++.dg/cpp0x/udlit-declare-neg.C: New.
	* g++.dg/cpp0x/udlit-friend.C: New.
	* g++.dg/cpp0x/udlit-general.C: New.
	* g++.dg/cpp0x/udlit-inline.C: New.
	* g++.dg/cpp0x/udlit-linkage-neg.C: New.
	* g++.dg/cpp0x/udlit-member-neg.C: New.
	* g++.dg/cpp0x/udlit-namespace.C: New.
	* g++.dg/cpp0x/udlit-nofunc-neg.C: New.
	* g++.dg/cpp0x/udlit-nonempty-str-neg.C: New.
	* g++.dg/cpp0x/udlit-nospace-neg.C: New.
	* g++.dg/cpp0x/udlit-nosuffix-neg.C: New.
	* g++.dg/cpp0x/udlit-nounder-neg.C: New.
	* g++.dg/cpp0x/udlit-operator-neg.C: New.
	* g++.dg/cpp0x/udlit-raw-str.C: New.
	* g++.dg/cpp0x/udlit-shadow-neg.C: New.
	* g++.dg/cpp0x/udlit-suffix-neg.C: New.
	* g++.dg/cpp0x/udlit-systemheader.C: New.
	* g++.dg/cpp0x/udlit-template.C: New.
	* g++.dg/cpp0x/udlit-tmpl-arg.C: New.
	* g++.dg/cpp0x/udlit-tmpl-arg-neg.C: New.
	* g++.dg/cpp0x/udlit-tmpl-parms.C: New.
	* g++.dg/cpp0x/udlit-tmpl-parms-neg.C: New.
	* g++.dg/cpp0x/udlit_system_header: New.

[-- Attachment #5: CL_udlit_libcpp --]
[-- Type: application/octet-stream, Size: 662 bytes --]

2011-10-21  Ed Smith-Rowland  <3dw4rd@verizon.net>

	Implement C++11 user-defined literals.
	* expr.c: (cpp_interpret_float_suffix, cpp_interpret_int_suffix,
	cpp_userdef_string_remove_type, cpp_userdef_string_add_type,
	cpp_userdef_char_remove_type, cpp_userdef_char_add_type,
	cpp_userdef_string_p, cpp_userdef_char_p, cpp_get_userdef_suffix): New.
	(cpp_classify_number): Classify unrecognized tokens as user-defined literals.
	* include/cpplib.h: Add new tokens for user-defined literals.
	* init.c: Add new preprocessor flag (cxx11).
	* lex.c: (lex_string, lex_raw_string): Handle user-defined literals
	including concatenation and promotion with suffixes.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-12  6:51                         ` Ed Smith-Rowland
@ 2011-10-12 18:49                           ` Jason Merrill
  0 siblings, 0 replies; 36+ messages in thread
From: Jason Merrill @ 2011-10-12 18:49 UTC (permalink / raw)
  To: Ed Smith-Rowland; +Cc: gcc-patches

On 10/12/2011 01:05 AM, Ed Smith-Rowland wrote:
> cp_parser_operator(function_id) is simply run twice in
> cp_parser_unqualified_id.
> Once inside cp_parser_template_id called at parser.c:4515.
> Once directly inside cp_parser_unqualified_id at parser.c:4525.

Ah.  You could try replacing the operator "" X tokens with a single 
CPP_LITERAL_OPERATOR token, like we do for CPP_NESTED_NAME_SPECIFIER and 
CPP_TEMPLATE_ID.

> cp_parser_template_id never succeeds with literal operator templates. I
> find that curious. But I haven't looked real hard and the things do get
> parsed somehow.

I'd only expect it to succeed if you actually wrote, e.g.,

operator""_c<'a','b','c'>();

Jason

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-11 17:39                       ` Jason Merrill
@ 2011-10-12  6:51                         ` Ed Smith-Rowland
  2011-10-12 18:49                           ` Jason Merrill
  0 siblings, 1 reply; 36+ messages in thread
From: Ed Smith-Rowland @ 2011-10-12  6:51 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

On 10/11/2011 12:57 PM, Jason Merrill wrote:
> On 10/11/2011 12:55 PM, Jason Merrill wrote:
>> On 10/09/2011 07:19 PM, Ed Smith-Rowland wrote:
>>> Does cp_parser_identifier (parser) *not* consume the identifier token?
>>
>> I'm pretty sure it does.
It does.
>>
>> Does it work to only complain if !cp_parser_parsing_tentatively?
>
> I suppose not, if you got no complaints with cp_parser_error.
>
> Jason
>
>
cp_parser_operator(function_id) is simply run twice in 
cp_parser_unqualified_id.
Once inside cp_parser_template_id called at parser.c:4515.
Once directly inside cp_parser_unqualified_id at parser.c:4525.

cp_parser_template_id never succeeds with literal operator templates.  I 
find that curious.  But I haven't looked real hard and the things do get 
parsed somehow.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-09 23:46                   ` Ed Smith-Rowland
@ 2011-10-11 19:20                     ` Jason Merrill
  2011-10-11 17:39                       ` Jason Merrill
  0 siblings, 1 reply; 36+ messages in thread
From: Jason Merrill @ 2011-10-11 19:20 UTC (permalink / raw)
  To: Ed Smith-Rowland; +Cc: gcc-patches

On 10/09/2011 07:19 PM, Ed Smith-Rowland wrote:
> Does cp_parser_identifier (parser) *not* consume the identifier token?

I'm pretty sure it does.

Does it work to only complain if !cp_parser_parsing_tentatively?

Jason

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-11 19:20                     ` Jason Merrill
@ 2011-10-11 17:39                       ` Jason Merrill
  2011-10-12  6:51                         ` Ed Smith-Rowland
  0 siblings, 1 reply; 36+ messages in thread
From: Jason Merrill @ 2011-10-11 17:39 UTC (permalink / raw)
  To: Ed Smith-Rowland; +Cc: gcc-patches

On 10/11/2011 12:55 PM, Jason Merrill wrote:
> On 10/09/2011 07:19 PM, Ed Smith-Rowland wrote:
>> Does cp_parser_identifier (parser) *not* consume the identifier token?
>
> I'm pretty sure it does.
>
> Does it work to only complain if !cp_parser_parsing_tentatively?

I suppose not, if you got no complaints with cp_parser_error.

Jason

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-09  1:18                 ` Jason Merrill
@ 2011-10-09 23:46                   ` Ed Smith-Rowland
  2011-10-11 19:20                     ` Jason Merrill
  0 siblings, 1 reply; 36+ messages in thread
From: Ed Smith-Rowland @ 2011-10-09 23:46 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

On 10/08/2011 07:15 PM, Jason Merrill wrote:
> On 10/08/2011 07:25 PM, Ed Smith-Rowland wrote:
>> Also, In spite of the documentation cp_parser_template_parameter_list
>> returns a TREE_VEC not a TREE_LIST. This happens inside
>> end_template_parm_list called inside the former. So parameter_list is a
>> TREE_VEC, parm_list is a TREE_LIST, parm is a PARM_DECL, etc.
>
> Ah, I was thinking of template arguments rather than parameters.  
> You're right, except that INNERMOST_TEMPLATE_PARMS should be just 
> TREE_VALUE; you are already starting from the innermost parm list if 
> you use what end_template_parm_list returns.
>
> Though it occurs to me that push_template_decl_real might be a better 
> place for this check.
>
>> I'm still looking for a fix for duplicate errors/warnings coming from
>> cp_parser_operator. I tried cp_parser_error and lost the errors. I'll
>> look for different code paths for the two invocations and see if I can
>> either move something up or see if something is set differently between
>> the two that would be useful for a flag.
>
> One approach would be changing the token stream after the first error 
> to something that won't produce another error, e.g. changing 
> token->u.value to be an empty string after you complain about it being 
> non-empty.
Interesting.  That one error is the one of the three that does *not* repeat.
One idea.  the fist error about non-empty string is followed by a 
consume_token (for the string).
Does cp_parser_identifier (parser) *not* consume the identifier token?  
Is that token left on the stream for  second pass?
I'll try it and get back.
>
> Jason
>

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-08 21:38               ` Ed Smith-Rowland
@ 2011-10-09  1:18                 ` Jason Merrill
  2011-10-09 23:46                   ` Ed Smith-Rowland
  0 siblings, 1 reply; 36+ messages in thread
From: Jason Merrill @ 2011-10-09  1:18 UTC (permalink / raw)
  To: Ed Smith-Rowland; +Cc: gcc-patches

On 10/08/2011 07:25 PM, Ed Smith-Rowland wrote:
> Also, In spite of the documentation cp_parser_template_parameter_list
> returns a TREE_VEC not a TREE_LIST. This happens inside
> end_template_parm_list called inside the former. So parameter_list is a
> TREE_VEC, parm_list is a TREE_LIST, parm is a PARM_DECL, etc.

Ah, I was thinking of template arguments rather than parameters.  You're 
right, except that INNERMOST_TEMPLATE_PARMS should be just TREE_VALUE; 
you are already starting from the innermost parm list if you use what 
end_template_parm_list returns.

Though it occurs to me that push_template_decl_real might be a better 
place for this check.

> I'm still looking for a fix for duplicate errors/warnings coming from
> cp_parser_operator. I tried cp_parser_error and lost the errors. I'll
> look for different code paths for the two invocations and see if I can
> either move something up or see if something is set differently between
> the two that would be useful for a flag.

One approach would be changing the token stream after the first error to 
something that won't produce another error, e.g. changing token->u.value 
to be an empty string after you complain about it being non-empty.

Jason

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-05 21:24             ` Jason Merrill
@ 2011-10-08 21:38               ` Ed Smith-Rowland
  2011-10-09  1:18                 ` Jason Merrill
  0 siblings, 1 reply; 36+ messages in thread
From: Ed Smith-Rowland @ 2011-10-08 21:38 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 2990 bytes --]

On 10/05/2011 05:08 PM, Jason Merrill wrote:
> On 10/05/2011 11:55 AM, Ed Smith-Rowland wrote:
>> +         int num_parms = TREE_VEC_LENGTH (parameter_list);
>> +         if (num_parms != 1)
>> +           ok = false;
>> +         else
>> +           {
>> +             tree parm_list = TREE_VEC_ELT (parameter_list, 0);
>> +             tree parm = INNERMOST_TEMPLATE_PARMS (parm_list);
>
> This is backwards; you want to do INNERMOST_TEMPLATE_PARMS before 
> looking at the number of parms or pulling out the one at index 0.
>
Now I'm confused.  In an earlier email you said (3/30/2011 in response 
to how to check template parms):
----------------------------------------------------------------------------------------
If you're looking at the PARM_DECL for the template parameter, you want 
to check that TREE_TYPE (decl) is char_type_node and that 
TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (decl)) is true.  Does that 
help?
----------------------------------------------------------------------------------------
Also, In spite of the documentation cp_parser_template_parameter_list 
returns a TREE_VEC not a TREE_LIST.  This happens inside 
end_template_parm_list called inside the former.  So parameter_list is a 
TREE_VEC, parm_list is a TREE_LIST, parm is a PARM_DECL, etc.
>> +struct GTY(()) tree_userdef_literal {
>> +  struct tree_common common;
>
> I think you can use tree_base instead of tree_common here, since you 
> aren't using TREE_TYPE or TREE_CHAIN.
>
Done.
>> One thing doesn't work.  Earlier I had said that friend declarations 
>> failed.  Not true.  What fails is defining the function body in the 
>> class definition.  The function is simply not recorded.  I'm trying 
>> to track this down but pointers would be helpful.  If I write the 
>> function body outside the class definition friend works perfectly.
>
>> About friends.  The lookup for user-defined literal operators isn't 
>> ADL.  They are a lot like normal functions because of the suffix-id 
>> as opposed to operator<< in this regard.  Thus a friend literal 
>> operator should be accessible both as an explicit operator call and 
>> via a literal.  Both are tested and except as noted above about 
>> inline defs the tests pass.
>
> A function that is only declared in a friend declaration can only be 
> found by ADL, so that doesn't sound like a failure to me; it sounds 
> like it's working the way it should.  However, if you declare the 
> function earlier and then define it in the friend declaration it ought 
> to work.
>
Ok.  Then things really do work all around.  I almost never use friend.  ;-)
> Jason
>
I'm still looking for a fix for duplicate errors/warnings coming from 
cp_parser_operator.  I tried cp_parser_error and lost the errors.  I'll 
look for different code paths for the two invocations and see if I can 
either move something up or see if something is set differently between 
the two that would be useful for a flag.

Then I think this thing is really done.

Ed


[-- Attachment #2: patch26 --]
[-- Type: text/plain, Size: 73147 bytes --]

Index: gcc/c-family/c-common.c
===================================================================
--- gcc/c-family/c-common.c	(revision 179328)
+++ gcc/c-family/c-common.c	(working copy)
@@ -9919,4 +9919,17 @@
   MARK_TS_TYPED (EXCESS_PRECISION_EXPR);
 }
 
+/* Build a user-defined numeric literal out of an integer constant type VALUE
+   with identifier SUFFIX.  */
+
+tree
+build_userdef_literal (tree suffix_id, tree value, tree num_string)
+{
+  tree literal = make_node (USERDEF_LITERAL);
+  USERDEF_LITERAL_SUFFIX_ID (literal) = suffix_id;
+  USERDEF_LITERAL_VALUE (literal) = value;
+  USERDEF_LITERAL_NUM_STRING (literal) = num_string;
+  return literal;
+}
+
 #include "gt-c-family-c-common.h"
Index: gcc/c-family/c-lex.c
===================================================================
--- gcc/c-family/c-lex.c	(revision 179328)
+++ gcc/c-family/c-lex.c	(working copy)
@@ -44,8 +44,8 @@
 int pending_lang_change; /* If we need to switch languages - C++ only */
 int c_header_level;	 /* depth in C headers - C++ only */
 
-static tree interpret_integer (const cpp_token *, unsigned int);
-static tree interpret_float (const cpp_token *, unsigned int);
+static tree interpret_integer (const cpp_token *, unsigned int, const char *);
+static tree interpret_float (const cpp_token *, unsigned int, const char *);
 static tree interpret_fixed (const cpp_token *, unsigned int);
 static enum integer_type_kind narrowest_unsigned_type
 	(unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned int);
@@ -314,7 +314,8 @@
 
     case CPP_NUMBER:
       {
-	unsigned int flags = cpp_classify_number (parse_in, tok);
+	const char *suffix = NULL;
+	unsigned int flags = cpp_classify_number (parse_in, tok, &suffix);
 
 	switch (flags & CPP_N_CATEGORY)
 	  {
@@ -328,16 +329,27 @@
 	       Set PURE_ZERO to pass this information to the C++ parser.  */
 	    if (tok->val.str.len == 1 && *tok->val.str.text == '0')
 	      add_flags = PURE_ZERO;
-	    *value = interpret_integer (tok, flags);
+	    *value = interpret_integer (tok, flags, suffix);
 	    break;
 
 	  case CPP_N_FLOATING:
-	    *value = interpret_float (tok, flags);
+	    *value = interpret_float (tok, flags, suffix);
 	    break;
 
 	  default:
 	    gcc_unreachable ();
 	  }
+
+	if (flags & CPP_N_USERDEF)
+	  {
+	    tree num_string = build_string (tok->val.str.len - strlen (suffix),
+					    (const char *) tok->val.str.text);
+	    TREE_TYPE (num_string) = char_array_type_node;
+	    num_string = fix_string_type (num_string);
+	    tree literal = build_userdef_literal (get_identifier (suffix),
+						  *value, num_string);
+	    *value = literal;
+	  }
       }
       break;
 
@@ -415,6 +427,22 @@
       }
       goto retry;
 
+    case CPP_CHAR_USERDEF:
+    case CPP_WCHAR_USERDEF:
+    case CPP_CHAR16_USERDEF:
+    case CPP_CHAR32_USERDEF:
+      {
+	tree literal;
+	cpp_token temp_tok = *tok;
+	const char *suffix = cpp_get_userdef_suffix (tok);
+	temp_tok.val.str.len -= strlen (suffix);
+	temp_tok.type = cpp_userdef_char_remove_type (type);
+	literal = build_userdef_literal (get_identifier (suffix),
+					 lex_charconst (&temp_tok), NULL_TREE);
+	*value = literal;
+      }
+      break;
+
     case CPP_CHAR:
     case CPP_WCHAR:
     case CPP_CHAR16:
@@ -422,6 +450,22 @@
       *value = lex_charconst (tok);
       break;
 
+    case CPP_STRING_USERDEF:
+    case CPP_WSTRING_USERDEF:
+    case CPP_STRING16_USERDEF:
+    case CPP_STRING32_USERDEF:
+    case CPP_UTF8STRING_USERDEF:
+      {
+	tree literal, string;
+	const char *suffix = cpp_get_userdef_suffix (tok);
+	string = build_string (tok->val.str.len - strlen (suffix),
+			       (const char *) tok->val.str.text);
+	literal = build_userdef_literal (get_identifier (suffix),
+					 string, NULL_TREE);
+	*value = literal;
+      }
+      break;
+
     case CPP_STRING:
     case CPP_WSTRING:
     case CPP_STRING16:
@@ -536,9 +580,11 @@
   return itk_none;
 }
 
-/* Interpret TOKEN, an integer with FLAGS as classified by cpplib.  */
+/* Interpret TOKEN, an integer with FLAGS as classified by cpplib.
+   For C++0X SUFFIX may contain a user-defined literal suffix.  */
 static tree
-interpret_integer (const cpp_token *token, unsigned int flags)
+interpret_integer (const cpp_token *token, unsigned int flags,
+		   const char *suffix)
 {
   tree value, type;
   enum integer_type_kind itk;
@@ -621,9 +667,10 @@
 }
 
 /* Interpret TOKEN, a floating point number with FLAGS as classified
-   by cpplib.  */
+   by cpplib.  For C++0X SUFFIX may contain a user-defined literal suffix.  */
 static tree
-interpret_float (const cpp_token *token, unsigned int flags)
+interpret_float (const cpp_token *token, unsigned int flags,
+		 const char *suffix)
 {
   tree type;
   tree const_type;
@@ -702,7 +749,9 @@
      has any suffixes, cut them off; REAL_VALUE_ATOF/ REAL_VALUE_HTOF
      can't handle them.  */
   copylen = token->val.str.len;
-  if (flags & CPP_N_DFLOAT)
+  if (flags & CPP_N_USERDEF)
+    copylen -= strlen (suffix);
+  else if (flags & CPP_N_DFLOAT)
     copylen -= 2;
   else
     {
Index: gcc/c-family/c-common.h
===================================================================
--- gcc/c-family/c-common.h	(revision 179328)
+++ gcc/c-family/c-common.h	(working copy)
@@ -1067,4 +1067,27 @@
   return NULL;
 }
 
+/* A suffix-identifier value doublet that represents user-defined literals
+   for C++-0x.  */
+struct GTY(()) tree_userdef_literal {
+  struct tree_base base;
+  tree suffix_id;
+  tree value;
+  tree num_string;
+};
+
+#define USERDEF_LITERAL_SUFFIX_ID(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->suffix_id)
+
+#define USERDEF_LITERAL_VALUE(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->value)
+
+#define USERDEF_LITERAL_NUM_STRING(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->num_string)
+
+#define USERDEF_LITERAL_TYPE(NODE) \
+  (TREE_TYPE (USERDEF_LITERAL_VALUE (NODE)))
+
+extern tree build_userdef_literal (tree suffix_id, tree value, tree num_string);
+
 #endif /* ! GCC_C_COMMON_H */
Index: gcc/c-family/c-common.def
===================================================================
--- gcc/c-family/c-common.def	(revision 179328)
+++ gcc/c-family/c-common.def	(working copy)
@@ -47,6 +47,12 @@
    evaluated.  */
 DEFTREECODE (EXCESS_PRECISION_EXPR, "excess_precision_expr", tcc_expression, 1)
 
+/* Used to represent a user-defined literal.
+   The operands are an IDENTIFIER for the suffix, the VALUE of the literal,
+   and for numeric literals the original string representation of the
+   number.  */
+DEFTREECODE (USERDEF_LITERAL, "userdef_literal", tcc_exceptional, 3)
+
 /*
 Local variables:
 mode:c
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C	(revision 0)
@@ -0,0 +1,4 @@
+// { dg-options -std=c++0x }
+
+template<char...>
+  int operator"" _xyz(unsigned long long);	// { dg-error "has invalid argument list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit_system_header
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit_system_header	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit_system_header	(revision 0)
@@ -0,0 +1,6 @@
+
+#pragma GCC system_header
+
+char
+operator"" stdsuffix(char __c)
+{ return __c/2; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C	(revision 0)
@@ -0,0 +1,29 @@
+// { dg-options "-std=c++0x" }
+
+//  Can't have *both* literal operator template and raw literal operator.
+
+int
+operator"" _abc(const char*)
+  {
+    return 42;
+  }
+
+template<char...>
+  int
+  operator"" _abc() // {dg-error "user-defined literal operator template|conflicts with user-defined raw literal operator"}
+  {
+    return 13;
+  }
+
+template<char...>
+  int
+  operator"" _def()
+  {
+    return 12;
+  }
+
+int
+operator"" _def(const char*) // {dg-error "user-defined raw literal operator|conflicts with user-defined literal operator template"}
+  {
+    return 43;
+  }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C	(revision 0)
@@ -0,0 +1,43 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test simple operator declaration and definition in namespaces.
+
+#include <cmath>
+#include <limits>
+
+namespace Long
+{
+  long double operator"" _LL(long double);
+}
+
+namespace Short
+{
+  short
+  operator"" _SS(long double x)
+  { return std::fmod(x, static_cast<long double>(std::numeric_limits<short>::max())); }
+}
+
+void
+test1()
+{
+  long double x = Long::operator "" _LL(1.2L);
+
+  using namespace Short;
+  short s = operator"" _SS(1.2L);
+  short s2 = 1.2_SS;
+}
+
+int
+main()
+{
+  test1();
+}
+
+namespace Long
+{
+  long double
+  operator"" _LL(long double x)
+  { return x + 2.0L; }
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C	(revision 0)
@@ -0,0 +1,15 @@
+// { dg-options -std=c++0x }
+
+class Foo
+{
+public:
+  Foo() { }
+  int operator"" _Bar(char32_t);  // { dg-error "must be a non-member function" }
+};
+
+int i = operator"" _Bar(U'x');  // { dg-error "was not declared in this scope" }
+int j = U'x'_Bar;  // { dg-error "unable to find user-defined character literal operator" }
+
+int
+Foo::operator"" _Bar(char32_t)  // { dg-error "must be a non-member function" }
+{ return 42; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C	(revision 0)
@@ -0,0 +1,38 @@
+// { dg-options -std=c++0x }
+
+#include <cstddef>
+
+class Foo { };
+
+Foo
+operator"" _Foo(int *);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(unsigned long int);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(double);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const float *, std::size_t);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const wchar_t *, int);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const char16_t *);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(char...);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(unsigned long long int, char);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const char *, std::size_t, int);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(long double &);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(std::size_t, const char16_t *);	// { dg-error "has invalid argument list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C	(revision 0)
@@ -0,0 +1,17 @@
+// { dg-options "-std=c++98" }
+
+#include <cstddef>
+
+int
+operator"" _mm(long double m)	// { dg-warning "user-defined literals only available with" }
+{ return int(1000.0L * m); }
+
+int in = 0.0254_mm;	// { dg-error "invalid suffix" }
+
+int
+operator"" _Q(const char *, std::size_t)	// { dg-warning "user-defined literals only available with" }
+{ return 42; }
+
+int x = "Hello"_Q;	// { dg-error "invalid conversion from" }
+
+// { dg-error "expected" "" { target *-*-* } 15 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+#include <string>
+
+std::string operator"" 5X(const char*, std::size_t);	// { dg-error "expected suffix identifier" }
+
+// { dg-error "expected type-specifier before string constant" "" { target *-*-* } 5 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+constexpr unsigned long long
+operator"" _grow(unsigned long long n)
+{ return 2 * n; }
+
+double buffer[25_grow];
Index: gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C	(revision 0)
@@ -0,0 +1,49 @@
+// { dg-options -std=c++0x }
+
+//  Test that the standard suffixes shadow any user-defined suffixes of the same name.
+long double
+operator"" L(long double x)	// { dg-warning "floating point suffix shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ULL(unsigned long long int k)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return k; }
+
+long double
+operator"" l(long double x)	// { dg-warning "floating point suffix shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ull(unsigned long long int k)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return k; }
+
+//  Namespaces are no hiding place.
+namespace Long
+{
+
+long double
+operator"" L(long double x)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ULL(unsigned long long int k)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return k; }
+
+long double
+operator"" l(long double x)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ull(unsigned long long int k)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return k; }
+
+}
+
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 5 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 9 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 13 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 17 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 25 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 29 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 33 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 37 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test warning on declaration without leading underscore.
+
+long double operator"" nounder(long double); // { dg-warning "suffixes not preceded by|are reserved for future standardization" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options -std=c++0x }
+
+class Foo { };
+
+template<wchar_t...>
+  Foo operator"" _Foo(); // { dg-error "user-defined literal operator template|has invalid parameter list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-general.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-general.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-general.C	(revision 0)
@@ -0,0 +1,52 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test simple operator declaration and definition.
+
+#include <cstring>
+#include <string>
+#include <complex>
+#include <cassert>
+
+long double operator"" _v(long double);
+std::string operator"" _w(const char16_t*, size_t);
+unsigned operator"" _w(const char*);
+
+std::complex<double>
+operator"" _i(long double y)
+{ return std::complex<double>(0.0L, y); }
+
+void
+test1()
+{
+  long double x = operator"" _v(1.2L);
+  assert(x == 2.2L);
+
+  std::string s = operator"" _w(u"one", 3);
+  assert(s == "boo");
+
+  unsigned u = operator"" _w("Hello, World!");
+  assert(u == 13U);
+
+  std::complex<double> i = operator"" _i(2.0);
+  assert(i == std::complex<double>(0.0, 2.0));
+}
+
+int
+main()
+{
+  test1();
+}
+
+long double
+operator"" _v(long double x)
+{ return x + 1.0L; }
+
+std::string
+operator"" _w(const char16_t*, size_t)
+{ return std::string("boo"); }
+
+unsigned
+operator"" _w(const char* str)
+{ return strlen(str); }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C	(revision 0)
@@ -0,0 +1,3 @@
+// { dg-options -std=c++0x }
+
+#include "udlit_system_header"
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test error on non-function declaration.
+
+double operator"" _baddecl; // { dg-error "as non-function" }
+
+template<char...>
+  int operator"" _badtmpldecl; // { dg-error "as non-function" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C	(revision 0)
@@ -0,0 +1,15 @@
+// { dg-options -std=c++0x }
+
+#include <string>
+
+std::string operator"" _i18n(const char*, std::size_t);
+
+std::string vogon_poem = R"V0G0N(
+                O freddled gruntbuggly thy micturations are to me
+                    As plured gabbleblochits on a lurgid bee.
+                 Groop, I implore thee my foonting turlingdromes.   
+              And hooptiously drangle me with crinkly bindlewurdles,
+  Or I will rend thee in the gobberwarts with my blurlecruncheon, see if I don't.
+
+                    (by Prostetnic Vogon Jeltz; see p. 56/57)
+)V0G0N"_i18n;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-addr.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-addr.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-addr.C	(revision 0)
@@ -0,0 +1,10 @@
+// { dg-options "-std=c++0x" }
+
+#include <cstddef>
+
+bool operator"" _yn(const char*, size_t);
+
+typedef bool (*pfunk)(const char*, size_t);
+pfunk p = &operator"" _yn;
+
+bool tf = p("Hello,\0 World!", 14);
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C	(revision 0)
@@ -0,0 +1,4 @@
+// { dg-options -std=c++0x }
+
+template<char...>
+  int operator"" _abc();
Index: gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C	(revision 0)
@@ -0,0 +1,8 @@
+// { dg-options -std=c++0x }
+
+extern "C" {
+
+int
+operator"" _badclinkage(unsigned long long);	// { dg-error "operator with C linkage" }
+
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-template.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-template.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-template.C	(revision 0)
@@ -0,0 +1,51 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test template operator declaration and definition.
+
+#include <cassert>
+
+template<char...>
+  int operator"" _abc();
+
+template<>
+  int
+  operator"" _abc<>()
+  { return -1; }
+
+template<>
+  int
+  operator"" _abc<'L','U','E'>()
+  { return 42; }
+
+template<>
+  int
+  operator"" _abc<'6','6','6'>()
+  { return 21; }
+
+int
+test1()
+{
+  int i = operator"" _abc<'1','2','3'>();
+  assert(i == 45);
+  int universal_meaning = operator"" _abc<'L','U','E'>();
+  assert(universal_meaning == 42);
+  int b = operator"" _abc<'6','6','6'>();
+  int z = operator"" _abc<>();
+  assert(z == -1);
+  int j = 123_abc;
+  assert(j == i);
+  int jb = 666_abc;
+  assert(jb == b);
+}
+
+int
+main()
+{
+  test1();
+}
+
+template<char... Chars>
+  int operator"" _abc()
+  { return 42 + sizeof...(Chars); }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-args.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-args.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-args.C	(revision 0)
@@ -0,0 +1,38 @@
+// { dg-options -std=c++0x }
+
+#include <cstddef>
+
+class Foo { };
+
+Foo
+operator"" _Foo(const char *);
+
+Foo
+operator"" _Foo(unsigned long long int);
+
+Foo
+operator"" _Foo(long double);
+
+Foo
+operator"" _Foo(char);
+
+Foo
+operator"" _Foo(wchar_t);
+
+Foo
+operator"" _Foo(char16_t);
+
+Foo
+operator"" _Foo(char32_t);
+
+Foo
+operator"" _Foo(const char *, std::size_t);
+
+Foo
+operator"" _Foo(const wchar_t *, std::size_t);
+
+Foo
+operator"" _Foo(const char16_t *, std::size_t);
+
+Foo
+operator"" _Foo(const char32_t *, std::size_t);
Index: gcc/testsuite/g++.dg/cpp0x/udlit-declare-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-declare-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-declare-neg.C	(revision 0)
@@ -0,0 +1,15 @@
+// { dg-options "-std=c++0x" }
+
+//  Check that undeclared literal operator calls and literals give appropriate errors.
+
+int i = operator"" _Bar('x');  // { dg-error "was not declared in this scope" }
+int j = 'x'_Bar;  // { dg-error "unable to find user-defined character literal operator" }
+
+int ii = operator"" _BarCharStr("Howdy, Pardner!");  // { dg-error "was not declared in this scope" }
+int jj = "Howdy, Pardner!"_BarCharStr;  // { dg-error "unable to find user-defined string literal operator" }
+
+unsigned long long iULL = operator"" _BarULL(666ULL);  // { dg-error "was not declared in this scope" }
+unsigned long long jULL = 666_BarULL;  // { dg-error "unable to find user-defined numeric literal operator" }
+
+long double iLD = operator"" _BarLD(666.0L);  // { dg-error "was not declared in this scope" }
+long double jLD = 666.0_BarLD;  // { dg-error "unable to find user-defined numeric literal operator" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+char32_t
+operator"" (char32_t C)	// { dg-error "expected suffix identifier" }
+{ return C; }
+
+// { dg-error "expected type-specifier before string constant" "" { target *-*-* } 4 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test error on non-empty string after 'operator' keyword.
+
+double operator"hi" _badword(long double); // { dg-error "expected empty string after" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-inline.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-inline.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-inline.C	(revision 0)
@@ -0,0 +1,22 @@
+// { dg-options "-std=c++0x" }
+
+//  Literal operators can be inline.
+
+inline int
+operator"" _thing1(char cc)
+{ return 42 * cc; }
+
+int operator"" _thing2(char cc);
+
+class Foo
+{
+  int
+  friend operator"" _thing2(char cc)
+  { return 42 * cc; }
+};
+
+int i = operator"" _thing1('x');
+int j = 'x'_thing1;
+
+int iF = operator"" _thing2('x');
+int jF = 'x'_thing2;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+extern "C"_badlinkage {	// { dg-error "expected unqualified-id before" }
+
+int foo();
+
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-friend.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-friend.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-friend.C	(revision 0)
@@ -0,0 +1,28 @@
+// { dg-options -std=c++0x }
+
+long double
+operator"" _Hertz(long double);
+
+class Foo
+{
+public:
+  Foo() { }
+
+  friend Foo operator"" _Bar(char);
+
+  friend long double
+  operator"" _Hertz(long double omega)
+  { return omega / 6.28318530717958648; }
+};
+
+Foo
+operator"" _Bar(char)
+{ return Foo(); }
+
+Foo f1 = operator"" _Bar('x');
+
+Foo f2 = 'x'_Bar;
+
+long double fm1 = operator"" _Hertz(552.92L);
+
+long double fm2 = 552.92_Hertz;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+#include <string>
+
+std::string operator"" _xxx(const char*, size_t);
+
+std::string operator"" _yyy(const char*, size_t);
+
+std::string concat = "Hello, "_xxx "World!"_yyy;	// { dg-error "inconsistent user-defined literal suffixes" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options -std=c++0x }
+
+class Foo { };
+
+template<char...>
+  Foo operator"" _Foo();
Index: gcc/testsuite/g++.dg/cpp0x/udlit-concat.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-concat.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-concat.C	(revision 0)
@@ -0,0 +1,24 @@
+// { dg-options "-std=c++0x" }
+
+#include <string>
+
+std::string operator"" _www(const char*, size_t);
+
+std::string concat01 = "Hello, " "World!"_www;
+
+std::string concat10 = "Hello, "_www "World!";
+
+std::string concat11 = "Hello, "_www "World!"_www;
+
+
+class Tachyon { };
+
+Tachyon operator"" _fast(const char*, size_t);
+
+int operator"" _fast(const char32_t*, size_t);
+
+int speedy01 = "Hello, " U"World!"_fast;
+
+int speedy10 = "Hello, "_fast U"World!";
+
+int speedy11 = "Hello, "_fast U"World!"_fast;
Index: gcc/cp/typeck.c
===================================================================
--- gcc/cp/typeck.c	(revision 179328)
+++ gcc/cp/typeck.c	(working copy)
@@ -8334,3 +8334,94 @@
   return 1;
 }
 
+
+/* Return true if a user-defined literal operator has one of the allowed
+   argument types.  */
+
+bool
+check_literal_operator_args (const_tree decl,
+			     bool *long_long_unsigned_p, bool *long_double_p)
+{
+  tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
+  if (processing_template_decl)
+    return (argtypes == NULL_TREE
+	    || same_type_p (TREE_VALUE (argtypes), void_type_node));
+  else
+    {
+      tree argtype;
+      int arity;
+      int max_arity = 2;
+      bool found_string_p = false;
+      bool maybe_raw_p = false;
+      bool found_size_p = false;
+      tree const_char_ptr_type_node
+	   = build_pointer_type(build_type_variant(char_type_node, 1, 0));
+      tree const_wchar_ptr_type_node
+	   = build_pointer_type(build_type_variant(wchar_type_node, 1, 0));
+      tree const_char16_ptr_type_node
+	   = build_pointer_type(build_type_variant(char16_type_node, 1, 0));
+      tree const_char32_ptr_type_node
+	   = build_pointer_type(build_type_variant(char32_type_node, 1, 0));
+
+      *long_long_unsigned_p = false;
+      *long_double_p = false;
+
+      /* Count the number and type of arguments and check for ellipsis.  */
+      for (argtype = argtypes, arity = 0;
+	   argtype && argtype != void_list_node;
+	   argtype = TREE_CHAIN (argtype))
+	{
+	  tree t = TREE_VALUE (argtype);
+	  ++arity;
+
+	  if (same_type_p (t, const_char_ptr_type_node))
+	    {
+	      found_string_p = true;
+	      maybe_raw_p = true;
+	    }
+	  else if (same_type_p (t, const_wchar_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, const_char16_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, const_char32_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, size_type_node))
+	    {
+	      if (!found_string_p)
+		return false;
+	      found_size_p = true;
+	    }
+	  else if (same_type_p (t, long_long_unsigned_type_node))
+	    {
+	      max_arity = 1;
+	      *long_long_unsigned_p = true;
+	    }
+	  else if (same_type_p (t, long_double_type_node))
+	    {
+	      max_arity = 1;
+	      *long_double_p = true;
+	    }
+	  else if (same_type_p (t, char_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, wchar_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, char16_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, char32_type_node))
+	    max_arity = 1;
+	  else
+	    return false;
+	}
+      if (!argtype)
+	return false; /* Found ellipsis.  */
+
+      if (arity > max_arity)
+	return false;
+
+      if (found_string_p && !maybe_raw_p && !found_size_p)
+	return false;
+
+      return true;
+    }
+}
+
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 179328)
+++ gcc/cp/decl.c	(working copy)
@@ -1203,6 +1203,21 @@
       || TREE_TYPE (olddecl) == error_mark_node)
     return error_mark_node;
 
+  if (UDLIT_OPER_P (DECL_NAME (newdecl))
+      && UDLIT_OPER_P (DECL_NAME (olddecl)))
+    {
+      if (TREE_CODE (newdecl) == TEMPLATE_DECL
+	  && TREE_CODE (olddecl) != TEMPLATE_DECL)
+	error ("user-defined literal operator template %q+D"
+	       " conflicts with user-defined raw literal operator %qD",
+	       newdecl, olddecl);
+      else if (TREE_CODE (newdecl) != TEMPLATE_DECL
+	       && TREE_CODE (olddecl) == TEMPLATE_DECL)
+	error ("user-defined raw literal operator %q+D"
+	       " conflicts with user-defined literal operator template %qD",
+	       newdecl, olddecl);
+    }
+
   if (DECL_P (olddecl)
       && TREE_CODE (newdecl) == FUNCTION_DECL
       && TREE_CODE (olddecl) == FUNCTION_DECL
@@ -7333,7 +7348,48 @@
   if (IDENTIFIER_OPNAME_P (DECL_NAME (decl))
       && !grok_op_properties (decl, /*complain=*/true))
     return NULL_TREE;
+  else if (UDLIT_OPER_P (DECL_NAME (decl)))
+    {
+      bool long_long_unsigned_p;
+      bool long_double_p;
+      const char *suffix = NULL;
+      /* [over.literal]/6: Literal operators shall not have C linkage. */
+      if (DECL_LANGUAGE(decl) == lang_c)
+	{
+	  error ("literal operator with C linkage");
+	  return NULL_TREE;
+	}
 
+      if (DECL_NAMESPACE_SCOPE_P (decl))
+	{
+	  if (!check_literal_operator_args(decl,
+					   &long_long_unsigned_p, &long_double_p))
+	    {
+	      error ("%qD has invalid argument list", decl);
+	      return NULL_TREE;
+	    }
+
+	  suffix = UDLIT_OP_SUFFIX (DECL_NAME (decl));
+	  if (long_long_unsigned_p)
+	    {
+	      if (cpp_interpret_int_suffix (suffix, strlen (suffix)))
+		warning (0, "integer suffix %<%s%>"
+			    " shadowed by implementation", suffix);
+	    }
+	  else if (long_double_p)
+	    {
+	      if (cpp_interpret_float_suffix (suffix, strlen (suffix)))
+		warning (0, "floating point suffix %<%s%>"
+			    " shadowed by implementation", suffix);
+	    }
+	}
+      else
+	{
+	  error ("%qD must be a non-member function", decl);
+	  return NULL_TREE;
+	}
+    }
+
   if (funcdef_flag)
     /* Make the init_value nonzero so pushdecl knows this is not
        tentative.  error_mark_node is replaced later with the BLOCK.  */
@@ -8518,6 +8574,15 @@
       error ("declaration of %qD as non-function", dname);
       return error_mark_node;
     }
+ 
+  if (dname
+      && TREE_CODE (dname) == IDENTIFIER_NODE
+      && UDLIT_OPER_P (dname)
+      && innermost_code != cdk_function)
+    {
+      error ("declaration of %qD as non-function", dname);
+      return error_mark_node;
+    }
 
   if (dname && IDENTIFIER_OPNAME_P (dname))
     {
@@ -13734,6 +13799,7 @@
     case TRAIT_EXPR:		return TS_CP_TRAIT_EXPR;
     case LAMBDA_EXPR:		return TS_CP_LAMBDA_EXPR;
     case TEMPLATE_INFO:		return TS_CP_TEMPLATE_INFO;
+    case USERDEF_LITERAL:	return TS_CP_USERDEF_LITERAL;
     default:			return TS_CP_GENERIC;
     }
 }
Index: gcc/cp/error.c
===================================================================
--- gcc/cp/error.c	(revision 179328)
+++ gcc/cp/error.c	(working copy)
@@ -1534,6 +1534,8 @@
     }
   else if (name && IDENTIFIER_OPNAME_P (name))
     pp_cxx_tree_identifier (cxx_pp, name);
+  else if (name && UDLIT_OPER_P (name))
+    pp_cxx_tree_identifier (cxx_pp, name);
   else
     dump_decl (name, flags);
 
@@ -1756,6 +1758,10 @@
       pp_constant (cxx_pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (cxx_pp, t);
+      break;
+
     case THROW_EXPR:
       /* While waiting for caret diagnostics, avoid printing
 	 __cxa_allocate_exception, __cxa_throw, and the like.  */
@@ -3231,7 +3237,7 @@
 	pedwarn (input_location, OPT_pedantic,
 		 "inline namespaces "
 		 "only available with -std=c++0x or -std=gnu++0x");
-	break;	
+	break;
       case CPP0X_OVERRIDE_CONTROLS:
 	pedwarn (input_location, 0,
 		 "override controls (override/final) "
@@ -3242,8 +3248,13 @@
 		 "non-static data member initializers "
 		 "only available with -std=c++0x or -std=gnu++0x");
         break;
+      case CPP0X_USER_DEFINED_LITERALS:
+	pedwarn (input_location, 0,
+		 "user-defined literals "
+		 "only available with -std=c++0x or -std=gnu++0x");
+	break;
       default:
-	gcc_unreachable();
+	gcc_unreachable ();
       }
 }
 
Index: gcc/cp/cxx-pretty-print.c
===================================================================
--- gcc/cp/cxx-pretty-print.c	(revision 179328)
+++ gcc/cp/cxx-pretty-print.c	(working copy)
@@ -367,6 +367,17 @@
     pp_cxx_unqualified_id (pp, t);
 }
 
+/* user-defined literal:
+      literal ud-suffix  */
+
+void
+pp_cxx_userdef_literal (cxx_pretty_printer *pp, tree t)
+{
+  pp_cxx_constant (pp, USERDEF_LITERAL_VALUE (t));
+  pp_cxx_id_expression (pp, USERDEF_LITERAL_SUFFIX_ID (t));
+}
+
+
 /* primary-expression:
      literal
      this
@@ -413,6 +424,10 @@
       pp_cxx_constant (pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (pp, t);
+      break;
+
     case BASELINK:
       t = BASELINK_FUNCTIONS (t);
     case VAR_DECL:
@@ -1023,6 +1038,10 @@
       pp_cxx_constant (pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (pp, t);
+      break;
+
     case RESULT_DECL:
       pp_cxx_unqualified_id (pp, t);
       break;
Index: gcc/cp/semantics.c
===================================================================
--- gcc/cp/semantics.c	(revision 179328)
+++ gcc/cp/semantics.c	(working copy)
@@ -7748,6 +7748,7 @@
     case TEMPLATE_PARM_INDEX:
     case TRAIT_EXPR:
     case IDENTIFIER_NODE:
+    case USERDEF_LITERAL:
       /* We can see a FIELD_DECL in a pointer-to-member expression.  */
     case FIELD_DECL:
     case PARM_DECL:
Index: gcc/cp/cxx-pretty-print.h
===================================================================
--- gcc/cp/cxx-pretty-print.h	(revision 179328)
+++ gcc/cp/cxx-pretty-print.h	(working copy)
@@ -74,5 +74,7 @@
 void pp_cxx_trait_expression (cxx_pretty_printer *, tree);
 void pp_cxx_va_arg_expression (cxx_pretty_printer *, tree);
 void pp_cxx_offsetof_expression (cxx_pretty_printer *, tree);
+void pp_cxx_userdef_literal (cxx_pretty_printer *, tree);
 
+
 #endif /* GCC_CXX_PRETTY_PRINT_H */
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 179328)
+++ gcc/cp/parser.c	(working copy)
@@ -210,6 +210,8 @@
   (cp_lexer *);
 static void cp_lexer_rollback_tokens
   (cp_lexer *);
+static tree cp_literal_operator_id
+  (const char *);
 #ifdef ENABLE_CHECKING
 static void cp_lexer_print_token
   (FILE *, cp_token *);
@@ -501,20 +503,20 @@
 	}
       else
 	{
-          if (warn_cxx0x_compat
-              && C_RID_CODE (token->u.value) >= RID_FIRST_CXX0X
-              && C_RID_CODE (token->u.value) <= RID_LAST_CXX0X)
-            {
-              /* Warn about the C++0x keyword (but still treat it as
-                 an identifier).  */
-              warning (OPT_Wc__0x_compat, 
-                       "identifier %qE will become a keyword in C++0x",
-                       token->u.value);
+	  if (warn_cxx0x_compat
+	      && C_RID_CODE (token->u.value) >= RID_FIRST_CXX0X
+	      && C_RID_CODE (token->u.value) <= RID_LAST_CXX0X)
+	    {
+	      /* Warn about the C++0x keyword (but still treat it as
+		 an identifier).  */
+	      warning (OPT_Wc__0x_compat, 
+		       "identifier %qE will become a keyword in C++0x",
+		       token->u.value);
 
-              /* Clear out the C_RID_CODE so we don't warn about this
-                 particular identifier-turned-keyword again.  */
-              C_SET_RID_CODE (token->u.value, RID_MAX);
-            }
+	      /* Clear out the C_RID_CODE so we don't warn about this
+		 particular identifier-turned-keyword again.  */
+	      C_SET_RID_CODE (token->u.value, RID_MAX);
+	    }
 
 	  token->ambiguous_p = false;
 	  token->keyword = RID_MAX;
@@ -1531,6 +1533,12 @@
   (cp_parser *);
 static tree cp_parser_string_literal
   (cp_parser *, bool, bool);
+static tree cp_parser_userdef_char_literal
+  (cp_parser *);
+static tree cp_parser_userdef_string_literal
+  (cp_token *);
+static tree cp_parser_userdef_numeric_literal
+  (cp_parser *);
 
 /* Basic concepts [gram.basic]  */
 
@@ -2039,6 +2047,8 @@
   (cp_parser *);
 static bool cp_parser_allow_gnu_extensions_p
   (cp_parser *);
+static bool cp_parser_is_pure_string_literal
+  (cp_token *);
 static bool cp_parser_is_string_literal
   (cp_token *);
 static bool cp_parser_is_keyword
@@ -2059,7 +2069,7 @@
 /* Returns nonzero if TOKEN is a string literal.  */
 
 static bool
-cp_parser_is_string_literal (cp_token* token)
+cp_parser_is_pure_string_literal (cp_token* token)
 {
   return (token->type == CPP_STRING ||
 	  token->type == CPP_STRING16 ||
@@ -2068,6 +2078,20 @@
 	  token->type == CPP_UTF8STRING);
 }
 
+/* Returns nonzero if TOKEN is a string literal
+   of a user-defined string literal.  */
+
+static bool
+cp_parser_is_string_literal (cp_token* token)
+{
+  return (cp_parser_is_pure_string_literal (token) ||
+	  token->type == CPP_STRING_USERDEF ||
+	  token->type == CPP_STRING16_USERDEF ||
+	  token->type == CPP_STRING32_USERDEF ||
+	  token->type == CPP_WSTRING_USERDEF ||
+	  token->type == CPP_UTF8STRING_USERDEF);
+}
+
 /* Returns nonzero if TOKEN is the indicated KEYWORD.  */
 
 static bool
@@ -3107,7 +3131,11 @@
   struct obstack str_ob;
   cpp_string str, istr, *strs;
   cp_token *tok;
-  enum cpp_ttype type;
+  enum cpp_ttype type, curr_type;
+  int have_suffix_p = 0;
+  tree string_tree;
+  tree suffix_id = NULL_TREE;
+  bool curr_tok_is_userdef_p = false;
 
   tok = cp_lexer_peek_token (parser->lexer);
   if (!cp_parser_is_string_literal (tok))
@@ -3116,7 +3144,18 @@
       return error_mark_node;
     }
 
-  type = tok->type;
+  if (cpp_userdef_string_p (tok->type))
+    {
+      string_tree = USERDEF_LITERAL_VALUE (tok->u.value);
+      curr_type = cpp_userdef_string_remove_type (tok->type);
+      curr_tok_is_userdef_p = true;
+    }
+  else
+    {
+      string_tree = tok->u.value;
+      curr_type = tok->type;
+    }
+  type = curr_type;
 
   /* Try to avoid the overhead of creating and destroying an obstack
      for the common case of just one string.  */
@@ -3125,10 +3164,19 @@
     {
       cp_lexer_consume_token (parser->lexer);
 
-      str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value);
-      str.len = TREE_STRING_LENGTH (tok->u.value);
+      str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree);
+      str.len = TREE_STRING_LENGTH (string_tree);
       count = 1;
 
+      if (curr_tok_is_userdef_p)
+	{
+	  suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value);
+	  have_suffix_p = 1;
+	  curr_type = cpp_userdef_string_remove_type (tok->type);
+	}
+      else
+	curr_type = tok->type;
+
       strs = &str;
     }
   else
@@ -3140,14 +3188,35 @@
 	{
 	  cp_lexer_consume_token (parser->lexer);
 	  count++;
-	  str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value);
-	  str.len = TREE_STRING_LENGTH (tok->u.value);
+	  str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree);
+	  str.len = TREE_STRING_LENGTH (string_tree);
 
-	  if (type != tok->type)
+	  if (curr_tok_is_userdef_p)
 	    {
+	      tree curr_suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value);
+	      if (have_suffix_p == 0)
+		{
+		  suffix_id = curr_suffix_id;
+		  have_suffix_p = 1;
+		}
+	      else if (have_suffix_p == 1
+		       && curr_suffix_id != suffix_id)
+		{
+		  error ("inconsistent user-defined literal suffixes"
+			 " %qD and %qD in string literal",
+			 suffix_id, curr_suffix_id);
+		  have_suffix_p = -1;
+		}
+	      curr_type = cpp_userdef_string_remove_type (tok->type);
+	    }
+	  else
+	    curr_type = tok->type;
+
+	  if (type != curr_type)
+	    {
 	      if (type == CPP_STRING)
-		type = tok->type;
-	      else if (tok->type != CPP_STRING)
+		type = curr_type;
+	      else if (curr_type != CPP_STRING)
 		error_at (tok->location,
 			  "unsupported non-standard concatenation "
 			  "of string literals");
@@ -3156,6 +3225,18 @@
 	  obstack_grow (&str_ob, &str, sizeof (cpp_string));
 
 	  tok = cp_lexer_peek_token (parser->lexer);
+	  if (cpp_userdef_string_p (tok->type))
+	    {
+	      string_tree = USERDEF_LITERAL_VALUE (tok->u.value);
+	      curr_type = cpp_userdef_string_remove_type (tok->type);
+	      curr_tok_is_userdef_p = true;
+	    }
+	  else
+	    {
+	      string_tree = tok->u.value;
+	      curr_type = tok->type;
+	      curr_tok_is_userdef_p = false;
+	    }
 	}
       while (cp_parser_is_string_literal (tok));
 
@@ -3193,6 +3274,13 @@
 	}
 
       value = fix_string_type (value);
+
+      if (have_suffix_p)
+	{
+	  tree literal = build_userdef_literal (suffix_id, value, NULL_TREE);
+	  tok->u.value = literal;
+	  return cp_parser_userdef_string_literal (tok);
+	}
     }
   else
     /* cpp_interpret_string has issued an error.  */
@@ -3204,7 +3292,184 @@
   return value;
 }
 
+/* Parse a user-defined char constant.  Returns a call to a user-defined
+   literal operator taking the character as an argument.  */
 
+static tree
+cp_parser_userdef_char_literal (cp_parser *parser)
+{
+  cp_token *token = NULL;
+  tree literal, suffix_id, value;
+  tree name, decl;
+  tree result;
+  VEC(tree,gc) *vec;
+
+  token = cp_lexer_consume_token (parser->lexer);
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  value = USERDEF_LITERAL_VALUE (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  vec = make_tree_vector ();
+  VEC_safe_push (tree, gc, vec, value);
+  decl = lookup_function_nonclass (name, vec, /*block_p=*/false);
+  if (!decl || decl == error_mark_node)
+    {
+      error ("unable to find user-defined character literal operator %qD",
+	     name);
+      release_tree_vector (vec);
+      return error_mark_node;
+    }
+  result = finish_call_expr (decl, &vec, false, true, tf_warning_or_error);
+  release_tree_vector (vec);
+
+  return result;
+}
+
+/* A subroutine of cp_parser_userdef_numeric_literal to
+   create a char... template parameter pack from a string node.  */
+
+static tree
+make_char_string_pack (tree value)
+{
+  tree parmvec;
+  tree argpack = make_node (NONTYPE_ARGUMENT_PACK);
+  const char *str = TREE_STRING_POINTER (value);
+  int i, len = TREE_STRING_LENGTH (value);
+  /*  Do I need to stuff THIS into a tree? */
+  tree argvec = make_tree_vec (1);
+
+  /* Fill in PARMVEC with all of the parameters.  */
+  parmvec = make_tree_vec (len);
+  for (i = 0; i < len; ++i)
+    TREE_VEC_ELT (parmvec, i) = build_int_cst (char_type_node, str[i]);
+
+  /* Build the argument packs.  */
+  SET_ARGUMENT_PACK_ARGS (argpack, parmvec);
+  TREE_TYPE (argpack) = char_type_node;
+
+  /*  Do I need to stuff THIS into a tree? */
+  TREE_VEC_ELT (argvec, 0) = argpack;
+
+  return argvec;
+}
+
+/* Parse a user-defined numeric constant.  returns a call to a user-defined
+   literal operator.  */
+static tree
+cp_parser_userdef_numeric_literal (cp_parser *parser)
+{
+  cp_token *token = NULL;
+  tree literal, suffix_id, value, num_string;
+  tree name, decl;
+  tree result = error_mark_node;
+  VEC(tree,gc) *args;
+
+  token = cp_lexer_consume_token (parser->lexer);
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  value = USERDEF_LITERAL_VALUE (literal);
+  num_string = USERDEF_LITERAL_NUM_STRING (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  /* Try to find the literal operator by finishing the call expression
+     with the numeric argument.  */
+  args = make_tree_vector ();
+  VEC_safe_push (tree, gc, args, value);
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl && decl != error_mark_node)
+    {
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  /* If the numeric argument didn't work, look for a raw literal
+     operator taking a const char* argument consisting of the number
+     in string format.  */
+  args = make_tree_vector ();
+  VEC_safe_push (tree, gc, args, num_string);
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl && decl != error_mark_node)
+    {
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  /* If the raw literal didn't work, look for a non-type template
+     function with parameter pack char....  Call the function with
+     template parameter characters representing the number.  */
+  args = make_tree_vector ();
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl && decl != error_mark_node)
+    {
+      tree tmpl_args = make_char_string_pack (num_string);
+      decl = lookup_template_function (decl, tmpl_args);
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  if (result == error_mark_node)
+    error ("unable to find user-defined numeric literal operator %qD", name);
+
+  return result;
+}
+
+/* Parse a user-defined string constant.  Returns a call to a user-defined
+   literal operator taking a character pointer and the length of the string
+   as arguments.  */
+static tree
+cp_parser_userdef_string_literal (cp_token *token)
+{
+  tree literal, suffix_id, value;
+  tree name, decl;
+  tree result;
+  VEC(tree,gc) *vec;
+  int len;
+
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+  value = USERDEF_LITERAL_VALUE (literal);
+  len = TREE_STRING_LENGTH (value) - 1;
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  vec = make_tree_vector ();
+  VEC_safe_push (tree, gc, vec, value);
+  VEC_safe_push (tree, gc, vec, build_int_cst (size_type_node, len));
+  decl = lookup_function_nonclass (name, vec, /*block_p=*/false);
+  if (!decl || decl == error_mark_node)
+    {
+      error ("unable to find user-defined string literal operator %qD", name);
+      release_tree_vector (vec);
+      return error_mark_node;
+    }
+  result = finish_call_expr (decl, &vec, false, true, tf_warning_or_error);
+  release_tree_vector (vec);
+
+  return result;
+}
+
+
 /* Basic concepts [gram.basic]  */
 
 /* Parse a translation-unit.
@@ -3347,12 +3612,16 @@
 	   character-literal
 	   floating-literal
 	   string-literal
-	   boolean-literal  */
+	   boolean-literal
+	   pointer-literal
+	   user-defined-literal  */
     case CPP_CHAR:
     case CPP_CHAR16:
     case CPP_CHAR32:
     case CPP_WCHAR:
     case CPP_NUMBER:
+      if (TREE_CODE (token->u.value) == USERDEF_LITERAL)
+	return cp_parser_userdef_numeric_literal (parser);
       token = cp_lexer_consume_token (parser->lexer);
       if (TREE_CODE (token->u.value) == FIXED_CST)
 	{
@@ -3406,11 +3675,22 @@
 	}
       return token->u.value;
 
+    case CPP_CHAR_USERDEF:
+    case CPP_CHAR16_USERDEF:
+    case CPP_CHAR32_USERDEF:
+    case CPP_WCHAR_USERDEF:
+      return cp_parser_userdef_char_literal (parser);
+
     case CPP_STRING:
     case CPP_STRING16:
     case CPP_STRING32:
     case CPP_WSTRING:
     case CPP_UTF8STRING:
+    case CPP_STRING_USERDEF:
+    case CPP_STRING16_USERDEF:
+    case CPP_STRING32_USERDEF:
+    case CPP_WSTRING_USERDEF:
+    case CPP_UTF8STRING_USERDEF:
       /* ??? Should wide strings be allowed when parser->translate_strings_p
 	 is false (i.e. in attributes)?  If not, we can kill the third
 	 argument to cp_parser_string_literal.  */
@@ -4888,7 +5168,7 @@
 	/* Restore the saved message.  */
 	parser->type_definition_forbidden_message = saved_message;
 	/* `typeid' may not appear in an integral constant expression.  */
-	if (cp_parser_non_integral_constant_expression(parser, NIC_TYPEID))
+	if (cp_parser_non_integral_constant_expression (parser, NIC_TYPEID))
 	  return error_mark_node;
       }
       break;
@@ -9471,7 +9751,7 @@
   /* If the next token is `extern' and the following token is a string
      literal, then we have a linkage specification.  */
   if (token1.keyword == RID_EXTERN
-      && cp_parser_is_string_literal (&token2))
+      && cp_parser_is_pure_string_literal (&token2))
     cp_parser_linkage_specification (parser);
   /* If the next token is `template', then we have either a template
      declaration, an explicit instantiation, or an explicit
@@ -10902,6 +11182,22 @@
   return cp_parser_operator (parser);
 }
 
+/* Return an identifier node for a user-defined literal operator.
+   The suffix identifier is chained to the operator name identifier.  */
+
+static tree
+cp_literal_operator_id (const char* name)
+{
+  tree identifier;
+  char *buffer = XNEWVEC (char, strlen (UDLIT_OP_ANSI_PREFIX)
+			      + strlen (name) + 10);
+  sprintf (buffer, UDLIT_OP_ANSI_FORMAT, name);
+  identifier = get_identifier (buffer);
+  /*IDENTIFIER_UDLIT_OPNAME_P (identifier) = 1; If we get a flag someday. */
+
+  return identifier;
+}
+
 /* Parse an operator.
 
    operator:
@@ -11121,6 +11417,35 @@
       cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE);
       return ansi_opname (ARRAY_REF);
 
+    case CPP_STRING:
+      if (cxx_dialect == cxx98)
+	maybe_warn_cpp0x (CPP0X_USER_DEFINED_LITERALS);
+      if (TREE_STRING_LENGTH (token->u.value) > 2)
+	{
+	  error ("expected empty string after %<operator%> keyword");
+	  return error_mark_node;
+	}
+      /* Consume the string.  */
+      cp_lexer_consume_token (parser->lexer);
+      /* Look for an identifier.  */
+      id = cp_parser_identifier (parser);
+      if (id != error_mark_node)
+	{
+	  const char *name = IDENTIFIER_POINTER (id);
+
+	  /* 17.6.3.3.5  */
+	  if (name[0] != '_' && !in_system_header)
+	    warning (0, "suffixes not preceded by %<_%> "
+			"are reserved for future standardization");
+
+	  return cp_literal_operator_id(name);
+	}
+      else
+	{
+	  error ("expected suffix identifier");
+	  return error_mark_node;
+	}
+
     default:
       /* Anything else is an error.  */
       break;
@@ -20304,6 +20629,32 @@
   /* Finish up.  */
   finish_template_decl (parameter_list);
 
+  /* Check the template arguments for a user-defined literal operator template.  */
+  if (decl
+      && (TREE_CODE (decl) == FUNCTION_DECL || DECL_FUNCTION_TEMPLATE_P (decl))
+      && UDLIT_OPER_P (DECL_NAME (decl)))
+    {
+      bool ok = true;
+      if (parameter_list == NULL_TREE)
+	ok = false;
+      else
+	{
+	  int num_parms = TREE_VEC_LENGTH (parameter_list);
+	  if (num_parms != 1)
+	    ok = false;
+	  else
+	    {
+	      tree parm_list = TREE_VEC_ELT (parameter_list, 0);
+	      tree parm = INNERMOST_TEMPLATE_PARMS (parm_list);
+	      if (TREE_TYPE (parm) != char_type_node
+		  || !TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (parm)))
+		ok = false;
+	    }
+	}
+      if (!ok)
+	error ("user-defined literal operator template %qD"
+	       " has invalid parameter list", decl);
+    }
   /* Register member declarations.  */
   if (member_p && !friend_p && decl && !DECL_CLASS_TEMPLATE_P (decl))
     finish_member_declaration (decl);
@@ -22605,7 +22956,8 @@
   /* If the next token is `extern' and the following token is a string
      literal, then we have a linkage specification.  */
   if (token->keyword == RID_EXTERN
-      && cp_parser_is_string_literal (cp_lexer_peek_nth_token (parser->lexer, 2)))
+      && cp_parser_is_pure_string_literal
+	 (cp_lexer_peek_nth_token (parser->lexer, 2)))
     cp_parser_linkage_specification (parser);
   /* Handle #pragma, if any.  */
   else if (token->type == CPP_PRAGMA)
Index: gcc/cp/cp-objcp-common.c
===================================================================
--- gcc/cp/cp-objcp-common.c	(revision 179328)
+++ gcc/cp/cp-objcp-common.c	(working copy)
@@ -100,6 +100,8 @@
 
     case TEMPLATE_INFO:         return sizeof (struct tree_template_info);
 
+    case USERDEF_LITERAL:	return sizeof (struct tree_userdef_literal);
+
     default:
       gcc_unreachable ();
     }
Index: gcc/cp/mangle.c
===================================================================
--- gcc/cp/mangle.c	(revision 179328)
+++ gcc/cp/mangle.c	(working copy)
@@ -181,6 +181,7 @@
 static void write_unqualified_name (const tree);
 static void write_conversion_operator_name (const tree);
 static void write_source_name (tree);
+static void write_literal_operator_name (tree);
 static void write_unnamed_type_name (const tree);
 static void write_closure_type_name (const tree);
 static int hwint_to_ascii (unsigned HOST_WIDE_INT, const unsigned int, char *,
@@ -1174,6 +1175,8 @@
 	  }
       write_string (mangled_name);
     }
+  else if (UDLIT_OPER_P (identifier))
+    write_literal_operator_name (identifier);
   else
     write_source_name (identifier);
 }
@@ -1227,6 +1230,8 @@
 
 	  write_string (oni[DECL_OVERLOADED_OPERATOR_P (decl)].mangled_name);
 	}
+      else if (UDLIT_OPER_P (DECL_NAME (decl)))
+	write_literal_operator_name (DECL_NAME (decl));
       else
 	found = false;
 
@@ -1286,6 +1291,21 @@
   write_identifier (IDENTIFIER_POINTER (identifier));
 }
 
+/* Write a user-defined literal operator.
+   IDENTIFIER is an LITERAL_IDENTIFIER_NODE.  */
+
+static void
+write_literal_operator_name (tree identifier)
+{
+  const char* suffix = UDLIT_OP_SUFFIX (identifier);
+  char* buffer = XNEWVEC (char, strlen (UDLIT_OP_MANGLED_PREFIX)
+			      + strlen (suffix) + 10);
+  sprintf (buffer, UDLIT_OP_MANGLED_FORMAT, suffix);
+
+  write_unsigned_number (strlen (buffer));
+  write_identifier (buffer);
+}
+
 /* Encode 0 as _, and 1+ as n-1_.  */
 
 static void
Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h	(revision 179328)
+++ gcc/cp/cp-tree.h	(working copy)
@@ -396,7 +396,9 @@
   /* override controls, override/final */
   CPP0X_OVERRIDE_CONTROLS,
   /* non-static data member initializers */
-  CPP0X_NSDMI
+  CPP0X_NSDMI,
+  /* user defined literals */
+  CPP0X_USER_DEFINED_LITERALS
 } cpp0x_warn_str;
   
 /* The various kinds of operation used by composite_pointer_type. */
@@ -727,6 +729,7 @@
   TS_CP_TRAIT_EXPR,
   TS_CP_LAMBDA_EXPR,
   TS_CP_TEMPLATE_INFO,
+  TS_CP_USERDEF_LITERAL,
   LAST_TS_CP_ENUM
 };
 
@@ -752,6 +755,8 @@
     lambda_expression;
   struct tree_template_info GTY ((tag ("TS_CP_TEMPLATE_INFO")))
     template_info;
+  struct tree_userdef_literal GTY ((tag ("TS_CP_USERDEF_LITERAL")))
+    userdef_literal;
 };
 
 \f
@@ -4204,6 +4209,17 @@
              LAMBDANAME_PREFIX, \
 	     sizeof (LAMBDANAME_PREFIX) - 1))
 
+#define UDLIT_OP_ANSI_PREFIX "operator\"\" "
+#define UDLIT_OP_ANSI_FORMAT UDLIT_OP_ANSI_PREFIX "%s"
+#define UDLIT_OP_MANGLED_PREFIX "li"
+#define UDLIT_OP_MANGLED_FORMAT UDLIT_OP_MANGLED_PREFIX "%s"
+#define UDLIT_OPER_P(ID_NODE) \
+  (!strncmp (IDENTIFIER_POINTER (ID_NODE), \
+             UDLIT_OP_ANSI_PREFIX, \
+	     sizeof (UDLIT_OP_ANSI_PREFIX) - 1))
+#define UDLIT_OP_SUFFIX(ID_NODE) \
+  (IDENTIFIER_POINTER (ID_NODE) + sizeof (UDLIT_OP_ANSI_PREFIX) - 1)
+
 #if !defined(NO_DOLLAR_IN_LABEL) || !defined(NO_DOT_IN_LABEL)
 
 #define VTABLE_NAME_P(ID_NODE) (IDENTIFIER_POINTER (ID_NODE)[1] == 'v' \
@@ -5728,6 +5744,7 @@
 extern int lvalue_or_else			(tree, enum lvalue_use,
                                                  tsubst_flags_t);
 extern void check_template_keyword		(tree);
+extern bool check_literal_operator_args		(const_tree, bool *, bool *);
 
 /* in typeck2.c */
 extern void require_complete_eh_spec_types	(tree, tree);
Index: libcpp/include/cpplib.h
===================================================================
--- libcpp/include/cpplib.h	(revision 179328)
+++ libcpp/include/cpplib.h	(working copy)
@@ -131,6 +131,16 @@
   TK(OBJC_STRING,	LITERAL) /* @"string" - Objective-C */		\
   TK(HEADER_NAME,	LITERAL) /* <stdio.h> in #include */		\
 									\
+  TK(CHAR_USERDEF,	LITERAL) /* 'char'_suffix - C++-0x */		\
+  TK(WCHAR_USERDEF,	LITERAL) /* L'char'_suffix - C++-0x */		\
+  TK(CHAR16_USERDEF,	LITERAL) /* u'char'_suffix - C++-0x */		\
+  TK(CHAR32_USERDEF,	LITERAL) /* U'char'_suffix - C++-0x */		\
+  TK(STRING_USERDEF,	LITERAL) /* "string"_suffix - C++-0x */		\
+  TK(WSTRING_USERDEF,	LITERAL) /* L"string"_suffix - C++-0x */	\
+  TK(STRING16_USERDEF,	LITERAL) /* u"string"_suffix - C++-0x */	\
+  TK(STRING32_USERDEF,	LITERAL) /* U"string"_suffix - C++-0x */	\
+  TK(UTF8STRING_USERDEF,LITERAL) /* u8"string"_suffix - C++-0x */	\
+									\
   TK(COMMENT,		LITERAL) /* Only if output comments.  */	\
 				 /* SPELL_LITERAL happens to DTRT.  */	\
   TK(MACRO_ARG,		NONE)	 /* Macro argument.  */			\
@@ -402,6 +412,9 @@
   /* True for traditional preprocessing.  */
   unsigned char traditional;
 
+  /* Nonzero for the 2011 C++ Standard.  */
+  unsigned char cxx11;
+
   /* Holds the name of the target (execution) character set.  */
   const char *narrow_charset;
 
@@ -817,13 +830,22 @@
 #define CPP_N_FRACT	0x100000 /* Fract types.  */
 #define CPP_N_ACCUM	0x200000 /* Accum types.  */
 
+#define CPP_N_USERDEF	0x1000000 /* C++0x user-defined literal.  */
+
 /* Classify a CPP_NUMBER token.  The return value is a combination of
    the flags from the above sets.  */
-extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *);
+extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *,
+				     const char **);
 
+/* Return the classification flags for a float suffix.  */
+extern unsigned int cpp_interpret_float_suffix (const char *, size_t);
+
+/* Return the classification flags for an int suffix.  */
+extern unsigned int cpp_interpret_int_suffix (const char *, size_t);
+
 /* Evaluate a token classified as category CPP_N_INTEGER.  */
 extern cpp_num cpp_interpret_integer (cpp_reader *, const cpp_token *,
-				      unsigned int type);
+				      unsigned int);
 
 /* Sign extend a number, with PRECISION significant bits and all
    others assumed clear, to fill out a cpp_num structure.  */
@@ -993,4 +1015,20 @@
 extern void cpp_force_token_locations (cpp_reader *, source_location *);
 extern void cpp_stop_forcing_token_locations (cpp_reader *);
 
+/* In expr.c */
+extern enum cpp_ttype cpp_userdef_string_remove_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_string_add_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_char_remove_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_char_add_type
+  (enum cpp_ttype type);
+extern bool cpp_userdef_string_p
+  (enum cpp_ttype type);
+extern bool cpp_userdef_char_p
+  (enum cpp_ttype type);
+extern const char * cpp_get_userdef_suffix
+  (const cpp_token *);
+
 #endif /* ! LIBCPP_CPPLIB_H */
Index: libcpp/init.c
===================================================================
--- libcpp/init.c	(revision 179328)
+++ libcpp/init.c	(working copy)
@@ -80,22 +80,23 @@
   char digraphs;
   char uliterals;
   char rliterals;
+  char cxx11;
 };
 
 static const struct lang_flags lang_defaults[] =
-{ /*              c99 c++ xnum xid std  //   digr ulit rlit */
-  /* GNUC89   */  { 0,  0,  1,   0,  0,   1,   1,   0,   0 },
-  /* GNUC99   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1 },
-  /* GNUC1X   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1 },
-  /* STDC89   */  { 0,  0,  0,   0,  1,   0,   0,   0,   0 },
-  /* STDC94   */  { 0,  0,  0,   0,  1,   0,   1,   0,   0 },
-  /* STDC99   */  { 1,  0,  1,   0,  1,   1,   1,   0,   0 },
-  /* STDC1X   */  { 1,  0,  1,   0,  1,   1,   1,   1,   0 },
-  /* GNUCXX   */  { 0,  1,  1,   0,  0,   1,   1,   0,   0 },
-  /* CXX98    */  { 0,  1,  1,   0,  1,   1,   1,   0,   0 },
-  /* GNUCXX0X */  { 1,  1,  1,   0,  0,   1,   1,   1,   1 },
-  /* CXX0X    */  { 1,  1,  1,   0,  1,   1,   1,   1,   1 },
-  /* ASM      */  { 0,  0,  1,   0,  0,   1,   0,   0,   0 }
+{ /*              c99 c++ xnum xid std  //   digr ulit rlit cxx11 */
+  /* GNUC89   */  { 0,  0,  1,   0,  0,   1,   1,   0,   0,    0 },
+  /* GNUC99   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1,    0 },
+  /* GNUC1X   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1,    0 },
+  /* STDC89   */  { 0,  0,  0,   0,  1,   0,   0,   0,   0,    0 },
+  /* STDC94   */  { 0,  0,  0,   0,  1,   0,   1,   0,   0,    0 },
+  /* STDC99   */  { 1,  0,  1,   0,  1,   1,   1,   0,   0,    0 },
+  /* STDC1X   */  { 1,  0,  1,   0,  1,   1,   1,   1,   0,    0 },
+  /* GNUCXX   */  { 0,  1,  1,   0,  0,   1,   1,   0,   0,    0 },
+  /* CXX98    */  { 0,  1,  1,   0,  1,   1,   1,   0,   0,    0 },
+  /* GNUCXX0X */  { 1,  1,  1,   0,  0,   1,   1,   1,   1,    1 },
+  /* CXX0X    */  { 1,  1,  1,   0,  1,   1,   1,   1,   1,    1 },
+  /* ASM      */  { 0,  0,  1,   0,  0,   1,   0,   0,   0,    0 }
   /* xid should be 1 for GNUC99, STDC99, GNUCXX, CXX98, GNUCXX0X, and
      CXX0X when no longer experimental (when all uses of identifiers
      in the compiler have been audited for correct handling of
@@ -120,6 +121,7 @@
   CPP_OPTION (pfile, digraphs)			 = l->digraphs;
   CPP_OPTION (pfile, uliterals)			 = l->uliterals;
   CPP_OPTION (pfile, rliterals)			 = l->rliterals;
+  CPP_OPTION (pfile, cxx11)			 = l->cxx11;
 }
 
 /* Initialize library global state.  */
Index: libcpp/expr.c
===================================================================
--- libcpp/expr.c	(revision 179328)
+++ libcpp/expr.c	(working copy)
@@ -1,6 +1,6 @@
 /* Parse C expressions for cpplib.
    Copyright (C) 1987, 1992, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
-   2002, 2004, 2008, 2009, 2010 Free Software Foundation.
+   2002, 2004, 2008, 2009, 2010, 2011 Free Software Foundation.
    Contributed by Per Bothner, 1994.
 
 This program is free software; you can redistribute it and/or modify it
@@ -185,6 +185,13 @@
 	     q ? CPP_N_MD_Q : CPP_N_DEFAULT));
 }
 
+/* Return the classification flags for a float suffix.  */
+unsigned int
+cpp_interpret_float_suffix (const char *s, size_t len)
+{
+  return interpret_float_suffix ((const unsigned char *)s, len);
+}
+
 /* Subroutine of cpp_classify_number.  S points to an integer suffix
    of length LEN, possibly zero. Returns 0 for an invalid suffix, or a
    flag vector describing the suffix.  */
@@ -219,11 +226,143 @@
 	     : (l == 1) ? CPP_N_MEDIUM : CPP_N_LARGE));
 }
 
+/* Return the classification flags for an int suffix.  */
+unsigned int
+cpp_interpret_int_suffix (const char *s, size_t len)
+{
+  return interpret_int_suffix ((const unsigned char *)s, len);
+}
+
+/* Return the string type corresponding to the the input user-defined string
+   literal type.  If the input type is not a user-defined string literal
+   type return the input type.  */
+enum cpp_ttype
+cpp_userdef_string_remove_type (enum cpp_ttype type)
+{
+  if (type == CPP_STRING_USERDEF)
+    return CPP_STRING;
+  else if (type == CPP_WSTRING_USERDEF)
+    return CPP_WSTRING;
+  else if (type == CPP_STRING16_USERDEF)
+    return CPP_STRING16;
+  else if (type == CPP_STRING32_USERDEF)
+    return CPP_STRING32;
+  else if (type == CPP_UTF8STRING_USERDEF)
+    return CPP_UTF8STRING;
+  else
+    return type;
+}
+
+/* Return the user-defined string literal type corresponding to the input
+   string type.  If the input type is not a string type return the input
+   type.  */
+enum cpp_ttype
+cpp_userdef_string_add_type (enum cpp_ttype type)
+{
+  if (type == CPP_STRING)
+    return CPP_STRING_USERDEF;
+  else if (type == CPP_WSTRING)
+    return CPP_WSTRING_USERDEF;
+  else if (type == CPP_STRING16)
+    return CPP_STRING16_USERDEF;
+  else if (type == CPP_STRING32)
+    return CPP_STRING32_USERDEF;
+  else if (type == CPP_UTF8STRING)
+    return CPP_UTF8STRING_USERDEF;
+  else
+    return type;
+}
+
+/* Return the char type corresponding to the the input user-defined char
+   literal type.  If the input type is not a user-defined char literal
+   type return the input type.  */
+enum cpp_ttype
+cpp_userdef_char_remove_type (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR_USERDEF)
+    return CPP_CHAR;
+  else if (type == CPP_WCHAR_USERDEF)
+    return CPP_WCHAR;
+  else if (type == CPP_CHAR16_USERDEF)
+    return CPP_STRING16;
+  else if (type == CPP_CHAR32_USERDEF)
+    return CPP_STRING32;
+  else
+    return type;
+}
+
+/* Return the user-defined char literal type corresponding to the input
+   char type.  If the input type is not a char type return the input
+   type.  */
+enum cpp_ttype
+cpp_userdef_char_add_type (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR)
+    return CPP_CHAR_USERDEF;
+  else if (type == CPP_WCHAR)
+    return CPP_WCHAR_USERDEF;
+  else if (type == CPP_CHAR16)
+    return CPP_CHAR16_USERDEF;
+  else if (type == CPP_CHAR32)
+    return CPP_CHAR32_USERDEF;
+  else
+    return type;
+}
+
+/* Return true if the token type is a user-defined string literal.  */
+bool
+cpp_userdef_string_p (enum cpp_ttype type)
+{
+  if (type == CPP_STRING_USERDEF
+   || type == CPP_WSTRING_USERDEF
+   || type == CPP_STRING16_USERDEF
+   || type == CPP_STRING32_USERDEF
+   || type == CPP_UTF8STRING_USERDEF)
+    return true;
+  else
+    return false;
+}
+
+/* Return true if the token type is a user-defined char literal.  */
+bool
+cpp_userdef_char_p (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR_USERDEF
+   || type == CPP_WCHAR_USERDEF
+   || type == CPP_CHAR16_USERDEF
+   || type == CPP_CHAR32_USERDEF)
+    return true;
+  else
+    return false;
+}
+
+/* Extract the suffix from a user-defined literal string or char.  */
+const char *
+cpp_get_userdef_suffix (const cpp_token *tok)
+{
+  unsigned int len = tok->val.str.len;
+  const char *text = (const char *)tok->val.str.text;
+  char delim;
+  unsigned int i;
+  for (i = 0; i < len; ++i)
+    if (text[i] == '\'' || text[i] == '"')
+      break;
+  if (i == len)
+    return text + len;
+  delim = text[i];
+  for (i = len; i > 0; --i)
+    if (text[i - 1] == delim)
+      break;
+  return text + i;
+}
+
 /* Categorize numeric constants according to their field (integer,
    floating point, or invalid), radix (decimal, octal, hexadecimal),
-   and type suffixes.  */
+   and type suffixes.  In C++0X if UD_SUFFIX is non null it will be
+   assigned any unrecognized suffix for a user-defined literal.  */
 unsigned int
-cpp_classify_number (cpp_reader *pfile, const cpp_token *token)
+cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
+		     const char **ud_suffix)
 {
   const uchar *str = token->val.str.text;
   const uchar *limit;
@@ -231,6 +370,9 @@
   enum {NOT_FLOAT = 0, AFTER_POINT, AFTER_EXPON} float_flag;
   bool seen_digit;
 
+  if (ud_suffix)
+    *ud_suffix = NULL;
+
   /* If the lexer has done its job, length one can only be a single
      digit.  Fast-path this very common case.  */
   if (token->val.str.len == 1)
@@ -361,10 +503,19 @@
       result = interpret_float_suffix (str, limit - str);
       if (result == 0)
 	{
-	  cpp_error (pfile, CPP_DL_ERROR,
-		     "invalid suffix \"%.*s\" on floating constant",
-		     (int) (limit - str), str);
-	  return CPP_N_INVALID;
+	  if (CPP_OPTION (pfile, cxx11))
+	    {
+	      if (ud_suffix)
+		*ud_suffix = (const char *) str;
+	      result = CPP_N_LARGE | CPP_N_USERDEF;
+	    }
+	  else
+	    {
+	      cpp_error (pfile, CPP_DL_ERROR,
+			 "invalid suffix \"%.*s\" on floating constant",
+			 (int) (limit - str), str);
+	      return CPP_N_INVALID;
+	    }
 	}
 
       /* Traditional C didn't accept any floating suffixes.  */
@@ -406,10 +557,19 @@
       result = interpret_int_suffix (str, limit - str);
       if (result == 0)
 	{
-	  cpp_error (pfile, CPP_DL_ERROR,
-		     "invalid suffix \"%.*s\" on integer constant",
-		     (int) (limit - str), str);
-	  return CPP_N_INVALID;
+	  if (CPP_OPTION (pfile, cxx11))
+	    {
+	      if (ud_suffix)
+		*ud_suffix = (const char *) str;
+	      result = CPP_N_UNSIGNED | CPP_N_LARGE | CPP_N_USERDEF;
+	    }
+	  else
+	    {
+	      cpp_error (pfile, CPP_DL_ERROR,
+			 "invalid suffix \"%.*s\" on integer constant",
+			 (int) (limit - str), str);
+	      return CPP_N_INVALID;
+	    }
 	}
 
       /* Traditional C only accepted the 'L' suffix.
@@ -748,7 +908,7 @@
   switch (token->type)
     {
     case CPP_NUMBER:
-      temp = cpp_classify_number (pfile, token);
+      temp = cpp_classify_number (pfile, token, NULL);
       switch (temp & CPP_N_CATEGORY)
 	{
 	case CPP_N_FLOATING:
Index: libcpp/lex.c
===================================================================
--- libcpp/lex.c	(revision 179328)
+++ libcpp/lex.c	(working copy)
@@ -1227,6 +1227,7 @@
   token->type = type;
   token->val.str.len = len;
   token->val.str.text = dest;
+/*printf("\ntoken: %s", token->val.str.text);*/
 }
 
 /* Subroutine of lex_raw_string: Append LEN chars from BASE to the buffer
@@ -1478,6 +1479,18 @@
     }
  break_outer_loop:
 
+  if (CPP_OPTION (pfile, cxx11))
+    {
+      /* Grab user defined literal suffix.  */
+      if (ISIDST(*cur))
+	{
+	  type = cpp_userdef_string_add_type (type);
+	  ++cur;
+	}
+      while (ISIDNUM(*cur))
+	++cur;
+    }
+
   pfile->buffer->cur = cur;
   if (first_buff == NULL)
     create_literal (pfile, token, base, cur - base, type);
@@ -1581,6 +1594,19 @@
     cpp_error (pfile, CPP_DL_PEDWARN, "missing terminating %c character",
 	       (int) terminator);
 
+  if (CPP_OPTION (pfile, cxx11))
+    {
+      /* Grab user defined literal suffix.  */
+      if (ISIDST(*cur))
+	{
+	  type = cpp_userdef_char_add_type (type);
+	  type = cpp_userdef_string_add_type (type);
+          ++cur;
+	}
+      while (ISIDNUM(*cur))
+	++cur;
+    }
+
   pfile->buffer->cur = cur;
   create_literal (pfile, token, base, cur - base, type);
 }

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-10-05 15:57           ` Ed Smith-Rowland
@ 2011-10-05 21:24             ` Jason Merrill
  2011-10-08 21:38               ` Ed Smith-Rowland
  0 siblings, 1 reply; 36+ messages in thread
From: Jason Merrill @ 2011-10-05 21:24 UTC (permalink / raw)
  To: Ed Smith-Rowland; +Cc: gcc-patches

On 10/05/2011 11:55 AM, Ed Smith-Rowland wrote:
> +         int num_parms = TREE_VEC_LENGTH (parameter_list);
> +         if (num_parms != 1)
> +           ok = false;
> +         else
> +           {
> +             tree parm_list = TREE_VEC_ELT (parameter_list, 0);
> +             tree parm = INNERMOST_TEMPLATE_PARMS (parm_list);

This is backwards; you want to do INNERMOST_TEMPLATE_PARMS before 
looking at the number of parms or pulling out the one at index 0.

> +struct GTY(()) tree_userdef_literal {
> +  struct tree_common common;

I think you can use tree_base instead of tree_common here, since you 
aren't using TREE_TYPE or TREE_CHAIN.

> One thing doesn't work.  Earlier I had said that friend declarations failed.  Not true.  What fails is defining the function body in the class definition.  The function is simply not recorded.  I'm trying to track this down but pointers would be helpful.  If I write the function body outside the class definition friend works perfectly.

> About friends.  The lookup for user-defined literal operators isn't ADL.  They are a lot like normal functions because of the suffix-id as opposed to operator<< in this regard.  Thus a friend literal operator should be accessible both as an explicit operator call and via a literal.  Both are tested and except as noted above about inline defs the tests pass.

A function that is only declared in a friend declaration can only be 
found by ADL, so that doesn't sound like a failure to me; it sounds like 
it's working the way it should.  However, if you declare the function 
earlier and then define it in the friend declaration it ought to work.

Jason

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-09-20 21:48         ` Jason Merrill
@ 2011-10-05 15:57           ` Ed Smith-Rowland
  2011-10-05 21:24             ` Jason Merrill
  0 siblings, 1 reply; 36+ messages in thread
From: Ed Smith-Rowland @ 2011-10-05 15:57 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 3858 bytes --]

On 09/20/2011 04:15 PM, Jason Merrill wrote:
> On 09/19/2011 10:07 PM, Ed Smith-Rowland wrote:
>> On 09/19/2011 05:11 PM, Jason Merrill wrote:
>>> Can't you store the string and the suffix, and then interpret the
>>> number later if you end up calling an operator that takes the value?
>
>> I could and I thought abut it but from the wording (2.14.8 p3 and p4) it
>> looks like the numeric argument gets first try, then raw literal then
>> literal template. I thought I might as well let the preprocessor do the
>> numeric conversion since I'll always check it first.
>
> Fair enough.  We could do the overload resolution before we produce 
> the actual value to be passed, but I guess that's probably not a 
> sufficient optmization to bother with.
>
>> +       error ("user-defined literal operator template %q+D"
>> +              " conflicts with user-defined raw literal operator %q+D",
>> +              newdecl, olddecl);
>
> You should only use + for one of the decls; that sets the source 
> position for the diagnostic.
>
>> +  TK(CHAR_USERDEF,     LITERAL) /* 'char'_suffix - C++-0x 
>> */           \
>> +  TK(WCHAR_USERDEF,    LITERAL) /* L'char'_suffix - C++-0x 
>> */          \
>> +  TK(CHAR16_USERDEF,   LITERAL) /* u'char'_suffix - C++-0x 
>> */          \
>> +  TK(CHAR32_USERDEF,   LITERAL) /* U'char'_suffix - C++-0x 
>> */          \
>> +  TK(STRING_USERDEF,   LITERAL) /* "string"_suffix - C++-0x 
>> */         \
>> +  TK(WSTRING_USERDEF,  LITERAL) /* L"string"_suffix - C++-0x 
>> */        \
>> +  TK(STRING16_USERDEF, LITERAL) /* u"string"_suffix - C++-0x 
>> */        \
>> +  TK(STRING32_USERDEF, LITERAL) /* U"string"_suffix - C++-0x 
>> */        \
>> +  TK(UTF8STRING_USERDEF,LITERAL) /* u8"string"_suffix - C++-0x 
>> */      \
>
> Could we avoid adding all these additional codes by setting a flag on 
> the token?  It seems odd to have extra codes for char/string literals 
> but not for numbers.
>
>> +       const char *suffix;
>> +       cpp_get_userdef_suffix (tok->val.str, '\'', &suffix);
>
> Let's return the suffix pointer instead of passing in the address of a 
> local variable.  And pass in the token pointer rather than the string 
> and a delimiter; libcpp can figure out which delimiter to use based on 
> the token type.  It could also handle the flag I suggested above so 
> that the front end doesn't need to know about it.
>
> Jason
>
Here is another iteration of the patch.

I tried getting rid of all the codes.
1.  I couldn't even bootstrap the result.
2.  I sort of like the codes - these really are different sort of tokens 
- strings with suffixes.
3.  One could argue that then I should have a CPP_NUMBER_USERDEF token.  
I'm mixed.  On one hand this would be more consistent.  On the other, 
suffixed numbers are an old tried and true token.  This last is why the 
treatment of numbers was different from strings and chars.

I finally figured out template operators.  They work now.

One thing doesn't work.  Earlier I had said that friend declarations 
failed.  Not true.  What fails is defining the function body in the 
class definition.  The function is simply not recorded.  I'm trying to 
track this down but pointers would be helpful.  If I write the function 
body outside the class definition friend works perfectly.

About friends.  The lookup for user-defined literal operators isn't 
ADL.  They are a lot like normal functions because of the suffix-id as 
opposed to operator<< in this regard.  Thus a friend literal operator 
should be accessible both as an explicit operator call and via a 
literal.  Both are tested and except as noted above about inline defs 
the tests pass.

I have some repeated error messages I would like to clean up.  I want 
the missing underscore warning to appear only once.  Again, pointers 
would be helpful.

Basically, the thing works.

Thank you,

Ed

[-- Attachment #2: patch25 --]
[-- Type: text/plain, Size: 73411 bytes --]

Index: gcc/c-family/c-common.c
===================================================================
--- gcc/c-family/c-common.c	(revision 179328)
+++ gcc/c-family/c-common.c	(working copy)
@@ -9919,4 +9919,17 @@
   MARK_TS_TYPED (EXCESS_PRECISION_EXPR);
 }
 
+/* Build a user-defined numeric literal out of an integer constant type VALUE
+   with identifier SUFFIX.  */
+
+tree
+build_userdef_literal (tree suffix_id, tree value, tree num_string)
+{
+  tree literal = make_node (USERDEF_LITERAL);
+  USERDEF_LITERAL_SUFFIX_ID (literal) = suffix_id;
+  USERDEF_LITERAL_VALUE (literal) = value;
+  USERDEF_LITERAL_NUM_STRING (literal) = num_string;
+  return literal;
+}
+
 #include "gt-c-family-c-common.h"
Index: gcc/c-family/c-lex.c
===================================================================
--- gcc/c-family/c-lex.c	(revision 179328)
+++ gcc/c-family/c-lex.c	(working copy)
@@ -44,8 +44,8 @@
 int pending_lang_change; /* If we need to switch languages - C++ only */
 int c_header_level;	 /* depth in C headers - C++ only */
 
-static tree interpret_integer (const cpp_token *, unsigned int);
-static tree interpret_float (const cpp_token *, unsigned int);
+static tree interpret_integer (const cpp_token *, unsigned int, const char *);
+static tree interpret_float (const cpp_token *, unsigned int, const char *);
 static tree interpret_fixed (const cpp_token *, unsigned int);
 static enum integer_type_kind narrowest_unsigned_type
 	(unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned int);
@@ -314,7 +314,8 @@
 
     case CPP_NUMBER:
       {
-	unsigned int flags = cpp_classify_number (parse_in, tok);
+	const char *suffix = NULL;
+	unsigned int flags = cpp_classify_number (parse_in, tok, &suffix);
 
 	switch (flags & CPP_N_CATEGORY)
 	  {
@@ -328,16 +329,27 @@
 	       Set PURE_ZERO to pass this information to the C++ parser.  */
 	    if (tok->val.str.len == 1 && *tok->val.str.text == '0')
 	      add_flags = PURE_ZERO;
-	    *value = interpret_integer (tok, flags);
+	    *value = interpret_integer (tok, flags, suffix);
 	    break;
 
 	  case CPP_N_FLOATING:
-	    *value = interpret_float (tok, flags);
+	    *value = interpret_float (tok, flags, suffix);
 	    break;
 
 	  default:
 	    gcc_unreachable ();
 	  }
+
+	if (flags & CPP_N_USERDEF)
+	  {
+	    tree num_string = build_string (tok->val.str.len - strlen (suffix),
+					    (const char *) tok->val.str.text);
+	    TREE_TYPE (num_string) = char_array_type_node;
+	    num_string = fix_string_type (num_string);
+	    tree literal = build_userdef_literal (get_identifier (suffix),
+						  *value, num_string);
+	    *value = literal;
+	  }
       }
       break;
 
@@ -415,6 +427,22 @@
       }
       goto retry;
 
+    case CPP_CHAR_USERDEF:
+    case CPP_WCHAR_USERDEF:
+    case CPP_CHAR16_USERDEF:
+    case CPP_CHAR32_USERDEF:
+      {
+	tree literal;
+	cpp_token temp_tok = *tok;
+	const char *suffix = cpp_get_userdef_suffix (tok);
+	temp_tok.val.str.len -= strlen (suffix);
+	temp_tok.type = cpp_userdef_char_remove_type (type);
+	literal = build_userdef_literal (get_identifier (suffix),
+					 lex_charconst (&temp_tok), NULL_TREE);
+	*value = literal;
+      }
+      break;
+
     case CPP_CHAR:
     case CPP_WCHAR:
     case CPP_CHAR16:
@@ -422,6 +450,22 @@
       *value = lex_charconst (tok);
       break;
 
+    case CPP_STRING_USERDEF:
+    case CPP_WSTRING_USERDEF:
+    case CPP_STRING16_USERDEF:
+    case CPP_STRING32_USERDEF:
+    case CPP_UTF8STRING_USERDEF:
+      {
+	tree literal, string;
+	const char *suffix = cpp_get_userdef_suffix (tok);
+	string = build_string (tok->val.str.len - strlen (suffix),
+			       (const char *) tok->val.str.text);
+	literal = build_userdef_literal (get_identifier (suffix),
+					 string, NULL_TREE);
+	*value = literal;
+      }
+      break;
+
     case CPP_STRING:
     case CPP_WSTRING:
     case CPP_STRING16:
@@ -536,9 +580,11 @@
   return itk_none;
 }
 
-/* Interpret TOKEN, an integer with FLAGS as classified by cpplib.  */
+/* Interpret TOKEN, an integer with FLAGS as classified by cpplib.
+   For C++0X SUFFIX may contain a user-defined literal suffix.  */
 static tree
-interpret_integer (const cpp_token *token, unsigned int flags)
+interpret_integer (const cpp_token *token, unsigned int flags,
+		   const char *suffix)
 {
   tree value, type;
   enum integer_type_kind itk;
@@ -621,9 +667,10 @@
 }
 
 /* Interpret TOKEN, a floating point number with FLAGS as classified
-   by cpplib.  */
+   by cpplib.  For C++0X SUFFIX may contain a user-defined literal suffix.  */
 static tree
-interpret_float (const cpp_token *token, unsigned int flags)
+interpret_float (const cpp_token *token, unsigned int flags,
+		 const char *suffix)
 {
   tree type;
   tree const_type;
@@ -702,7 +749,9 @@
      has any suffixes, cut them off; REAL_VALUE_ATOF/ REAL_VALUE_HTOF
      can't handle them.  */
   copylen = token->val.str.len;
-  if (flags & CPP_N_DFLOAT)
+  if (flags & CPP_N_USERDEF)
+    copylen -= strlen (suffix);
+  else if (flags & CPP_N_DFLOAT)
     copylen -= 2;
   else
     {
Index: gcc/c-family/c-common.h
===================================================================
--- gcc/c-family/c-common.h	(revision 179328)
+++ gcc/c-family/c-common.h	(working copy)
@@ -1067,4 +1067,27 @@
   return NULL;
 }
 
+/* A suffix-identifier value doublet that represents user-defined literals
+   for C++-0x.  */
+struct GTY(()) tree_userdef_literal {
+  struct tree_common common;
+  tree suffix_id;
+  tree value;
+  tree num_string;
+};
+
+#define USERDEF_LITERAL_SUFFIX_ID(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->suffix_id)
+
+#define USERDEF_LITERAL_VALUE(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->value)
+
+#define USERDEF_LITERAL_NUM_STRING(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->num_string)
+
+#define USERDEF_LITERAL_TYPE(NODE) \
+  (TREE_TYPE (USERDEF_LITERAL_VALUE (NODE)))
+
+extern tree build_userdef_literal (tree suffix_id, tree value, tree num_string);
+
 #endif /* ! GCC_C_COMMON_H */
Index: gcc/c-family/c-common.def
===================================================================
--- gcc/c-family/c-common.def	(revision 179328)
+++ gcc/c-family/c-common.def	(working copy)
@@ -47,6 +47,12 @@
    evaluated.  */
 DEFTREECODE (EXCESS_PRECISION_EXPR, "excess_precision_expr", tcc_expression, 1)
 
+/* Used to represent a user-defined literal.
+   The operands are an IDENTIFIER for the suffix, the VALUE of the literal,
+   and for numeric literals the original string representation of the
+   number.  */
+DEFTREECODE (USERDEF_LITERAL, "userdef_literal", tcc_exceptional, 3)
+
 /*
 Local variables:
 mode:c
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C	(revision 0)
@@ -0,0 +1,4 @@
+// { dg-options -std=c++0x }
+
+template<char...>
+  int operator"" _xyz(unsigned long long);	// { dg-error "has invalid argument list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit_system_header
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit_system_header	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit_system_header	(revision 0)
@@ -0,0 +1,6 @@
+
+#pragma GCC system_header
+
+char
+operator"" stdsuffix(char __c)
+{ return __c/2; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C	(revision 0)
@@ -0,0 +1,29 @@
+// { dg-options "-std=c++0x" }
+
+//  Can't have *both* literal operator template and raw literal operator.
+
+int
+operator"" _abc(const char*)
+  {
+    return 42;
+  }
+
+template<char...>
+  int
+  operator"" _abc() // {dg-error "user-defined literal operator template|conflicts with user-defined raw literal operator"}
+  {
+    return 13;
+  }
+
+template<char...>
+  int
+  operator"" _def()
+  {
+    return 12;
+  }
+
+int
+operator"" _def(const char*) // {dg-error "user-defined raw literal operator|conflicts with user-defined literal operator template"}
+  {
+    return 43;
+  }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C	(revision 0)
@@ -0,0 +1,43 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test simple operator declaration and definition in namespaces.
+
+#include <cmath>
+#include <limits>
+
+namespace Long
+{
+  long double operator"" _LL(long double);
+}
+
+namespace Short
+{
+  short
+  operator"" _SS(long double x)
+  { return std::fmod(x, static_cast<long double>(std::numeric_limits<short>::max())); }
+}
+
+void
+test1()
+{
+  long double x = Long::operator "" _LL(1.2L);
+
+  using namespace Short;
+  short s = operator"" _SS(1.2L);
+  short s2 = 1.2_SS;
+}
+
+int
+main()
+{
+  test1();
+}
+
+namespace Long
+{
+  long double
+  operator"" _LL(long double x)
+  { return x + 2.0L; }
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C	(revision 0)
@@ -0,0 +1,15 @@
+// { dg-options -std=c++0x }
+
+class Foo
+{
+public:
+  Foo() { }
+  int operator"" _Bar(char32_t);  // { dg-error "must be a non-member function" }
+};
+
+int i = operator"" _Bar(U'x');  // { dg-error "was not declared in this scope" }
+int j = U'x'_Bar;  // { dg-error "unable to find user-defined character literal operator" }
+
+int
+Foo::operator"" _Bar(char32_t)  // { dg-error "must be a non-member function" }
+{ return 42; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C	(revision 0)
@@ -0,0 +1,38 @@
+// { dg-options -std=c++0x }
+
+#include <cstddef>
+
+class Foo { };
+
+Foo
+operator"" _Foo(int *);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(unsigned long int);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(double);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const float *, std::size_t);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const wchar_t *, int);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const char16_t *);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(char...);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(unsigned long long int, char);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(const char *, std::size_t, int);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(long double &);	// { dg-error "has invalid argument list" }
+
+Foo
+operator"" _Foo(std::size_t, const char16_t *);	// { dg-error "has invalid argument list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C	(revision 0)
@@ -0,0 +1,17 @@
+// { dg-options "-std=c++98" }
+
+#include <cstddef>
+
+int
+operator"" _mm(long double m)	// { dg-warning "user-defined literals only available with" }
+{ return int(1000.0L * m); }
+
+int in = 0.0254_mm;	// { dg-error "invalid suffix" }
+
+int
+operator"" _Q(const char *, std::size_t)	// { dg-warning "user-defined literals only available with" }
+{ return 42; }
+
+int x = "Hello"_Q;	// { dg-error "invalid conversion from" }
+
+// { dg-error "expected" "" { target *-*-* } 15 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+#include <string>
+
+std::string operator"" 5X(const char*, std::size_t);	// { dg-error "expected suffix identifier" }
+
+// { dg-error "expected type-specifier before string constant" "" { target *-*-* } 5 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+constexpr unsigned long long
+operator"" _grow(unsigned long long n)
+{ return 2 * n; }
+
+double buffer[25_grow];
Index: gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C	(revision 0)
@@ -0,0 +1,49 @@
+// { dg-options -std=c++0x }
+
+//  Test that the standard suffixes shadow any user-defined suffixes of the same name.
+long double
+operator"" L(long double x)	// { dg-warning "floating point suffix shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ULL(unsigned long long int k)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return k; }
+
+long double
+operator"" l(long double x)	// { dg-warning "floating point suffix shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ull(unsigned long long int k)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return k; }
+
+//  Namespaces are no hiding place.
+namespace Long
+{
+
+long double
+operator"" L(long double x)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ULL(unsigned long long int k)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return k; }
+
+long double
+operator"" l(long double x)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ull(unsigned long long int k)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return k; }
+
+}
+
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 5 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 9 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 13 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 17 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 25 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 29 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 33 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 37 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test warning on declaration without leading underscore.
+
+long double operator"" nounder(long double); // { dg-warning "suffixes not preceded by|are reserved for future standardization" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options -std=c++0x }
+
+class Foo { };
+
+template<wchar_t...>
+  Foo operator"" _Foo(); // { dg-error "user-defined literal operator template|has invalid parameter list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-general.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-general.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-general.C	(revision 0)
@@ -0,0 +1,52 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test simple operator declaration and definition.
+
+#include <cstring>
+#include <string>
+#include <complex>
+#include <cassert>
+
+long double operator"" _v(long double);
+std::string operator"" _w(const char16_t*, size_t);
+unsigned operator"" _w(const char*);
+
+std::complex<double>
+operator"" _i(long double y)
+{ return std::complex<double>(0.0L, y); }
+
+void
+test1()
+{
+  long double x = operator"" _v(1.2L);
+  assert(x == 2.2L);
+
+  std::string s = operator"" _w(u"one", 3);
+  assert(s == "boo");
+
+  unsigned u = operator"" _w("Hello, World!");
+  assert(u == 13U);
+
+  std::complex<double> i = operator"" _i(2.0);
+  assert(i == std::complex<double>(0.0, 2.0));
+}
+
+int
+main()
+{
+  test1();
+}
+
+long double
+operator"" _v(long double x)
+{ return x + 1.0L; }
+
+std::string
+operator"" _w(const char16_t*, size_t)
+{ return std::string("boo"); }
+
+unsigned
+operator"" _w(const char* str)
+{ return strlen(str); }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C	(revision 0)
@@ -0,0 +1,3 @@
+// { dg-options -std=c++0x }
+
+#include "udlit_system_header"
Index: gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C	(revision 0)
@@ -0,0 +1,15 @@
+// { dg-options -std=c++0x }
+
+#include <string>
+
+std::string operator"" _i18n(const char*, std::size_t);
+
+std::string vogon_poem = R"V0G0N(
+                O freddled gruntbuggly thy micturations are to me
+                    As plured gabbleblochits on a lurgid bee.
+                 Groop, I implore thee my foonting turlingdromes.   
+              And hooptiously drangle me with crinkly bindlewurdles,
+  Or I will rend thee in the gobberwarts with my blurlecruncheon, see if I don't.
+
+                    (by Prostetnic Vogon Jeltz; see p. 56/57)
+)V0G0N"_i18n;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test error on non-function declaration.
+
+double operator"" _baddecl; // { dg-error "as non-function" }
+
+template<char...>
+  int operator"" _badtmpldecl; // { dg-error "as non-function" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-addr.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-addr.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-addr.C	(revision 0)
@@ -0,0 +1,10 @@
+// { dg-options "-std=c++0x" }
+
+#include <cstddef>
+
+bool operator"" _yn(const char*, size_t);
+
+typedef bool (*pfunk)(const char*, size_t);
+pfunk p = &operator"" _yn;
+
+bool tf = p("Hello,\0 World!", 14);
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C	(revision 0)
@@ -0,0 +1,4 @@
+// { dg-options -std=c++0x }
+
+template<char...>
+  int operator"" _abc();
Index: gcc/testsuite/g++.dg/cpp0x/udlit-inline-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-inline-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-inline-neg.C	(revision 0)
@@ -0,0 +1,17 @@
+// { dg-options -std=c++0x }
+
+//  Make sure inline literal operator definition in class issn't accepted.
+
+class Foo
+{
+  int
+  operator"" _thing(char cc)
+  { return 42 * cc; }
+};
+
+int
+main()
+{
+  int iF = Foo::operator"" _thing('x');
+  int jF = 'x'_thing;
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C	(revision 0)
@@ -0,0 +1,8 @@
+// { dg-options -std=c++0x }
+
+extern "C" {
+
+int
+operator"" _badclinkage(unsigned long long);	// { dg-error "operator with C linkage" }
+
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-template.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-template.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-template.C	(revision 0)
@@ -0,0 +1,51 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test template operator declaration and definition.
+
+#include <cassert>
+
+template<char...>
+  int operator"" _abc();
+
+template<>
+  int
+  operator"" _abc<>()
+  { return -1; }
+
+template<>
+  int
+  operator"" _abc<'L','U','E'>()
+  { return 42; }
+
+template<>
+  int
+  operator"" _abc<'6','6','6'>()
+  { return 21; }
+
+int
+test1()
+{
+  int i = operator"" _abc<'1','2','3'>();
+  assert(i == 45);
+  int universal_meaning = operator"" _abc<'L','U','E'>();
+  assert(universal_meaning == 42);
+  int b = operator"" _abc<'6','6','6'>();
+  int z = operator"" _abc<>();
+  assert(z == -1);
+  int j = 123_abc;
+  assert(j == i);
+  int jb = 666_abc;
+  assert(jb == b);
+}
+
+int
+main()
+{
+  test1();
+}
+
+template<char... Chars>
+  int operator"" _abc()
+  { return 42 + sizeof...(Chars); }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-args.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-args.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-args.C	(revision 0)
@@ -0,0 +1,38 @@
+// { dg-options -std=c++0x }
+
+#include <cstddef>
+
+class Foo { };
+
+Foo
+operator"" _Foo(const char *);
+
+Foo
+operator"" _Foo(unsigned long long int);
+
+Foo
+operator"" _Foo(long double);
+
+Foo
+operator"" _Foo(char);
+
+Foo
+operator"" _Foo(wchar_t);
+
+Foo
+operator"" _Foo(char16_t);
+
+Foo
+operator"" _Foo(char32_t);
+
+Foo
+operator"" _Foo(const char *, std::size_t);
+
+Foo
+operator"" _Foo(const wchar_t *, std::size_t);
+
+Foo
+operator"" _Foo(const char16_t *, std::size_t);
+
+Foo
+operator"" _Foo(const char32_t *, std::size_t);
Index: gcc/testsuite/g++.dg/cpp0x/udlit-declare-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-declare-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-declare-neg.C	(revision 0)
@@ -0,0 +1,15 @@
+// { dg-options "-std=c++0x" }
+
+//  Check that undeclared literal operator calls and literals give appropriate errors.
+
+int i = operator"" _Bar('x');  // { dg-error "was not declared in this scope" }
+int j = 'x'_Bar;  // { dg-error "unable to find user-defined character literal operator" }
+
+int ii = operator"" _BarCharStr("Howdy, Pardner!");  // { dg-error "was not declared in this scope" }
+int jj = "Howdy, Pardner!"_BarCharStr;  // { dg-error "unable to find user-defined string literal operator" }
+
+unsigned long long iULL = operator"" _BarULL(666ULL);  // { dg-error "was not declared in this scope" }
+unsigned long long jULL = 666_BarULL;  // { dg-error "unable to find user-defined numeric literal operator" }
+
+long double iLD = operator"" _BarLD(666.0L);  // { dg-error "was not declared in this scope" }
+long double jLD = 666.0_BarLD;  // { dg-error "unable to find user-defined numeric literal operator" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+char32_t
+operator"" (char32_t C)	// { dg-error "expected suffix identifier" }
+{ return C; }
+
+// { dg-error "expected type-specifier before string constant" "" { target *-*-* } 4 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test error on non-empty string after 'operator' keyword.
+
+double operator"hi" _badword(long double); // { dg-error "expected empty string after" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-inline.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-inline.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-inline.C	(revision 0)
@@ -0,0 +1,20 @@
+// { dg-options "-std=c++0x" }
+
+//  Literal operators can be inline.
+
+inline int
+operator"" _thing1(char cc)
+{ return 42 * cc; }
+
+class Foo
+{
+  int
+  friend operator"" _thing2(char cc)
+  { return 42 * cc; }
+};
+
+int i = operator"" _thing1('x');
+int j = 'x'_thing1;
+
+int iF = operator"" _thing2('x');
+int jF = 'x'_thing2;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+extern "C"_badlinkage {	// { dg-error "expected unqualified-id before" }
+
+int foo();
+
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-friend.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-friend.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-friend.C	(revision 0)
@@ -0,0 +1,16 @@
+// { dg-options -std=c++0x }
+
+class Foo
+{
+public:
+  Foo() { }
+  friend Foo operator"" _Bar(char);
+};
+
+Foo
+operator"" _Bar(char)
+{ return Foo(); }
+
+Foo f1 = operator"" _Bar('x');
+
+Foo f2 = 'x'_Bar;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+#include <string>
+
+std::string operator"" _xxx(const char*, size_t);
+
+std::string operator"" _yyy(const char*, size_t);
+
+std::string concat = "Hello, "_xxx "World!"_yyy;	// { dg-error "inconsistent user-defined literal suffixes" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options -std=c++0x }
+
+class Foo { };
+
+template<char...>
+  Foo operator"" _Foo();
Index: gcc/testsuite/g++.dg/cpp0x/udlit-concat.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-concat.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-concat.C	(revision 0)
@@ -0,0 +1,24 @@
+// { dg-options "-std=c++0x" }
+
+#include <string>
+
+std::string operator"" _www(const char*, size_t);
+
+std::string concat01 = "Hello, " "World!"_www;
+
+std::string concat10 = "Hello, "_www "World!";
+
+std::string concat11 = "Hello, "_www "World!"_www;
+
+
+class Tachyon { };
+
+Tachyon operator"" _fast(const char*, size_t);
+
+int operator"" _fast(const char32_t*, size_t);
+
+int speedy01 = "Hello, " U"World!"_fast;
+
+int speedy10 = "Hello, "_fast U"World!";
+
+int speedy11 = "Hello, "_fast U"World!"_fast;
Index: gcc/cp/typeck.c
===================================================================
--- gcc/cp/typeck.c	(revision 179328)
+++ gcc/cp/typeck.c	(working copy)
@@ -8334,3 +8334,94 @@
   return 1;
 }
 
+
+/* Return true if a user-defined literal operator has one of the allowed
+   argument types.  */
+
+bool
+check_literal_operator_args (const_tree decl,
+			     bool *long_long_unsigned_p, bool *long_double_p)
+{
+  tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
+  if (processing_template_decl)
+    return (argtypes == NULL_TREE
+	    || same_type_p (TREE_VALUE (argtypes), void_type_node));
+  else
+    {
+      tree argtype;
+      int arity;
+      int max_arity = 2;
+      bool found_string_p = false;
+      bool maybe_raw_p = false;
+      bool found_size_p = false;
+      tree const_char_ptr_type_node
+	   = build_pointer_type(build_type_variant(char_type_node, 1, 0));
+      tree const_wchar_ptr_type_node
+	   = build_pointer_type(build_type_variant(wchar_type_node, 1, 0));
+      tree const_char16_ptr_type_node
+	   = build_pointer_type(build_type_variant(char16_type_node, 1, 0));
+      tree const_char32_ptr_type_node
+	   = build_pointer_type(build_type_variant(char32_type_node, 1, 0));
+
+      *long_long_unsigned_p = false;
+      *long_double_p = false;
+
+      /* Count the number and type of arguments and check for ellipsis.  */
+      for (argtype = argtypes, arity = 0;
+	   argtype && argtype != void_list_node;
+	   argtype = TREE_CHAIN (argtype))
+	{
+	  tree t = TREE_VALUE (argtype);
+	  ++arity;
+
+	  if (same_type_p (t, const_char_ptr_type_node))
+	    {
+	      found_string_p = true;
+	      maybe_raw_p = true;
+	    }
+	  else if (same_type_p (t, const_wchar_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, const_char16_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, const_char32_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, size_type_node))
+	    {
+	      if (!found_string_p)
+		return false;
+	      found_size_p = true;
+	    }
+	  else if (same_type_p (t, long_long_unsigned_type_node))
+	    {
+	      max_arity = 1;
+	      *long_long_unsigned_p = true;
+	    }
+	  else if (same_type_p (t, long_double_type_node))
+	    {
+	      max_arity = 1;
+	      *long_double_p = true;
+	    }
+	  else if (same_type_p (t, char_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, wchar_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, char16_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, char32_type_node))
+	    max_arity = 1;
+	  else
+	    return false;
+	}
+      if (!argtype)
+	return false; /* Found ellipsis.  */
+
+      if (arity > max_arity)
+	return false;
+
+      if (found_string_p && !maybe_raw_p && !found_size_p)
+	return false;
+
+      return true;
+    }
+}
+
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 179328)
+++ gcc/cp/decl.c	(working copy)
@@ -1203,6 +1203,21 @@
       || TREE_TYPE (olddecl) == error_mark_node)
     return error_mark_node;
 
+  if (UDLIT_OPER_P (DECL_NAME (newdecl))
+      && UDLIT_OPER_P (DECL_NAME (olddecl)))
+    {
+      if (TREE_CODE (newdecl) == TEMPLATE_DECL
+	  && TREE_CODE (olddecl) != TEMPLATE_DECL)
+	error ("user-defined literal operator template %q+D"
+	       " conflicts with user-defined raw literal operator %qD",
+	       newdecl, olddecl);
+      else if (TREE_CODE (newdecl) != TEMPLATE_DECL
+	       && TREE_CODE (olddecl) == TEMPLATE_DECL)
+	error ("user-defined raw literal operator %q+D"
+	       " conflicts with user-defined literal operator template %qD",
+	       newdecl, olddecl);
+    }
+
   if (DECL_P (olddecl)
       && TREE_CODE (newdecl) == FUNCTION_DECL
       && TREE_CODE (olddecl) == FUNCTION_DECL
@@ -7333,7 +7348,48 @@
   if (IDENTIFIER_OPNAME_P (DECL_NAME (decl))
       && !grok_op_properties (decl, /*complain=*/true))
     return NULL_TREE;
+  else if (UDLIT_OPER_P (DECL_NAME (decl)))
+    {
+      bool long_long_unsigned_p;
+      bool long_double_p;
+      const char *suffix = NULL;
+      /* [over.literal]/6: Literal operators shall not have C linkage. */
+      if (DECL_LANGUAGE(decl) == lang_c)
+	{
+	  error ("literal operator with C linkage");
+	  return NULL_TREE;
+	}
 
+      if (DECL_NAMESPACE_SCOPE_P (decl))
+	{
+	  if (!check_literal_operator_args(decl,
+					   &long_long_unsigned_p, &long_double_p))
+	    {
+	      error ("%qD has invalid argument list", decl);
+	      return NULL_TREE;
+	    }
+
+	  suffix = UDLIT_OP_SUFFIX (DECL_NAME (decl));
+	  if (long_long_unsigned_p)
+	    {
+	      if (cpp_interpret_int_suffix (suffix, strlen (suffix)))
+		warning (0, "integer suffix %<%s%>"
+			    " shadowed by implementation", suffix);
+	    }
+	  else if (long_double_p)
+	    {
+	      if (cpp_interpret_float_suffix (suffix, strlen (suffix)))
+		warning (0, "floating point suffix %<%s%>"
+			    " shadowed by implementation", suffix);
+	    }
+	}
+      else
+	{
+	  error ("%qD must be a non-member function", decl);
+	  return NULL_TREE;
+	}
+    }
+
   if (funcdef_flag)
     /* Make the init_value nonzero so pushdecl knows this is not
        tentative.  error_mark_node is replaced later with the BLOCK.  */
@@ -8518,6 +8574,15 @@
       error ("declaration of %qD as non-function", dname);
       return error_mark_node;
     }
+ 
+  if (dname
+      && TREE_CODE (dname) == IDENTIFIER_NODE
+      && UDLIT_OPER_P (dname)
+      && innermost_code != cdk_function)
+    {
+      error ("declaration of %qD as non-function", dname);
+      return error_mark_node;
+    }
 
   if (dname && IDENTIFIER_OPNAME_P (dname))
     {
@@ -13734,6 +13799,7 @@
     case TRAIT_EXPR:		return TS_CP_TRAIT_EXPR;
     case LAMBDA_EXPR:		return TS_CP_LAMBDA_EXPR;
     case TEMPLATE_INFO:		return TS_CP_TEMPLATE_INFO;
+    case USERDEF_LITERAL:	return TS_CP_USERDEF_LITERAL;
     default:			return TS_CP_GENERIC;
     }
 }
Index: gcc/cp/error.c
===================================================================
--- gcc/cp/error.c	(revision 179328)
+++ gcc/cp/error.c	(working copy)
@@ -1534,6 +1534,8 @@
     }
   else if (name && IDENTIFIER_OPNAME_P (name))
     pp_cxx_tree_identifier (cxx_pp, name);
+  else if (name && UDLIT_OPER_P (name))
+    pp_cxx_tree_identifier (cxx_pp, name);
   else
     dump_decl (name, flags);
 
@@ -1756,6 +1758,10 @@
       pp_constant (cxx_pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (cxx_pp, t);
+      break;
+
     case THROW_EXPR:
       /* While waiting for caret diagnostics, avoid printing
 	 __cxa_allocate_exception, __cxa_throw, and the like.  */
@@ -3231,7 +3237,7 @@
 	pedwarn (input_location, OPT_pedantic,
 		 "inline namespaces "
 		 "only available with -std=c++0x or -std=gnu++0x");
-	break;	
+	break;
       case CPP0X_OVERRIDE_CONTROLS:
 	pedwarn (input_location, 0,
 		 "override controls (override/final) "
@@ -3242,8 +3248,13 @@
 		 "non-static data member initializers "
 		 "only available with -std=c++0x or -std=gnu++0x");
         break;
+      case CPP0X_USER_DEFINED_LITERALS:
+	pedwarn (input_location, 0,
+		 "user-defined literals "
+		 "only available with -std=c++0x or -std=gnu++0x");
+	break;
       default:
-	gcc_unreachable();
+	gcc_unreachable ();
       }
 }
 
Index: gcc/cp/cxx-pretty-print.c
===================================================================
--- gcc/cp/cxx-pretty-print.c	(revision 179328)
+++ gcc/cp/cxx-pretty-print.c	(working copy)
@@ -367,6 +367,17 @@
     pp_cxx_unqualified_id (pp, t);
 }
 
+/* user-defined literal:
+      literal ud-suffix  */
+
+void
+pp_cxx_userdef_literal (cxx_pretty_printer *pp, tree t)
+{
+  pp_cxx_constant (pp, USERDEF_LITERAL_VALUE (t));
+  pp_cxx_id_expression (pp, USERDEF_LITERAL_SUFFIX_ID (t));
+}
+
+
 /* primary-expression:
      literal
      this
@@ -413,6 +424,10 @@
       pp_cxx_constant (pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (pp, t);
+      break;
+
     case BASELINK:
       t = BASELINK_FUNCTIONS (t);
     case VAR_DECL:
@@ -1023,6 +1038,10 @@
       pp_cxx_constant (pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (pp, t);
+      break;
+
     case RESULT_DECL:
       pp_cxx_unqualified_id (pp, t);
       break;
Index: gcc/cp/semantics.c
===================================================================
--- gcc/cp/semantics.c	(revision 179328)
+++ gcc/cp/semantics.c	(working copy)
@@ -7748,6 +7748,7 @@
     case TEMPLATE_PARM_INDEX:
     case TRAIT_EXPR:
     case IDENTIFIER_NODE:
+    case USERDEF_LITERAL:
       /* We can see a FIELD_DECL in a pointer-to-member expression.  */
     case FIELD_DECL:
     case PARM_DECL:
Index: gcc/cp/cxx-pretty-print.h
===================================================================
--- gcc/cp/cxx-pretty-print.h	(revision 179328)
+++ gcc/cp/cxx-pretty-print.h	(working copy)
@@ -74,5 +74,7 @@
 void pp_cxx_trait_expression (cxx_pretty_printer *, tree);
 void pp_cxx_va_arg_expression (cxx_pretty_printer *, tree);
 void pp_cxx_offsetof_expression (cxx_pretty_printer *, tree);
+void pp_cxx_userdef_literal (cxx_pretty_printer *, tree);
 
+
 #endif /* GCC_CXX_PRETTY_PRINT_H */
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 179328)
+++ gcc/cp/parser.c	(working copy)
@@ -210,6 +210,8 @@
   (cp_lexer *);
 static void cp_lexer_rollback_tokens
   (cp_lexer *);
+static tree cp_literal_operator_id
+  (const char *);
 #ifdef ENABLE_CHECKING
 static void cp_lexer_print_token
   (FILE *, cp_token *);
@@ -501,20 +503,20 @@
 	}
       else
 	{
-          if (warn_cxx0x_compat
-              && C_RID_CODE (token->u.value) >= RID_FIRST_CXX0X
-              && C_RID_CODE (token->u.value) <= RID_LAST_CXX0X)
-            {
-              /* Warn about the C++0x keyword (but still treat it as
-                 an identifier).  */
-              warning (OPT_Wc__0x_compat, 
-                       "identifier %qE will become a keyword in C++0x",
-                       token->u.value);
+	  if (warn_cxx0x_compat
+	      && C_RID_CODE (token->u.value) >= RID_FIRST_CXX0X
+	      && C_RID_CODE (token->u.value) <= RID_LAST_CXX0X)
+	    {
+	      /* Warn about the C++0x keyword (but still treat it as
+		 an identifier).  */
+	      warning (OPT_Wc__0x_compat, 
+		       "identifier %qE will become a keyword in C++0x",
+		       token->u.value);
 
-              /* Clear out the C_RID_CODE so we don't warn about this
-                 particular identifier-turned-keyword again.  */
-              C_SET_RID_CODE (token->u.value, RID_MAX);
-            }
+	      /* Clear out the C_RID_CODE so we don't warn about this
+		 particular identifier-turned-keyword again.  */
+	      C_SET_RID_CODE (token->u.value, RID_MAX);
+	    }
 
 	  token->ambiguous_p = false;
 	  token->keyword = RID_MAX;
@@ -1531,6 +1533,12 @@
   (cp_parser *);
 static tree cp_parser_string_literal
   (cp_parser *, bool, bool);
+static tree cp_parser_userdef_char_literal
+  (cp_parser *);
+static tree cp_parser_userdef_string_literal
+  (cp_token *);
+static tree cp_parser_userdef_numeric_literal
+  (cp_parser *);
 
 /* Basic concepts [gram.basic]  */
 
@@ -2039,6 +2047,8 @@
   (cp_parser *);
 static bool cp_parser_allow_gnu_extensions_p
   (cp_parser *);
+static bool cp_parser_is_pure_string_literal
+  (cp_token *);
 static bool cp_parser_is_string_literal
   (cp_token *);
 static bool cp_parser_is_keyword
@@ -2059,7 +2069,7 @@
 /* Returns nonzero if TOKEN is a string literal.  */
 
 static bool
-cp_parser_is_string_literal (cp_token* token)
+cp_parser_is_pure_string_literal (cp_token* token)
 {
   return (token->type == CPP_STRING ||
 	  token->type == CPP_STRING16 ||
@@ -2068,6 +2078,20 @@
 	  token->type == CPP_UTF8STRING);
 }
 
+/* Returns nonzero if TOKEN is a string literal
+   of a user-defined string literal.  */
+
+static bool
+cp_parser_is_string_literal (cp_token* token)
+{
+  return (cp_parser_is_pure_string_literal (token) ||
+	  token->type == CPP_STRING_USERDEF ||
+	  token->type == CPP_STRING16_USERDEF ||
+	  token->type == CPP_STRING32_USERDEF ||
+	  token->type == CPP_WSTRING_USERDEF ||
+	  token->type == CPP_UTF8STRING_USERDEF);
+}
+
 /* Returns nonzero if TOKEN is the indicated KEYWORD.  */
 
 static bool
@@ -3107,7 +3131,11 @@
   struct obstack str_ob;
   cpp_string str, istr, *strs;
   cp_token *tok;
-  enum cpp_ttype type;
+  enum cpp_ttype type, curr_type;
+  int have_suffix_p = 0;
+  tree string_tree;
+  tree suffix_id = NULL_TREE;
+  bool curr_tok_is_userdef_p = false;
 
   tok = cp_lexer_peek_token (parser->lexer);
   if (!cp_parser_is_string_literal (tok))
@@ -3116,7 +3144,18 @@
       return error_mark_node;
     }
 
-  type = tok->type;
+  if (cpp_userdef_string_p (tok->type))
+    {
+      string_tree = USERDEF_LITERAL_VALUE (tok->u.value);
+      curr_type = cpp_userdef_string_remove_type (tok->type);
+      curr_tok_is_userdef_p = true;
+    }
+  else
+    {
+      string_tree = tok->u.value;
+      curr_type = tok->type;
+    }
+  type = curr_type;
 
   /* Try to avoid the overhead of creating and destroying an obstack
      for the common case of just one string.  */
@@ -3125,10 +3164,19 @@
     {
       cp_lexer_consume_token (parser->lexer);
 
-      str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value);
-      str.len = TREE_STRING_LENGTH (tok->u.value);
+      str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree);
+      str.len = TREE_STRING_LENGTH (string_tree);
       count = 1;
 
+      if (curr_tok_is_userdef_p)
+	{
+	  suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value);
+	  have_suffix_p = 1;
+	  curr_type = cpp_userdef_string_remove_type (tok->type);
+	}
+      else
+	curr_type = tok->type;
+
       strs = &str;
     }
   else
@@ -3140,14 +3188,35 @@
 	{
 	  cp_lexer_consume_token (parser->lexer);
 	  count++;
-	  str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value);
-	  str.len = TREE_STRING_LENGTH (tok->u.value);
+	  str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree);
+	  str.len = TREE_STRING_LENGTH (string_tree);
 
-	  if (type != tok->type)
+	  if (curr_tok_is_userdef_p)
 	    {
+	      tree curr_suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value);
+	      if (have_suffix_p == 0)
+		{
+		  suffix_id = curr_suffix_id;
+		  have_suffix_p = 1;
+		}
+	      else if (have_suffix_p == 1
+		       && curr_suffix_id != suffix_id)
+		{
+		  error ("inconsistent user-defined literal suffixes"
+			 " %qD and %qD in string literal",
+			 suffix_id, curr_suffix_id);
+		  have_suffix_p = -1;
+		}
+	      curr_type = cpp_userdef_string_remove_type (tok->type);
+	    }
+	  else
+	    curr_type = tok->type;
+
+	  if (type != curr_type)
+	    {
 	      if (type == CPP_STRING)
-		type = tok->type;
-	      else if (tok->type != CPP_STRING)
+		type = curr_type;
+	      else if (curr_type != CPP_STRING)
 		error_at (tok->location,
 			  "unsupported non-standard concatenation "
 			  "of string literals");
@@ -3156,6 +3225,18 @@
 	  obstack_grow (&str_ob, &str, sizeof (cpp_string));
 
 	  tok = cp_lexer_peek_token (parser->lexer);
+	  if (cpp_userdef_string_p (tok->type))
+	    {
+	      string_tree = USERDEF_LITERAL_VALUE (tok->u.value);
+	      curr_type = cpp_userdef_string_remove_type (tok->type);
+	      curr_tok_is_userdef_p = true;
+	    }
+	  else
+	    {
+	      string_tree = tok->u.value;
+	      curr_type = tok->type;
+	      curr_tok_is_userdef_p = false;
+	    }
 	}
       while (cp_parser_is_string_literal (tok));
 
@@ -3193,6 +3274,13 @@
 	}
 
       value = fix_string_type (value);
+
+      if (have_suffix_p)
+	{
+	  tree literal = build_userdef_literal (suffix_id, value, NULL_TREE);
+	  tok->u.value = literal;
+	  return cp_parser_userdef_string_literal (tok);
+	}
     }
   else
     /* cpp_interpret_string has issued an error.  */
@@ -3204,7 +3292,184 @@
   return value;
 }
 
+/* Parse a user-defined char constant.  Returns a call to a user-defined
+   literal operator taking the character as an argument.  */
 
+static tree
+cp_parser_userdef_char_literal (cp_parser *parser)
+{
+  cp_token *token = NULL;
+  tree literal, suffix_id, value;
+  tree name, decl;
+  tree result;
+  VEC(tree,gc) *vec;
+
+  token = cp_lexer_consume_token (parser->lexer);
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  value = USERDEF_LITERAL_VALUE (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  vec = make_tree_vector ();
+  VEC_safe_push (tree, gc, vec, value);
+  decl = lookup_function_nonclass (name, vec, /*block_p=*/false);
+  if (!decl || decl == error_mark_node)
+    {
+      error ("unable to find user-defined character literal operator %qD",
+	     name);
+      release_tree_vector (vec);
+      return error_mark_node;
+    }
+  result = finish_call_expr (decl, &vec, false, true, tf_warning_or_error);
+  release_tree_vector (vec);
+
+  return result;
+}
+
+/* A subroutine of cp_parser_userdef_numeric_literal to
+   create a char... template parameter pack from a string node.  */
+
+static tree
+make_char_string_pack (tree value)
+{
+  tree parmvec;
+  tree argpack = make_node (NONTYPE_ARGUMENT_PACK);
+  const char *str = TREE_STRING_POINTER (value);
+  int i, len = TREE_STRING_LENGTH (value);
+  /*  Do I need to stuff THIS into a tree? */
+  tree argvec = make_tree_vec (1);
+
+  /* Fill in PARMVEC with all of the parameters.  */
+  parmvec = make_tree_vec (len);
+  for (i = 0; i < len; ++i)
+    TREE_VEC_ELT (parmvec, i) = build_int_cst (char_type_node, str[i]);
+
+  /* Build the argument packs.  */
+  SET_ARGUMENT_PACK_ARGS (argpack, parmvec);
+  TREE_TYPE (argpack) = char_type_node;
+
+  /*  Do I need to stuff THIS into a tree? */
+  TREE_VEC_ELT (argvec, 0) = argpack;
+
+  return argvec;
+}
+
+/* Parse a user-defined numeric constant.  returns a call to a user-defined
+   literal operator.  */
+static tree
+cp_parser_userdef_numeric_literal (cp_parser *parser)
+{
+  cp_token *token = NULL;
+  tree literal, suffix_id, value, num_string;
+  tree name, decl;
+  tree result = error_mark_node;
+  VEC(tree,gc) *args;
+
+  token = cp_lexer_consume_token (parser->lexer);
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  value = USERDEF_LITERAL_VALUE (literal);
+  num_string = USERDEF_LITERAL_NUM_STRING (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  /* Try to find the literal operator by finishing the call expression
+     with the numeric argument.  */
+  args = make_tree_vector ();
+  VEC_safe_push (tree, gc, args, value);
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl && decl != error_mark_node)
+    {
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  /* If the numeric argument didn't work, look for a raw literal
+     operator taking a const char* argument consisting of the number
+     in string format.  */
+  args = make_tree_vector ();
+  VEC_safe_push (tree, gc, args, num_string);
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl && decl != error_mark_node)
+    {
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  /* If the raw literal didn't work, look for a non-type template
+     function with parameter pack char....  Call the function with
+     template parameter characters representing the number.  */
+  args = make_tree_vector ();
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl && decl != error_mark_node)
+    {
+      tree tmpl_args = make_char_string_pack (num_string);
+      decl = lookup_template_function (decl, tmpl_args);
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  if (result == error_mark_node)
+    error ("unable to find user-defined numeric literal operator %qD", name);
+
+  return result;
+}
+
+/* Parse a user-defined string constant.  Returns a call to a user-defined
+   literal operator taking a character pointer and the length of the string
+   as arguments.  */
+static tree
+cp_parser_userdef_string_literal (cp_token *token)
+{
+  tree literal, suffix_id, value;
+  tree name, decl;
+  tree result;
+  VEC(tree,gc) *vec;
+  int len;
+
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+  value = USERDEF_LITERAL_VALUE (literal);
+  len = TREE_STRING_LENGTH (value) - 1;
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  vec = make_tree_vector ();
+  VEC_safe_push (tree, gc, vec, value);
+  VEC_safe_push (tree, gc, vec, build_int_cst (size_type_node, len));
+  decl = lookup_function_nonclass (name, vec, /*block_p=*/false);
+  if (!decl || decl == error_mark_node)
+    {
+      error ("unable to find user-defined string literal operator %qD", name);
+      release_tree_vector (vec);
+      return error_mark_node;
+    }
+  result = finish_call_expr (decl, &vec, false, true, tf_warning_or_error);
+  release_tree_vector (vec);
+
+  return result;
+}
+
+
 /* Basic concepts [gram.basic]  */
 
 /* Parse a translation-unit.
@@ -3347,12 +3612,16 @@
 	   character-literal
 	   floating-literal
 	   string-literal
-	   boolean-literal  */
+	   boolean-literal
+	   pointer-literal
+	   user-defined-literal  */
     case CPP_CHAR:
     case CPP_CHAR16:
     case CPP_CHAR32:
     case CPP_WCHAR:
     case CPP_NUMBER:
+      if (TREE_CODE (token->u.value) == USERDEF_LITERAL)
+	return cp_parser_userdef_numeric_literal (parser);
       token = cp_lexer_consume_token (parser->lexer);
       if (TREE_CODE (token->u.value) == FIXED_CST)
 	{
@@ -3406,11 +3675,22 @@
 	}
       return token->u.value;
 
+    case CPP_CHAR_USERDEF:
+    case CPP_CHAR16_USERDEF:
+    case CPP_CHAR32_USERDEF:
+    case CPP_WCHAR_USERDEF:
+      return cp_parser_userdef_char_literal (parser);
+
     case CPP_STRING:
     case CPP_STRING16:
     case CPP_STRING32:
     case CPP_WSTRING:
     case CPP_UTF8STRING:
+    case CPP_STRING_USERDEF:
+    case CPP_STRING16_USERDEF:
+    case CPP_STRING32_USERDEF:
+    case CPP_WSTRING_USERDEF:
+    case CPP_UTF8STRING_USERDEF:
       /* ??? Should wide strings be allowed when parser->translate_strings_p
 	 is false (i.e. in attributes)?  If not, we can kill the third
 	 argument to cp_parser_string_literal.  */
@@ -4888,7 +5168,7 @@
 	/* Restore the saved message.  */
 	parser->type_definition_forbidden_message = saved_message;
 	/* `typeid' may not appear in an integral constant expression.  */
-	if (cp_parser_non_integral_constant_expression(parser, NIC_TYPEID))
+	if (cp_parser_non_integral_constant_expression (parser, NIC_TYPEID))
 	  return error_mark_node;
       }
       break;
@@ -9471,7 +9751,7 @@
   /* If the next token is `extern' and the following token is a string
      literal, then we have a linkage specification.  */
   if (token1.keyword == RID_EXTERN
-      && cp_parser_is_string_literal (&token2))
+      && cp_parser_is_pure_string_literal (&token2))
     cp_parser_linkage_specification (parser);
   /* If the next token is `template', then we have either a template
      declaration, an explicit instantiation, or an explicit
@@ -10902,6 +11182,22 @@
   return cp_parser_operator (parser);
 }
 
+/* Return an identifier node for a user-defined literal operator.
+   The suffix identifier is chained to the operator name identifier.  */
+
+static tree
+cp_literal_operator_id (const char* name)
+{
+  tree identifier;
+  char *buffer = XNEWVEC (char, strlen (UDLIT_OP_ANSI_PREFIX)
+			      + strlen (name) + 10);
+  sprintf (buffer, UDLIT_OP_ANSI_FORMAT, name);
+  identifier = get_identifier (buffer);
+  /*IDENTIFIER_UDLIT_OPNAME_P (identifier) = 1; If we get a flag someday. */
+
+  return identifier;
+}
+
 /* Parse an operator.
 
    operator:
@@ -11121,6 +11417,35 @@
       cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE);
       return ansi_opname (ARRAY_REF);
 
+    case CPP_STRING:
+      if (cxx_dialect == cxx98)
+	maybe_warn_cpp0x (CPP0X_USER_DEFINED_LITERALS);
+      if (TREE_STRING_LENGTH (token->u.value) > 2)
+	{
+	  error ("expected empty string after %<operator%> keyword");
+	  return error_mark_node;
+	}
+      /* Consume the string.  */
+      cp_lexer_consume_token (parser->lexer);
+      /* Look for an identifier.  */
+      id = cp_parser_identifier (parser);
+      if (id != error_mark_node)
+	{
+	  const char *name = IDENTIFIER_POINTER (id);
+
+	  /* 17.6.3.3.5  */
+	  if (name[0] != '_' && !in_system_header)
+	    warning (0, "suffixes not preceded by %<_%> "
+			"are reserved for future standardization");
+
+	  return cp_literal_operator_id(name);
+	}
+      else
+	{
+	  error ("expected suffix identifier");
+	  return error_mark_node;
+	}
+
     default:
       /* Anything else is an error.  */
       break;
@@ -20304,6 +20629,32 @@
   /* Finish up.  */
   finish_template_decl (parameter_list);
 
+  /* Check the template arguments for a user-defined literal operator template.  */
+  if (decl
+      && (TREE_CODE (decl) == FUNCTION_DECL || DECL_FUNCTION_TEMPLATE_P (decl))
+      && UDLIT_OPER_P (DECL_NAME (decl)))
+    {
+      bool ok = true;
+      if (parameter_list == NULL_TREE)
+	ok = false;
+      else
+	{
+	  int num_parms = TREE_VEC_LENGTH (parameter_list);
+	  if (num_parms != 1)
+	    ok = false;
+	  else
+	    {
+	      tree parm_list = TREE_VEC_ELT (parameter_list, 0);
+	      tree parm = INNERMOST_TEMPLATE_PARMS (parm_list);
+	      if (TREE_TYPE (parm) != char_type_node
+		  || !TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (parm)))
+		ok = false;
+	    }
+	}
+      if (!ok)
+	error ("user-defined literal operator template %qD"
+	       " has invalid parameter list", decl);
+    }
   /* Register member declarations.  */
   if (member_p && !friend_p && decl && !DECL_CLASS_TEMPLATE_P (decl))
     finish_member_declaration (decl);
@@ -22605,7 +22956,8 @@
   /* If the next token is `extern' and the following token is a string
      literal, then we have a linkage specification.  */
   if (token->keyword == RID_EXTERN
-      && cp_parser_is_string_literal (cp_lexer_peek_nth_token (parser->lexer, 2)))
+      && cp_parser_is_pure_string_literal
+	 (cp_lexer_peek_nth_token (parser->lexer, 2)))
     cp_parser_linkage_specification (parser);
   /* Handle #pragma, if any.  */
   else if (token->type == CPP_PRAGMA)
Index: gcc/cp/cp-objcp-common.c
===================================================================
--- gcc/cp/cp-objcp-common.c	(revision 179328)
+++ gcc/cp/cp-objcp-common.c	(working copy)
@@ -100,6 +100,8 @@
 
     case TEMPLATE_INFO:         return sizeof (struct tree_template_info);
 
+    case USERDEF_LITERAL:	return sizeof (struct tree_userdef_literal);
+
     default:
       gcc_unreachable ();
     }
Index: gcc/cp/mangle.c
===================================================================
--- gcc/cp/mangle.c	(revision 179328)
+++ gcc/cp/mangle.c	(working copy)
@@ -181,6 +181,7 @@
 static void write_unqualified_name (const tree);
 static void write_conversion_operator_name (const tree);
 static void write_source_name (tree);
+static void write_literal_operator_name (tree);
 static void write_unnamed_type_name (const tree);
 static void write_closure_type_name (const tree);
 static int hwint_to_ascii (unsigned HOST_WIDE_INT, const unsigned int, char *,
@@ -1174,6 +1175,8 @@
 	  }
       write_string (mangled_name);
     }
+  else if (UDLIT_OPER_P (identifier))
+    write_literal_operator_name (identifier);
   else
     write_source_name (identifier);
 }
@@ -1227,6 +1230,8 @@
 
 	  write_string (oni[DECL_OVERLOADED_OPERATOR_P (decl)].mangled_name);
 	}
+      else if (UDLIT_OPER_P (DECL_NAME (decl)))
+	write_literal_operator_name (DECL_NAME (decl));
       else
 	found = false;
 
@@ -1286,6 +1291,21 @@
   write_identifier (IDENTIFIER_POINTER (identifier));
 }
 
+/* Write a user-defined literal operator.
+   IDENTIFIER is an LITERAL_IDENTIFIER_NODE.  */
+
+static void
+write_literal_operator_name (tree identifier)
+{
+  const char* suffix = UDLIT_OP_SUFFIX (identifier);
+  char* buffer = XNEWVEC (char, strlen (UDLIT_OP_MANGLED_PREFIX)
+			      + strlen (suffix) + 10);
+  sprintf (buffer, UDLIT_OP_MANGLED_FORMAT, suffix);
+
+  write_unsigned_number (strlen (buffer));
+  write_identifier (buffer);
+}
+
 /* Encode 0 as _, and 1+ as n-1_.  */
 
 static void
Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h	(revision 179328)
+++ gcc/cp/cp-tree.h	(working copy)
@@ -396,7 +396,9 @@
   /* override controls, override/final */
   CPP0X_OVERRIDE_CONTROLS,
   /* non-static data member initializers */
-  CPP0X_NSDMI
+  CPP0X_NSDMI,
+  /* user defined literals */
+  CPP0X_USER_DEFINED_LITERALS
 } cpp0x_warn_str;
   
 /* The various kinds of operation used by composite_pointer_type. */
@@ -727,6 +729,7 @@
   TS_CP_TRAIT_EXPR,
   TS_CP_LAMBDA_EXPR,
   TS_CP_TEMPLATE_INFO,
+  TS_CP_USERDEF_LITERAL,
   LAST_TS_CP_ENUM
 };
 
@@ -752,6 +755,8 @@
     lambda_expression;
   struct tree_template_info GTY ((tag ("TS_CP_TEMPLATE_INFO")))
     template_info;
+  struct tree_userdef_literal GTY ((tag ("TS_CP_USERDEF_LITERAL")))
+    userdef_literal;
 };
 
 \f
@@ -4204,6 +4209,17 @@
              LAMBDANAME_PREFIX, \
 	     sizeof (LAMBDANAME_PREFIX) - 1))
 
+#define UDLIT_OP_ANSI_PREFIX "operator\"\" "
+#define UDLIT_OP_ANSI_FORMAT UDLIT_OP_ANSI_PREFIX "%s"
+#define UDLIT_OP_MANGLED_PREFIX "li"
+#define UDLIT_OP_MANGLED_FORMAT UDLIT_OP_MANGLED_PREFIX "%s"
+#define UDLIT_OPER_P(ID_NODE) \
+  (!strncmp (IDENTIFIER_POINTER (ID_NODE), \
+             UDLIT_OP_ANSI_PREFIX, \
+	     sizeof (UDLIT_OP_ANSI_PREFIX) - 1))
+#define UDLIT_OP_SUFFIX(ID_NODE) \
+  (IDENTIFIER_POINTER (ID_NODE) + sizeof (UDLIT_OP_ANSI_PREFIX) - 1)
+
 #if !defined(NO_DOLLAR_IN_LABEL) || !defined(NO_DOT_IN_LABEL)
 
 #define VTABLE_NAME_P(ID_NODE) (IDENTIFIER_POINTER (ID_NODE)[1] == 'v' \
@@ -5728,6 +5744,7 @@
 extern int lvalue_or_else			(tree, enum lvalue_use,
                                                  tsubst_flags_t);
 extern void check_template_keyword		(tree);
+extern bool check_literal_operator_args		(const_tree, bool *, bool *);
 
 /* in typeck2.c */
 extern void require_complete_eh_spec_types	(tree, tree);
Index: libcpp/include/cpplib.h
===================================================================
--- libcpp/include/cpplib.h	(revision 179328)
+++ libcpp/include/cpplib.h	(working copy)
@@ -131,6 +131,16 @@
   TK(OBJC_STRING,	LITERAL) /* @"string" - Objective-C */		\
   TK(HEADER_NAME,	LITERAL) /* <stdio.h> in #include */		\
 									\
+  TK(CHAR_USERDEF,	LITERAL) /* 'char'_suffix - C++-0x */		\
+  TK(WCHAR_USERDEF,	LITERAL) /* L'char'_suffix - C++-0x */		\
+  TK(CHAR16_USERDEF,	LITERAL) /* u'char'_suffix - C++-0x */		\
+  TK(CHAR32_USERDEF,	LITERAL) /* U'char'_suffix - C++-0x */		\
+  TK(STRING_USERDEF,	LITERAL) /* "string"_suffix - C++-0x */		\
+  TK(WSTRING_USERDEF,	LITERAL) /* L"string"_suffix - C++-0x */	\
+  TK(STRING16_USERDEF,	LITERAL) /* u"string"_suffix - C++-0x */	\
+  TK(STRING32_USERDEF,	LITERAL) /* U"string"_suffix - C++-0x */	\
+  TK(UTF8STRING_USERDEF,LITERAL) /* u8"string"_suffix - C++-0x */	\
+									\
   TK(COMMENT,		LITERAL) /* Only if output comments.  */	\
 				 /* SPELL_LITERAL happens to DTRT.  */	\
   TK(MACRO_ARG,		NONE)	 /* Macro argument.  */			\
@@ -402,6 +412,9 @@
   /* True for traditional preprocessing.  */
   unsigned char traditional;
 
+  /* Nonzero for the 2011 C++ Standard.  */
+  unsigned char cxx11;
+
   /* Holds the name of the target (execution) character set.  */
   const char *narrow_charset;
 
@@ -817,13 +830,22 @@
 #define CPP_N_FRACT	0x100000 /* Fract types.  */
 #define CPP_N_ACCUM	0x200000 /* Accum types.  */
 
+#define CPP_N_USERDEF	0x1000000 /* C++0x user-defined literal.  */
+
 /* Classify a CPP_NUMBER token.  The return value is a combination of
    the flags from the above sets.  */
-extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *);
+extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *,
+				     const char **);
 
+/* Return the classification flags for a float suffix.  */
+extern unsigned int cpp_interpret_float_suffix (const char *, size_t);
+
+/* Return the classification flags for an int suffix.  */
+extern unsigned int cpp_interpret_int_suffix (const char *, size_t);
+
 /* Evaluate a token classified as category CPP_N_INTEGER.  */
 extern cpp_num cpp_interpret_integer (cpp_reader *, const cpp_token *,
-				      unsigned int type);
+				      unsigned int);
 
 /* Sign extend a number, with PRECISION significant bits and all
    others assumed clear, to fill out a cpp_num structure.  */
@@ -993,4 +1015,20 @@
 extern void cpp_force_token_locations (cpp_reader *, source_location *);
 extern void cpp_stop_forcing_token_locations (cpp_reader *);
 
+/* In expr.c */
+extern enum cpp_ttype cpp_userdef_string_remove_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_string_add_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_char_remove_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_char_add_type
+  (enum cpp_ttype type);
+extern bool cpp_userdef_string_p
+  (enum cpp_ttype type);
+extern bool cpp_userdef_char_p
+  (enum cpp_ttype type);
+extern const char * cpp_get_userdef_suffix
+  (const cpp_token *);
+
 #endif /* ! LIBCPP_CPPLIB_H */
Index: libcpp/init.c
===================================================================
--- libcpp/init.c	(revision 179328)
+++ libcpp/init.c	(working copy)
@@ -80,22 +80,23 @@
   char digraphs;
   char uliterals;
   char rliterals;
+  char cxx11;
 };
 
 static const struct lang_flags lang_defaults[] =
-{ /*              c99 c++ xnum xid std  //   digr ulit rlit */
-  /* GNUC89   */  { 0,  0,  1,   0,  0,   1,   1,   0,   0 },
-  /* GNUC99   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1 },
-  /* GNUC1X   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1 },
-  /* STDC89   */  { 0,  0,  0,   0,  1,   0,   0,   0,   0 },
-  /* STDC94   */  { 0,  0,  0,   0,  1,   0,   1,   0,   0 },
-  /* STDC99   */  { 1,  0,  1,   0,  1,   1,   1,   0,   0 },
-  /* STDC1X   */  { 1,  0,  1,   0,  1,   1,   1,   1,   0 },
-  /* GNUCXX   */  { 0,  1,  1,   0,  0,   1,   1,   0,   0 },
-  /* CXX98    */  { 0,  1,  1,   0,  1,   1,   1,   0,   0 },
-  /* GNUCXX0X */  { 1,  1,  1,   0,  0,   1,   1,   1,   1 },
-  /* CXX0X    */  { 1,  1,  1,   0,  1,   1,   1,   1,   1 },
-  /* ASM      */  { 0,  0,  1,   0,  0,   1,   0,   0,   0 }
+{ /*              c99 c++ xnum xid std  //   digr ulit rlit cxx11 */
+  /* GNUC89   */  { 0,  0,  1,   0,  0,   1,   1,   0,   0,    0 },
+  /* GNUC99   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1,    0 },
+  /* GNUC1X   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1,    0 },
+  /* STDC89   */  { 0,  0,  0,   0,  1,   0,   0,   0,   0,    0 },
+  /* STDC94   */  { 0,  0,  0,   0,  1,   0,   1,   0,   0,    0 },
+  /* STDC99   */  { 1,  0,  1,   0,  1,   1,   1,   0,   0,    0 },
+  /* STDC1X   */  { 1,  0,  1,   0,  1,   1,   1,   1,   0,    0 },
+  /* GNUCXX   */  { 0,  1,  1,   0,  0,   1,   1,   0,   0,    0 },
+  /* CXX98    */  { 0,  1,  1,   0,  1,   1,   1,   0,   0,    0 },
+  /* GNUCXX0X */  { 1,  1,  1,   0,  0,   1,   1,   1,   1,    1 },
+  /* CXX0X    */  { 1,  1,  1,   0,  1,   1,   1,   1,   1,    1 },
+  /* ASM      */  { 0,  0,  1,   0,  0,   1,   0,   0,   0,    0 }
   /* xid should be 1 for GNUC99, STDC99, GNUCXX, CXX98, GNUCXX0X, and
      CXX0X when no longer experimental (when all uses of identifiers
      in the compiler have been audited for correct handling of
@@ -120,6 +121,7 @@
   CPP_OPTION (pfile, digraphs)			 = l->digraphs;
   CPP_OPTION (pfile, uliterals)			 = l->uliterals;
   CPP_OPTION (pfile, rliterals)			 = l->rliterals;
+  CPP_OPTION (pfile, cxx11)			 = l->cxx11;
 }
 
 /* Initialize library global state.  */
Index: libcpp/expr.c
===================================================================
--- libcpp/expr.c	(revision 179328)
+++ libcpp/expr.c	(working copy)
@@ -1,6 +1,6 @@
 /* Parse C expressions for cpplib.
    Copyright (C) 1987, 1992, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
-   2002, 2004, 2008, 2009, 2010 Free Software Foundation.
+   2002, 2004, 2008, 2009, 2010, 2011 Free Software Foundation.
    Contributed by Per Bothner, 1994.
 
 This program is free software; you can redistribute it and/or modify it
@@ -185,6 +185,13 @@
 	     q ? CPP_N_MD_Q : CPP_N_DEFAULT));
 }
 
+/* Return the classification flags for a float suffix.  */
+unsigned int
+cpp_interpret_float_suffix (const char *s, size_t len)
+{
+  return interpret_float_suffix ((const unsigned char *)s, len);
+}
+
 /* Subroutine of cpp_classify_number.  S points to an integer suffix
    of length LEN, possibly zero. Returns 0 for an invalid suffix, or a
    flag vector describing the suffix.  */
@@ -219,11 +226,143 @@
 	     : (l == 1) ? CPP_N_MEDIUM : CPP_N_LARGE));
 }
 
+/* Return the classification flags for an int suffix.  */
+unsigned int
+cpp_interpret_int_suffix (const char *s, size_t len)
+{
+  return interpret_int_suffix ((const unsigned char *)s, len);
+}
+
+/* Return the string type corresponding to the the input user-defined string
+   literal type.  If the input type is not a user-defined string literal
+   type return the input type.  */
+enum cpp_ttype
+cpp_userdef_string_remove_type (enum cpp_ttype type)
+{
+  if (type == CPP_STRING_USERDEF)
+    return CPP_STRING;
+  else if (type == CPP_WSTRING_USERDEF)
+    return CPP_WSTRING;
+  else if (type == CPP_STRING16_USERDEF)
+    return CPP_STRING16;
+  else if (type == CPP_STRING32_USERDEF)
+    return CPP_STRING32;
+  else if (type == CPP_UTF8STRING_USERDEF)
+    return CPP_UTF8STRING;
+  else
+    return type;
+}
+
+/* Return the user-defined string literal type corresponding to the input
+   string type.  If the input type is not a string type return the input
+   type.  */
+enum cpp_ttype
+cpp_userdef_string_add_type (enum cpp_ttype type)
+{
+  if (type == CPP_STRING)
+    return CPP_STRING_USERDEF;
+  else if (type == CPP_WSTRING)
+    return CPP_WSTRING_USERDEF;
+  else if (type == CPP_STRING16)
+    return CPP_STRING16_USERDEF;
+  else if (type == CPP_STRING32)
+    return CPP_STRING32_USERDEF;
+  else if (type == CPP_UTF8STRING)
+    return CPP_UTF8STRING_USERDEF;
+  else
+    return type;
+}
+
+/* Return the char type corresponding to the the input user-defined char
+   literal type.  If the input type is not a user-defined char literal
+   type return the input type.  */
+enum cpp_ttype
+cpp_userdef_char_remove_type (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR_USERDEF)
+    return CPP_CHAR;
+  else if (type == CPP_WCHAR_USERDEF)
+    return CPP_WCHAR;
+  else if (type == CPP_CHAR16_USERDEF)
+    return CPP_STRING16;
+  else if (type == CPP_CHAR32_USERDEF)
+    return CPP_STRING32;
+  else
+    return type;
+}
+
+/* Return the user-defined char literal type corresponding to the input
+   char type.  If the input type is not a char type return the input
+   type.  */
+enum cpp_ttype
+cpp_userdef_char_add_type (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR)
+    return CPP_CHAR_USERDEF;
+  else if (type == CPP_WCHAR)
+    return CPP_WCHAR_USERDEF;
+  else if (type == CPP_CHAR16)
+    return CPP_CHAR16_USERDEF;
+  else if (type == CPP_CHAR32)
+    return CPP_CHAR32_USERDEF;
+  else
+    return type;
+}
+
+/* Return true if the token type is a user-defined string literal.  */
+bool
+cpp_userdef_string_p (enum cpp_ttype type)
+{
+  if (type == CPP_STRING_USERDEF
+   || type == CPP_WSTRING_USERDEF
+   || type == CPP_STRING16_USERDEF
+   || type == CPP_STRING32_USERDEF
+   || type == CPP_UTF8STRING_USERDEF)
+    return true;
+  else
+    return false;
+}
+
+/* Return true if the token type is a user-defined char literal.  */
+bool
+cpp_userdef_char_p (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR_USERDEF
+   || type == CPP_WCHAR_USERDEF
+   || type == CPP_CHAR16_USERDEF
+   || type == CPP_CHAR32_USERDEF)
+    return true;
+  else
+    return false;
+}
+
+/* Extract the suffix from a user-defined literal string or char.  */
+const char *
+cpp_get_userdef_suffix (const cpp_token *tok)
+{
+  unsigned int len = tok->val.str.len;
+  const char *text = (const char *)tok->val.str.text;
+  char delim;
+  unsigned int i;
+  for (i = 0; i < len; ++i)
+    if (text[i] == '\'' || text[i] == '"')
+      break;
+  if (i == len)
+    return text + len;
+  delim = text[i];
+  for (i = len; i > 0; --i)
+    if (text[i - 1] == delim)
+      break;
+  return text + i;
+}
+
 /* Categorize numeric constants according to their field (integer,
    floating point, or invalid), radix (decimal, octal, hexadecimal),
-   and type suffixes.  */
+   and type suffixes.  In C++0X if UD_SUFFIX is non null it will be
+   assigned any unrecognized suffix for a user-defined literal.  */
 unsigned int
-cpp_classify_number (cpp_reader *pfile, const cpp_token *token)
+cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
+		     const char **ud_suffix)
 {
   const uchar *str = token->val.str.text;
   const uchar *limit;
@@ -231,6 +370,9 @@
   enum {NOT_FLOAT = 0, AFTER_POINT, AFTER_EXPON} float_flag;
   bool seen_digit;
 
+  if (ud_suffix)
+    *ud_suffix = NULL;
+
   /* If the lexer has done its job, length one can only be a single
      digit.  Fast-path this very common case.  */
   if (token->val.str.len == 1)
@@ -361,10 +503,19 @@
       result = interpret_float_suffix (str, limit - str);
       if (result == 0)
 	{
-	  cpp_error (pfile, CPP_DL_ERROR,
-		     "invalid suffix \"%.*s\" on floating constant",
-		     (int) (limit - str), str);
-	  return CPP_N_INVALID;
+	  if (CPP_OPTION (pfile, cxx11))
+	    {
+	      if (ud_suffix)
+		*ud_suffix = (const char *) str;
+	      result = CPP_N_LARGE | CPP_N_USERDEF;
+	    }
+	  else
+	    {
+	      cpp_error (pfile, CPP_DL_ERROR,
+			 "invalid suffix \"%.*s\" on floating constant",
+			 (int) (limit - str), str);
+	      return CPP_N_INVALID;
+	    }
 	}
 
       /* Traditional C didn't accept any floating suffixes.  */
@@ -406,10 +557,19 @@
       result = interpret_int_suffix (str, limit - str);
       if (result == 0)
 	{
-	  cpp_error (pfile, CPP_DL_ERROR,
-		     "invalid suffix \"%.*s\" on integer constant",
-		     (int) (limit - str), str);
-	  return CPP_N_INVALID;
+	  if (CPP_OPTION (pfile, cxx11))
+	    {
+	      if (ud_suffix)
+		*ud_suffix = (const char *) str;
+	      result = CPP_N_UNSIGNED | CPP_N_LARGE | CPP_N_USERDEF;
+	    }
+	  else
+	    {
+	      cpp_error (pfile, CPP_DL_ERROR,
+			 "invalid suffix \"%.*s\" on integer constant",
+			 (int) (limit - str), str);
+	      return CPP_N_INVALID;
+	    }
 	}
 
       /* Traditional C only accepted the 'L' suffix.
@@ -748,7 +908,7 @@
   switch (token->type)
     {
     case CPP_NUMBER:
-      temp = cpp_classify_number (pfile, token);
+      temp = cpp_classify_number (pfile, token, NULL);
       switch (temp & CPP_N_CATEGORY)
 	{
 	case CPP_N_FLOATING:
Index: libcpp/lex.c
===================================================================
--- libcpp/lex.c	(revision 179328)
+++ libcpp/lex.c	(working copy)
@@ -1227,6 +1227,7 @@
   token->type = type;
   token->val.str.len = len;
   token->val.str.text = dest;
+/*printf("\ntoken: %s", token->val.str.text);*/
 }
 
 /* Subroutine of lex_raw_string: Append LEN chars from BASE to the buffer
@@ -1478,6 +1479,18 @@
     }
  break_outer_loop:
 
+  if (CPP_OPTION (pfile, cxx11))
+    {
+      /* Grab user defined literal suffix.  */
+      if (ISIDST(*cur))
+	{
+	  type = cpp_userdef_string_add_type (type);
+	  ++cur;
+	}
+      while (ISIDNUM(*cur))
+	++cur;
+    }
+
   pfile->buffer->cur = cur;
   if (first_buff == NULL)
     create_literal (pfile, token, base, cur - base, type);
@@ -1581,6 +1594,19 @@
     cpp_error (pfile, CPP_DL_PEDWARN, "missing terminating %c character",
 	       (int) terminator);
 
+  if (CPP_OPTION (pfile, cxx11))
+    {
+      /* Grab user defined literal suffix.  */
+      if (ISIDST(*cur))
+	{
+	  type = cpp_userdef_char_add_type (type);
+	  type = cpp_userdef_string_add_type (type);
+          ++cur;
+	}
+      while (ISIDNUM(*cur))
+	++cur;
+    }
+
   pfile->buffer->cur = cur;
   create_literal (pfile, token, base, cur - base, type);
 }

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-09-20  7:23       ` Ed Smith-Rowland
@ 2011-09-20 21:48         ` Jason Merrill
  2011-10-05 15:57           ` Ed Smith-Rowland
  0 siblings, 1 reply; 36+ messages in thread
From: Jason Merrill @ 2011-09-20 21:48 UTC (permalink / raw)
  To: Ed Smith-Rowland; +Cc: gcc-patches

On 09/19/2011 10:07 PM, Ed Smith-Rowland wrote:
> On 09/19/2011 05:11 PM, Jason Merrill wrote:
>> Can't you store the string and the suffix, and then interpret the
>> number later if you end up calling an operator that takes the value?

> I could and I thought abut it but from the wording (2.14.8 p3 and p4) it
> looks like the numeric argument gets first try, then raw literal then
> literal template. I thought I might as well let the preprocessor do the
> numeric conversion since I'll always check it first.

Fair enough.  We could do the overload resolution before we produce the 
actual value to be passed, but I guess that's probably not a sufficient 
optmization to bother with.

> +       error ("user-defined literal operator template %q+D"
> +              " conflicts with user-defined raw literal operator %q+D",
> +              newdecl, olddecl);

You should only use + for one of the decls; that sets the source 
position for the diagnostic.

> +  TK(CHAR_USERDEF,     LITERAL) /* 'char'_suffix - C++-0x */           \
> +  TK(WCHAR_USERDEF,    LITERAL) /* L'char'_suffix - C++-0x */          \
> +  TK(CHAR16_USERDEF,   LITERAL) /* u'char'_suffix - C++-0x */          \
> +  TK(CHAR32_USERDEF,   LITERAL) /* U'char'_suffix - C++-0x */          \
> +  TK(STRING_USERDEF,   LITERAL) /* "string"_suffix - C++-0x */         \
> +  TK(WSTRING_USERDEF,  LITERAL) /* L"string"_suffix - C++-0x */        \
> +  TK(STRING16_USERDEF, LITERAL) /* u"string"_suffix - C++-0x */        \
> +  TK(STRING32_USERDEF, LITERAL) /* U"string"_suffix - C++-0x */        \
> +  TK(UTF8STRING_USERDEF,LITERAL) /* u8"string"_suffix - C++-0x */      \

Could we avoid adding all these additional codes by setting a flag on 
the token?  It seems odd to have extra codes for char/string literals 
but not for numbers.

> +       const char *suffix;
> +       cpp_get_userdef_suffix (tok->val.str, '\'', &suffix);

Let's return the suffix pointer instead of passing in the address of a 
local variable.  And pass in the token pointer rather than the string 
and a delimiter; libcpp can figure out which delimiter to use based on 
the token type.  It could also handle the flag I suggested above so that 
the front end doesn't need to know about it.

Jason

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-09-19 22:43     ` Jason Merrill
@ 2011-09-20  7:23       ` Ed Smith-Rowland
  2011-09-20 21:48         ` Jason Merrill
  0 siblings, 1 reply; 36+ messages in thread
From: Ed Smith-Rowland @ 2011-09-20  7:23 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 940 bytes --]

On 09/19/2011 05:11 PM, Jason Merrill wrote:
> On 09/19/2011 04:22 AM, Ed Smith-Rowland wrote:
>> +check_literal_operator_args( const_tree decl,
>
> Space before the (, not after.
>
Duh.  =:o)
>> Done.  I am now storing the numeric string along with the number and 
>> the suffix ID for numeric operators.  I'm keeping the numeric value 
>> because we need it too.
>
> Can't you store the string and the suffix, and then interpret the 
> number later if you end up calling an operator that takes the value?
I could and I thought abut it but from the wording (2.14.8 p3 and p4) it 
looks like the numeric argument gets first try, then raw literal then 
literal template.  I thought I might as well let the preprocessor do the 
numeric conversion since I'll always check it first.
>
> Jason
>
Also, I put the check in that errors if both a raw literal and a literal 
template share the same name.  That testcase now has dg stuff in it.

Ed



[-- Attachment #2: patch20 --]
[-- Type: text/plain, Size: 68821 bytes --]

Index: gcc/c-family/c-lex.c
===================================================================
--- gcc/c-family/c-lex.c	(revision 178919)
+++ gcc/c-family/c-lex.c	(working copy)
@@ -44,8 +44,8 @@
 int pending_lang_change; /* If we need to switch languages - C++ only */
 int c_header_level;	 /* depth in C headers - C++ only */
 
-static tree interpret_integer (const cpp_token *, unsigned int);
-static tree interpret_float (const cpp_token *, unsigned int);
+static tree interpret_integer (const cpp_token *, unsigned int, const char *);
+static tree interpret_float (const cpp_token *, unsigned int, const char *);
 static tree interpret_fixed (const cpp_token *, unsigned int);
 static enum integer_type_kind narrowest_unsigned_type
 	(unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned int);
@@ -314,7 +314,8 @@
 
     case CPP_NUMBER:
       {
-	unsigned int flags = cpp_classify_number (parse_in, tok);
+	const char *suffix = NULL;
+	unsigned int flags = cpp_classify_number (parse_in, tok, &suffix);
 
 	switch (flags & CPP_N_CATEGORY)
 	  {
@@ -328,16 +329,27 @@
 	       Set PURE_ZERO to pass this information to the C++ parser.  */
 	    if (tok->val.str.len == 1 && *tok->val.str.text == '0')
 	      add_flags = PURE_ZERO;
-	    *value = interpret_integer (tok, flags);
+	    *value = interpret_integer (tok, flags, suffix);
 	    break;
 
 	  case CPP_N_FLOATING:
-	    *value = interpret_float (tok, flags);
+	    *value = interpret_float (tok, flags, suffix);
 	    break;
 
 	  default:
 	    gcc_unreachable ();
 	  }
+
+	if (flags & CPP_N_USERDEF)
+	  {
+	    tree num_string = build_string (tok->val.str.len - strlen (suffix),
+					    (const char *) tok->val.str.text);
+	    TREE_TYPE (num_string) = char_array_type_node;
+	    num_string = fix_string_type (num_string);
+	    tree literal = build_userdef_literal (get_identifier (suffix),
+						  *value, num_string);
+	    *value = literal;
+	  }
       }
       break;
 
@@ -415,6 +427,23 @@
       }
       goto retry;
 
+    case CPP_CHAR_USERDEF:
+    case CPP_WCHAR_USERDEF:
+    case CPP_CHAR16_USERDEF:
+    case CPP_CHAR32_USERDEF:
+      {
+	tree literal;
+	cpp_token temp_tok = *tok;
+	const char *suffix;
+	cpp_get_userdef_suffix (tok->val.str, '\'', &suffix);
+	temp_tok.val.str.len -= strlen (suffix);
+	temp_tok.type = cpp_userdef_char_remove_type (type);
+	literal = build_userdef_literal (get_identifier (suffix),
+					 lex_charconst (&temp_tok), NULL_TREE);
+	*value = literal;
+      }
+      break;
+
     case CPP_CHAR:
     case CPP_WCHAR:
     case CPP_CHAR16:
@@ -422,6 +451,23 @@
       *value = lex_charconst (tok);
       break;
 
+    case CPP_STRING_USERDEF:
+    case CPP_WSTRING_USERDEF:
+    case CPP_STRING16_USERDEF:
+    case CPP_STRING32_USERDEF:
+    case CPP_UTF8STRING_USERDEF:
+      {
+	tree literal, string;
+	const char *suffix;
+	cpp_get_userdef_suffix (tok->val.str, '"', &suffix);
+	string = build_string (tok->val.str.len - strlen (suffix),
+			       (const char *) tok->val.str.text);
+	literal = build_userdef_literal (get_identifier (suffix),
+					 string, NULL_TREE);
+	*value = literal;
+      }
+      break;
+
     case CPP_STRING:
     case CPP_WSTRING:
     case CPP_STRING16:
@@ -536,9 +582,11 @@
   return itk_none;
 }
 
-/* Interpret TOKEN, an integer with FLAGS as classified by cpplib.  */
+/* Interpret TOKEN, an integer with FLAGS as classified by cpplib.
+   For C++0X SUFFIX may contain a user-defined literal suffix.  */
 static tree
-interpret_integer (const cpp_token *token, unsigned int flags)
+interpret_integer (const cpp_token *token, unsigned int flags,
+		   const char *suffix)
 {
   tree value, type;
   enum integer_type_kind itk;
@@ -621,9 +669,10 @@
 }
 
 /* Interpret TOKEN, a floating point number with FLAGS as classified
-   by cpplib.  */
+   by cpplib.  For C++0X SUFFIX may contain a user-defined literal suffix.  */
 static tree
-interpret_float (const cpp_token *token, unsigned int flags)
+interpret_float (const cpp_token *token, unsigned int flags,
+		 const char *suffix)
 {
   tree type;
   tree const_type;
@@ -702,7 +751,9 @@
      has any suffixes, cut them off; REAL_VALUE_ATOF/ REAL_VALUE_HTOF
      can't handle them.  */
   copylen = token->val.str.len;
-  if (flags & CPP_N_DFLOAT)
+  if (flags & CPP_N_USERDEF)
+    copylen -= strlen (suffix);
+  else if (flags & CPP_N_DFLOAT)
     copylen -= 2;
   else
     {
Index: gcc/c-family/c-common.c
===================================================================
--- gcc/c-family/c-common.c	(revision 178919)
+++ gcc/c-family/c-common.c	(working copy)
@@ -9919,4 +9919,17 @@
   MARK_TS_TYPED (EXCESS_PRECISION_EXPR);
 }
 
+/* Build a user-defined numeric literal out of an integer constant type VALUE
+   with identifier SUFFIX.  */
+
+tree
+build_userdef_literal (tree suffix_id, tree value, tree num_string)
+{
+  tree literal = make_node (USERDEF_LITERAL);
+  USERDEF_LITERAL_SUFFIX_ID (literal) = suffix_id;
+  USERDEF_LITERAL_VALUE (literal) = value;
+  USERDEF_LITERAL_NUM_STRING (literal) = num_string;
+  return literal;
+}
+
 #include "gt-c-family-c-common.h"
Index: gcc/c-family/c-common.h
===================================================================
--- gcc/c-family/c-common.h	(revision 178919)
+++ gcc/c-family/c-common.h	(working copy)
@@ -1067,4 +1067,27 @@
   return NULL;
 }
 
+/* A suffix-identifier value doublet that represents user-defined literals
+   for C++-0x.  */
+struct GTY(()) tree_userdef_literal {
+  struct tree_common common;
+  tree suffix_id;
+  tree value;
+  tree num_string;
+};
+
+#define USERDEF_LITERAL_SUFFIX_ID(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->suffix_id)
+
+#define USERDEF_LITERAL_VALUE(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->value)
+
+#define USERDEF_LITERAL_NUM_STRING(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->num_string)
+
+#define USERDEF_LITERAL_TYPE(NODE) \
+  (TREE_TYPE (USERDEF_LITERAL_VALUE (NODE)))
+
+extern tree build_userdef_literal (tree suffix_id, tree value, tree num_string);
+
 #endif /* ! GCC_C_COMMON_H */
Index: gcc/c-family/c-common.def
===================================================================
--- gcc/c-family/c-common.def	(revision 178919)
+++ gcc/c-family/c-common.def	(working copy)
@@ -47,6 +47,12 @@
    evaluated.  */
 DEFTREECODE (EXCESS_PRECISION_EXPR, "excess_precision_expr", tcc_expression, 1)
 
+/* Used to represent a user-defined literal.
+   The operands are an IDENTIFIER for the suffix, the VALUE of the literal,
+   and for numeric literals the original string representation of the
+   number.  */
+DEFTREECODE (USERDEF_LITERAL, "userdef_literal", tcc_exceptional, 3)
+
 /*
 Local variables:
 mode:c
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C	(revision 0)
@@ -0,0 +1,4 @@
+// { dg-options -std=c++0x }
+
+template<char...>
+  int operator"" _xyz(unsigned long long);	// { dg-error "has illegal argument list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit_system_header
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit_system_header	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit_system_header	(revision 0)
@@ -0,0 +1,6 @@
+
+#pragma GCC system_header
+
+char
+operator"" stdsuffix(char __c)
+{ return __c/2; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C	(revision 0)
@@ -0,0 +1,29 @@
+// { dg-options "-std=c++0x" }
+
+//  Both of these can't have *both* of these.
+
+int
+operator"" _abc(const char*) {dg-error "user-defined literal operator template|conflicts with user-defined raw literal operator"}
+  {
+    return 42;
+  }
+
+template<char...>
+  int
+  operator"" _abc()
+  {
+    return 13;
+  }
+
+template<char...>
+  int
+  operator"" _def() {dg-error "user-defined raw literal operator|conflicts with user-defined literal operator template"}
+  {
+    return 12;
+  }
+
+int
+operator"" _def(const char*)
+  {
+    return 43;
+  }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C	(revision 0)
@@ -0,0 +1,43 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test simple operator declaration and definition in namespaces.
+
+#include <cmath>
+#include <limits>
+
+namespace Long
+{
+  long double operator"" _LL(long double);
+}
+
+namespace Short
+{
+  short
+  operator"" _SS(long double x)
+  { return std::fmod(x, static_cast<long double>(std::numeric_limits<short>::max())); }
+}
+
+void
+test1()
+{
+  long double x = Long::operator "" _LL(1.2L);
+
+  using namespace Short;
+  short s = operator"" _SS(1.2L);
+  short s2 = 1.2_SS;
+}
+
+int
+main()
+{
+  test1();
+}
+
+namespace Long
+{
+  long double
+  operator"" _LL(long double x)
+  { return x + 2.0L; }
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C	(revision 0)
@@ -0,0 +1,8 @@
+// { dg-options -std=c++0x }
+
+class Foo
+{
+public:
+  Foo() { }
+  int operator"" _Bar(char32_t) { return 42; }	// { dg-error "must be a non-member function" }
+};
Index: gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C	(revision 0)
@@ -0,0 +1,38 @@
+// { dg-options -std=c++0x }
+
+#include <cstddef>
+
+class Foo { };
+
+Foo
+operator"" _Foo(int *);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(unsigned long int);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(double);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(const float *, std::size_t);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(const wchar_t *, int);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(const char16_t *);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(char...);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(unsigned long long int, char);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(const char *, std::size_t, int);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(long double &);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(std::size_t, const char16_t *);	// { dg-error "has illegal argument list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C	(revision 0)
@@ -0,0 +1,17 @@
+// { dg-options "-std=c++98" }
+
+#include <cstddef>
+
+int
+operator"" _mm(long double m)	// { dg-warning "user-defined literals only available with" }
+{ return int(1000.0L * m); }
+
+int in = 0.0254_mm;	// { dg-error "invalid suffix" }
+
+int
+operator"" _Q(const char *, std::size_t)	// { dg-warning "user-defined literals only available with" }
+{ return 42; }
+
+int x = "Hello"_Q;	// { dg-error "invalid conversion from" }
+
+// { dg-error "expected" "" { target *-*-* } 15 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+#include <string>
+
+std::string operator"" 5X(const char*, std::size_t);	// { dg-error "expected suffix identifier" }
+
+// { dg-error "expected type-specifier before string constant" "" { target *-*-* } 5 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+constexpr unsigned long long
+operator"" _grow(unsigned long long n)
+{ return 2 * n; }
+
+double buffer[25_grow];
Index: gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C	(revision 0)
@@ -0,0 +1,49 @@
+// { dg-options -std=c++0x }
+
+//  Test that the standard suffixes shadow any user-defined suffixes of the same name.
+long double
+operator"" L(long double x)	// { dg-warning "floating point suffix shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ULL(unsigned long long int k)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return k; }
+
+long double
+operator"" l(long double x)	// { dg-warning "floating point suffix shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ull(unsigned long long int k)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return k; }
+
+//  Namespaces are no hiding place.
+namespace Long
+{
+
+long double
+operator"" L(long double x)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ULL(unsigned long long int k)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return k; }
+
+long double
+operator"" l(long double x)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ull(unsigned long long int k)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return k; }
+
+}
+
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 5 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 9 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 13 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 17 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 25 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 29 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 33 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 37 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test warning on declaration without leading underscore.
+
+long double operator"" nounder(long double); // { dg-warning "suffixes not preceded by|are reserved for future standardization" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options -std=c++0x }
+
+class Foo { };
+
+template<wchar_t...>	// { dg-error "" }
+  Foo operator"" _Foo();
Index: gcc/testsuite/g++.dg/cpp0x/udlit-general.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-general.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-general.C	(revision 0)
@@ -0,0 +1,47 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test simple operator declaration and definition.
+
+#include <string>
+#include <complex>
+
+long double operator"" _v(long double);
+std::string operator"" _w(const char16_t*, size_t);
+unsigned operator"" _w(const char*);
+
+std::complex<double>
+operator"" _i(long double y)
+{ return std::complex<double>(0.0L, y); }
+
+void
+test1()
+{
+  long double x = operator"" _v(1.2L);
+
+  std::string s = operator"" _w(u"one", 3);
+
+  unsigned u = operator"" _w("Hello, World!");
+  unsigned u2 = operator"" _w("Hello, World!");
+
+  std::complex<double> i = operator"" _i(2.0);
+}
+
+int
+main()
+{
+  test1();
+}
+
+long double
+operator"" _v(long double x)
+{ return x + 1.0L; }
+
+std::string
+operator"" _w(const char16_t*, size_t)
+{ return std::string("boo"); }
+
+unsigned
+operator"" _w(const char*)
+{ return 0U; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C	(revision 0)
@@ -0,0 +1,3 @@
+// { dg-options -std=c++0x }
+
+#include "udlit_system_header"
Index: gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C	(revision 0)
@@ -0,0 +1,15 @@
+// { dg-options -std=c++0x }
+
+#include <string>
+
+std::string operator"" _i18n(const char*, std::size_t);
+
+std::string vogon_poem = R"V0G0N(
+                O freddled gruntbuggly thy micturations are to me
+                    As plured gabbleblochits on a lurgid bee.
+                 Groop, I implore thee my foonting turlingdromes.   
+              And hooptiously drangle me with crinkly bindlewurdles,
+  Or I will rend thee in the gobberwarts with my blurlecruncheon, see if I don't.
+
+                    (by Prostetnic Vogon Jeltz; see p. 56/57)
+)V0G0N"_i18n;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test error on non-function declaration.
+
+double operator"" _baddecl; // { dg-error "as non-function" }
+
+template<char...>
+  int operator"" _badtmpldecl; // { dg-error "as non-function" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-addr.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-addr.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-addr.C	(revision 0)
@@ -0,0 +1,10 @@
+// { dg-options "-std=c++0x" }
+
+#include <cstddef>
+
+bool operator"" _yn(const char*, size_t);
+
+typedef bool (*pfunk)(const char*, size_t);
+pfunk p = &operator"" _yn;
+
+bool tf = p("Hello,\0 World!", 14);
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C	(revision 0)
@@ -0,0 +1,4 @@
+// { dg-options -std=c++0x }
+
+template<char...>
+  int operator"" _abc();
Index: gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C	(revision 0)
@@ -0,0 +1,8 @@
+// { dg-options -std=c++0x }
+
+extern "C" {
+
+int
+operator"" _badclinkage(unsigned long long);	// { dg-error "operator with C linkage" }
+
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-template.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-template.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-template.C	(revision 0)
@@ -0,0 +1,25 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test template operator declaration and definition.
+
+template<char...>
+  int operator"" _abc();
+
+int
+test1()
+{
+  int universal_meaning = operator"" _abc<'L','U','E'>();
+  int j = 1234567890_abc;
+}
+
+int
+main()
+{
+  test1();
+}
+
+template<char...>
+  int operator"" _abc()
+  { return 42; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-args.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-args.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-args.C	(revision 0)
@@ -0,0 +1,38 @@
+// { dg-options -std=c++0x }
+
+#include <cstddef>
+
+class Foo { };
+
+Foo
+operator"" _Foo(const char *);
+
+Foo
+operator"" _Foo(unsigned long long int);
+
+Foo
+operator"" _Foo(long double);
+
+Foo
+operator"" _Foo(char);
+
+Foo
+operator"" _Foo(wchar_t);
+
+Foo
+operator"" _Foo(char16_t);
+
+Foo
+operator"" _Foo(char32_t);
+
+Foo
+operator"" _Foo(const char *, std::size_t);
+
+Foo
+operator"" _Foo(const wchar_t *, std::size_t);
+
+Foo
+operator"" _Foo(const char16_t *, std::size_t);
+
+Foo
+operator"" _Foo(const char32_t *, std::size_t);
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+char32_t
+operator"" (char32_t C)
+{ return C; }	// { dg-error "expected suffix identifier" }
+
+// { dg-error "expected type-specifier before string constant" "" { target *-*-* } 4 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test error on non-empty string after 'operator' keyword.
+
+double operator"hi" _badword(long double); // { dg-error "expected empty string after" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+extern "C"_badlinkage {	// { dg-error "expected unqualified-id before" }
+
+int foo();
+
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-friend.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-friend.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-friend.C	(revision 0)
@@ -0,0 +1,10 @@
+// { dg-options -std=c++0x }
+
+class Foo
+{
+public:
+  Foo() { }
+  friend Foo operator"" _Bar(char) { return Foo(); }
+};
+
+Foo f = 'x'_Bar;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+#include <string>
+
+std::string operator"" _xxx(const char*, size_t);
+
+std::string operator"" _yyy(const char*, size_t);
+
+std::string concat = "Hello, "_xxx "World!"_yyy;	// { dg-error "inconsistent user-defined literal suffixes" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options -std=c++0x }
+
+class Foo { };
+
+template<char...>
+  Foo operator"" _Foo();
Index: gcc/testsuite/g++.dg/cpp0x/udlit-concat.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-concat.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-concat.C	(revision 0)
@@ -0,0 +1,24 @@
+// { dg-options "-std=c++0x" }
+
+#include <string>
+
+std::string operator"" _www(const char*, size_t);
+
+std::string concat01 = "Hello, " "World!"_www;
+
+std::string concat10 = "Hello, "_www "World!";
+
+std::string concat11 = "Hello, "_www "World!"_www;
+
+
+class Tachyon { };
+
+Tachyon operator"" _fast(const char*, size_t);
+
+int operator"" _fast(const char32_t*, size_t);
+
+int speedy01 = "Hello, " U"World!"_fast;
+
+int speedy10 = "Hello, "_fast U"World!";
+
+int speedy11 = "Hello, "_fast U"World!"_fast;
Index: gcc/cp/typeck.c
===================================================================
--- gcc/cp/typeck.c	(revision 178919)
+++ gcc/cp/typeck.c	(working copy)
@@ -8321,3 +8321,94 @@
   return 1;
 }
 
+
+/* Return true if a user-defined literal operator has one of the allowed
+   argument types.  */
+
+bool
+check_literal_operator_args (const_tree decl,
+			     bool *long_long_unsigned_p, bool *long_double_p)
+{
+  tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
+  if (processing_template_decl)
+    return (argtypes == NULL_TREE
+	    || same_type_p (TREE_VALUE (argtypes), void_type_node));
+  else
+    {
+      tree argtype;
+      int arity;
+      int max_arity = 2;
+      bool found_string_p = false;
+      bool maybe_raw_p = false;
+      bool found_size_p = false;
+      tree const_char_ptr_type_node
+	   = build_pointer_type(build_type_variant(char_type_node, 1, 0));
+      tree const_wchar_ptr_type_node
+	   = build_pointer_type(build_type_variant(wchar_type_node, 1, 0));
+      tree const_char16_ptr_type_node
+	   = build_pointer_type(build_type_variant(char16_type_node, 1, 0));
+      tree const_char32_ptr_type_node
+	   = build_pointer_type(build_type_variant(char32_type_node, 1, 0));
+
+      *long_long_unsigned_p = false;
+      *long_double_p = false;
+
+      /* Count the number and type of arguments and check for ellipsis.  */
+      for (argtype = argtypes, arity = 0;
+	   argtype && argtype != void_list_node;
+	   argtype = TREE_CHAIN (argtype))
+	{
+	  tree t = TREE_VALUE (argtype);
+	  ++arity;
+
+	  if (same_type_p (t, const_char_ptr_type_node))
+	    {
+	      found_string_p = true;
+	      maybe_raw_p = true;
+	    }
+	  else if (same_type_p (t, const_wchar_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, const_char16_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, const_char32_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, size_type_node))
+	    {
+	      if (!found_string_p)
+		return false;
+	      found_size_p = true;
+	    }
+	  else if (same_type_p (t, long_long_unsigned_type_node))
+	    {
+	      max_arity = 1;
+	      *long_long_unsigned_p = true;
+	    }
+	  else if (same_type_p (t, long_double_type_node))
+	    {
+	      max_arity = 1;
+	      *long_double_p = true;
+	    }
+	  else if (same_type_p (t, char_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, wchar_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, char16_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, char32_type_node))
+	    max_arity = 1;
+	  else
+	    return false;
+	}
+      if (!argtype)
+	return false; /* Found ellipsis.  */
+
+      if (arity > max_arity)
+	return false;
+
+      if (found_string_p && !maybe_raw_p && !found_size_p)
+	return false;
+
+      return true;
+    }
+}
+
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 178919)
+++ gcc/cp/decl.c	(working copy)
@@ -1203,6 +1203,21 @@
       || TREE_TYPE (olddecl) == error_mark_node)
     return error_mark_node;
 
+  if (UDLIT_OPER_P (DECL_NAME (newdecl))
+      && UDLIT_OPER_P (DECL_NAME (olddecl)))
+    {
+      if (TREE_CODE (newdecl) == TEMPLATE_DECL
+	  && TREE_CODE (olddecl) != TEMPLATE_DECL)
+	error ("user-defined literal operator template %q+D"
+	       " conflicts with user-defined raw literal operator %q+D",
+	       newdecl, olddecl);
+      else if (TREE_CODE (newdecl) != TEMPLATE_DECL
+	       && TREE_CODE (olddecl) == TEMPLATE_DECL)
+	error ("user-defined raw literal operator %q+D"
+	       " conflicts with user-defined literal operator template %q+D",
+	       newdecl, olddecl);
+    }
+
   if (DECL_P (olddecl)
       && TREE_CODE (newdecl) == FUNCTION_DECL
       && TREE_CODE (olddecl) == FUNCTION_DECL
@@ -7314,7 +7329,48 @@
   if (IDENTIFIER_OPNAME_P (DECL_NAME (decl))
       && !grok_op_properties (decl, /*complain=*/true))
     return NULL_TREE;
+  else if (UDLIT_OPER_P (DECL_NAME (decl)))
+    {
+      bool long_long_unsigned_p;
+      bool long_double_p;
+      const char *suffix = NULL;
+      /* [over.literal]/6: Literal operators shall not have C linkage. */
+      if (DECL_LANGUAGE(decl) == lang_c)
+	{
+	  error ("literal operator with C linkage");
+	  return NULL_TREE;
+	}
 
+      if (DECL_NAMESPACE_SCOPE_P (decl))
+	{
+	  if (!check_literal_operator_args(decl,
+					   &long_long_unsigned_p, &long_double_p))
+	    {
+	      error ("%qD has invalid argument list", decl);
+	      return NULL_TREE;
+	    }
+
+	  suffix = UDLIT_OP_SUFFIX (DECL_NAME (decl));
+	  if (long_long_unsigned_p)
+	    {
+	      if (cpp_interpret_int_suffix (suffix, strlen (suffix)))
+		warning (0, "integer suffix %<%s%>"
+			    " shadowed by implementation", suffix);
+	    }
+	  else if (long_double_p)
+	    {
+	      if (cpp_interpret_float_suffix (suffix, strlen (suffix)))
+		warning (0, "floating point suffix %<%s%>"
+			    " shadowed by implementation", suffix);
+	    }
+	}
+      else
+	{
+	  error ("%qD must be a non-member function", decl);
+	  return NULL_TREE;
+	}
+    }
+
   if (funcdef_flag)
     /* Make the init_value nonzero so pushdecl knows this is not
        tentative.  error_mark_node is replaced later with the BLOCK.  */
@@ -8498,6 +8554,15 @@
       error ("declaration of %qD as non-function", dname);
       return error_mark_node;
     }
+ 
+  if (dname
+      && TREE_CODE (dname) == IDENTIFIER_NODE
+      && UDLIT_OPER_P (dname)
+      && innermost_code != cdk_function)
+    {
+      error ("declaration of %qD as non-function", dname);
+      return error_mark_node;
+    }
 
   if (dname && IDENTIFIER_OPNAME_P (dname))
     {
@@ -13746,6 +13811,7 @@
     case TRAIT_EXPR:		return TS_CP_TRAIT_EXPR;
     case LAMBDA_EXPR:		return TS_CP_LAMBDA_EXPR;
     case TEMPLATE_INFO:		return TS_CP_TEMPLATE_INFO;
+    case USERDEF_LITERAL:	return TS_CP_USERDEF_LITERAL;
     default:			return TS_CP_GENERIC;
     }
 }
Index: gcc/cp/error.c
===================================================================
--- gcc/cp/error.c	(revision 178919)
+++ gcc/cp/error.c	(working copy)
@@ -1533,6 +1533,8 @@
     }
   else if (name && IDENTIFIER_OPNAME_P (name))
     pp_cxx_tree_identifier (cxx_pp, name);
+  else if (name && UDLIT_OPER_P (name))
+    pp_cxx_tree_identifier (cxx_pp, name);
   else
     dump_decl (name, flags);
 
@@ -1755,6 +1757,10 @@
       pp_constant (cxx_pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (cxx_pp, t);
+      break;
+
     case THROW_EXPR:
       /* While waiting for caret diagnostics, avoid printing
 	 __cxa_allocate_exception, __cxa_throw, and the like.  */
@@ -3230,14 +3236,19 @@
 	pedwarn (input_location, OPT_pedantic,
 		 "inline namespaces "
 		 "only available with -std=c++0x or -std=gnu++0x");
-	break;	
+	break;
       case CPP0X_OVERRIDE_CONTROLS:
 	pedwarn (input_location, 0,
 		 "override controls (override/final) "
 		 "only available with -std=c++0x or -std=gnu++0x");
         break;
+      case CPP0X_USER_DEFINED_LITERALS:
+	pedwarn (input_location, 0,
+		 "user-defined literals "
+		 "only available with -std=c++0x or -std=gnu++0x");
+	break;
       default:
-	gcc_unreachable();
+	gcc_unreachable ();
       }
 }
 
Index: gcc/cp/cxx-pretty-print.c
===================================================================
--- gcc/cp/cxx-pretty-print.c	(revision 178919)
+++ gcc/cp/cxx-pretty-print.c	(working copy)
@@ -367,6 +367,17 @@
     pp_cxx_unqualified_id (pp, t);
 }
 
+/* user-defined literal:
+      literal ud-suffix  */
+
+void
+pp_cxx_userdef_literal (cxx_pretty_printer *pp, tree t)
+{
+  pp_cxx_constant (pp, USERDEF_LITERAL_VALUE (t));
+  pp_cxx_id_expression (pp, USERDEF_LITERAL_SUFFIX_ID (t));
+}
+
+
 /* primary-expression:
      literal
      this
@@ -413,6 +424,10 @@
       pp_cxx_constant (pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (pp, t);
+      break;
+
     case BASELINK:
       t = BASELINK_FUNCTIONS (t);
     case VAR_DECL:
@@ -1023,6 +1038,10 @@
       pp_cxx_constant (pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (pp, t);
+      break;
+
     case RESULT_DECL:
       pp_cxx_unqualified_id (pp, t);
       break;
Index: gcc/cp/semantics.c
===================================================================
--- gcc/cp/semantics.c	(revision 178919)
+++ gcc/cp/semantics.c	(working copy)
@@ -7748,6 +7748,7 @@
     case TEMPLATE_PARM_INDEX:
     case TRAIT_EXPR:
     case IDENTIFIER_NODE:
+    case USERDEF_LITERAL:
       /* We can see a FIELD_DECL in a pointer-to-member expression.  */
     case FIELD_DECL:
     case PARM_DECL:
Index: gcc/cp/cxx-pretty-print.h
===================================================================
--- gcc/cp/cxx-pretty-print.h	(revision 178919)
+++ gcc/cp/cxx-pretty-print.h	(working copy)
@@ -74,5 +74,7 @@
 void pp_cxx_trait_expression (cxx_pretty_printer *, tree);
 void pp_cxx_va_arg_expression (cxx_pretty_printer *, tree);
 void pp_cxx_offsetof_expression (cxx_pretty_printer *, tree);
+void pp_cxx_userdef_literal (cxx_pretty_printer *, tree);
 
+
 #endif /* GCC_CXX_PRETTY_PRINT_H */
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 178919)
+++ gcc/cp/parser.c	(working copy)
@@ -210,6 +210,8 @@
   (cp_lexer *);
 static void cp_lexer_rollback_tokens
   (cp_lexer *);
+static tree cp_literal_operator_id
+  (const char *);
 #ifdef ENABLE_CHECKING
 static void cp_lexer_print_token
   (FILE *, cp_token *);
@@ -501,20 +503,20 @@
 	}
       else
 	{
-          if (warn_cxx0x_compat
-              && C_RID_CODE (token->u.value) >= RID_FIRST_CXX0X
-              && C_RID_CODE (token->u.value) <= RID_LAST_CXX0X)
-            {
-              /* Warn about the C++0x keyword (but still treat it as
-                 an identifier).  */
-              warning (OPT_Wc__0x_compat, 
-                       "identifier %qE will become a keyword in C++0x",
-                       token->u.value);
+	  if (warn_cxx0x_compat
+	      && C_RID_CODE (token->u.value) >= RID_FIRST_CXX0X
+	      && C_RID_CODE (token->u.value) <= RID_LAST_CXX0X)
+	    {
+	      /* Warn about the C++0x keyword (but still treat it as
+		 an identifier).  */
+	      warning (OPT_Wc__0x_compat, 
+		       "identifier %qE will become a keyword in C++0x",
+		       token->u.value);
 
-              /* Clear out the C_RID_CODE so we don't warn about this
-                 particular identifier-turned-keyword again.  */
-              C_SET_RID_CODE (token->u.value, RID_MAX);
-            }
+	      /* Clear out the C_RID_CODE so we don't warn about this
+		 particular identifier-turned-keyword again.  */
+	      C_SET_RID_CODE (token->u.value, RID_MAX);
+	    }
 
 	  token->ambiguous_p = false;
 	  token->keyword = RID_MAX;
@@ -1528,6 +1530,12 @@
   (cp_parser *);
 static tree cp_parser_string_literal
   (cp_parser *, bool, bool);
+static tree cp_parser_userdef_char_literal
+  (cp_parser *);
+static tree cp_parser_userdef_string_literal
+  (cp_token *);
+static tree cp_parser_userdef_numeric_literal
+  (cp_parser *);
 
 /* Basic concepts [gram.basic]  */
 
@@ -2030,6 +2038,8 @@
   (cp_parser *);
 static bool cp_parser_allow_gnu_extensions_p
   (cp_parser *);
+static bool cp_parser_is_pure_string_literal
+  (cp_token *);
 static bool cp_parser_is_string_literal
   (cp_token *);
 static bool cp_parser_is_keyword
@@ -2050,7 +2060,7 @@
 /* Returns nonzero if TOKEN is a string literal.  */
 
 static bool
-cp_parser_is_string_literal (cp_token* token)
+cp_parser_is_pure_string_literal (cp_token* token)
 {
   return (token->type == CPP_STRING ||
 	  token->type == CPP_STRING16 ||
@@ -2059,6 +2069,20 @@
 	  token->type == CPP_UTF8STRING);
 }
 
+/* Returns nonzero if TOKEN is a string literal
+   of a user-defined string literal.  */
+
+static bool
+cp_parser_is_string_literal (cp_token* token)
+{
+  return (cp_parser_is_pure_string_literal (token) ||
+	  token->type == CPP_STRING_USERDEF ||
+	  token->type == CPP_STRING16_USERDEF ||
+	  token->type == CPP_STRING32_USERDEF ||
+	  token->type == CPP_WSTRING_USERDEF ||
+	  token->type == CPP_UTF8STRING_USERDEF);
+}
+
 /* Returns nonzero if TOKEN is the indicated KEYWORD.  */
 
 static bool
@@ -3098,7 +3122,11 @@
   struct obstack str_ob;
   cpp_string str, istr, *strs;
   cp_token *tok;
-  enum cpp_ttype type;
+  enum cpp_ttype type, curr_type;
+  int have_suffix_p = 0;
+  tree string_tree;
+  tree suffix_id = NULL_TREE;
+  bool curr_tok_is_userdef_p = false;
 
   tok = cp_lexer_peek_token (parser->lexer);
   if (!cp_parser_is_string_literal (tok))
@@ -3107,7 +3135,18 @@
       return error_mark_node;
     }
 
-  type = tok->type;
+  if (cpp_userdef_string_p (tok->type))
+    {
+      string_tree = USERDEF_LITERAL_VALUE (tok->u.value);
+      curr_type = cpp_userdef_string_remove_type (tok->type);
+      curr_tok_is_userdef_p = true;
+    }
+  else
+    {
+      string_tree = tok->u.value;
+      curr_type = tok->type;
+    }
+  type = curr_type;
 
   /* Try to avoid the overhead of creating and destroying an obstack
      for the common case of just one string.  */
@@ -3116,10 +3155,19 @@
     {
       cp_lexer_consume_token (parser->lexer);
 
-      str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value);
-      str.len = TREE_STRING_LENGTH (tok->u.value);
+      str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree);
+      str.len = TREE_STRING_LENGTH (string_tree);
       count = 1;
 
+      if (curr_tok_is_userdef_p)
+	{
+	  suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value);
+	  have_suffix_p = 1;
+	  curr_type = cpp_userdef_string_remove_type (tok->type);
+	}
+      else
+	curr_type = tok->type;
+
       strs = &str;
     }
   else
@@ -3131,14 +3179,35 @@
 	{
 	  cp_lexer_consume_token (parser->lexer);
 	  count++;
-	  str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value);
-	  str.len = TREE_STRING_LENGTH (tok->u.value);
+	  str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree);
+	  str.len = TREE_STRING_LENGTH (string_tree);
 
-	  if (type != tok->type)
+	  if (curr_tok_is_userdef_p)
 	    {
+	      tree curr_suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value);
+	      if (have_suffix_p == 0)
+		{
+		  suffix_id = curr_suffix_id;
+		  have_suffix_p = 1;
+		}
+	      else if (have_suffix_p == 1
+		       && curr_suffix_id != suffix_id)
+		{
+		  error ("inconsistent user-defined literal suffixes"
+			 " %qD and %qD in string literal",
+			 suffix_id, curr_suffix_id);
+		  have_suffix_p = -1;
+		}
+	      curr_type = cpp_userdef_string_remove_type (tok->type);
+	    }
+	  else
+	    curr_type = tok->type;
+
+	  if (type != curr_type)
+	    {
 	      if (type == CPP_STRING)
-		type = tok->type;
-	      else if (tok->type != CPP_STRING)
+		type = curr_type;
+	      else if (curr_type != CPP_STRING)
 		error_at (tok->location,
 			  "unsupported non-standard concatenation "
 			  "of string literals");
@@ -3147,6 +3216,18 @@
 	  obstack_grow (&str_ob, &str, sizeof (cpp_string));
 
 	  tok = cp_lexer_peek_token (parser->lexer);
+	  if (cpp_userdef_string_p (tok->type))
+	    {
+	      string_tree = USERDEF_LITERAL_VALUE (tok->u.value);
+	      curr_type = cpp_userdef_string_remove_type (tok->type);
+	      curr_tok_is_userdef_p = true;
+	    }
+	  else
+	    {
+	      string_tree = tok->u.value;
+	      curr_type = tok->type;
+	      curr_tok_is_userdef_p = false;
+	    }
 	}
       while (cp_parser_is_string_literal (tok));
 
@@ -3184,6 +3265,13 @@
 	}
 
       value = fix_string_type (value);
+
+      if (have_suffix_p)
+	{
+	  tree literal = build_userdef_literal (suffix_id, value, NULL_TREE);
+	  tok->u.value = literal;
+	  return cp_parser_userdef_string_literal (tok);
+	}
     }
   else
     /* cpp_interpret_string has issued an error.  */
@@ -3195,7 +3283,183 @@
   return value;
 }
 
+/* Parse a user-defined char constant.  Returns a call to a user-defined
+   literal operator taking the character as an argument.  */
 
+static tree
+cp_parser_userdef_char_literal (cp_parser *parser)
+{
+  cp_token *token = NULL;
+  tree literal, suffix_id, value;
+  tree name, decl;
+  tree result;
+  VEC(tree,gc) *vec;
+
+  token = cp_lexer_consume_token (parser->lexer);
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  value = USERDEF_LITERAL_VALUE (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  vec = make_tree_vector ();
+  VEC_safe_push (tree, gc, vec, value);
+  decl = lookup_function_nonclass (name, vec, /*block_p=*/false);
+  if (decl == error_mark_node)
+    {
+      error ("unable to find user-defined literal operator declaration");
+      release_tree_vector (vec);
+      return error_mark_node;
+    }
+  result = finish_call_expr (decl, &vec, false, true, tf_warning_or_error);
+  release_tree_vector (vec);
+
+  return result;
+}
+
+/* A subroutine of cp_parser_userdef_numeric_literal to
+   create a char... template parameter pack from a string node.  */
+
+static tree
+make_char_string_pack (tree value)
+{
+  tree parmvec;
+  tree argpack = make_node (NONTYPE_ARGUMENT_PACK);
+  const char *str = TREE_STRING_POINTER (value);
+  int i, len = TREE_STRING_LENGTH (value) - 1;
+  /*  Do I need to stuff THIS into a tree? */
+  tree argvec = make_tree_vec (1);
+
+  /* Fill in PARMVEC with all of the parameters.  */
+  parmvec = make_tree_vec (len);
+  for (i = 0; i < len; ++i)
+    TREE_VEC_ELT (parmvec, i) = build_int_cst (char_type_node, str[i]);
+
+  /* Build the argument packs.  */
+  SET_ARGUMENT_PACK_ARGS (argpack, parmvec);
+  TREE_TYPE (argpack) = char_type_node;
+
+  /*  Do I need to stuff THIS into a tree? */
+  TREE_VEC_ELT (argvec, 0) = argpack;
+
+  return argvec;
+}
+
+/* Parse a user-defined numeric constant.  returns a call to a user-defined
+   literal operator.  */
+static tree
+cp_parser_userdef_numeric_literal (cp_parser *parser)
+{
+  cp_token *token = NULL;
+  tree literal, suffix_id, value, num_string;
+  tree name, decl;
+  tree result = error_mark_node;
+  VEC(tree,gc) *args;
+
+  token = cp_lexer_consume_token (parser->lexer);
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  value = USERDEF_LITERAL_VALUE (literal);
+  num_string = USERDEF_LITERAL_NUM_STRING (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  /* Try to find the literal operator by finishing the call expression
+     with the numeric argument.  */
+  args = make_tree_vector ();
+  VEC_safe_push (tree, gc, args, value);
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl != error_mark_node)
+    {
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  /* If the numeric argument didn't work, look for a raw literal
+     operator taking a const char* argument consisting of the number
+     in string format.  */
+  args = make_tree_vector ();
+  VEC_safe_push (tree, gc, args, num_string);
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl != error_mark_node)
+    {
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  /* If the raw literal didn't work, look for a non-type template
+     function with parameter pack char....  Call the function with
+     template parameter characters representing the number.  */
+  args = make_tree_vector ();
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl != error_mark_node)
+    {
+      decl = finish_call_expr (decl, &args, false, true, tf_none);
+      if (decl != error_mark_node)
+	{
+	  tree tmpl_args = make_char_string_pack (num_string);
+	  result = lookup_template_function (decl, tmpl_args);
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  if (result == error_mark_node)
+    error ("unable to find appropriate call for user-defined literal");
+
+  return result;
+}
+
+/* Parse a user-defined string constant.  Returns a call to a user-defined
+   literal operator taking a character pointer and the length of the string
+   as arguments.  */
+static tree
+cp_parser_userdef_string_literal (cp_token *token)
+{
+  tree literal, suffix_id, value;
+  tree name, decl;
+  tree result;
+  VEC(tree,gc) *vec;
+  int len;
+
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+  value = USERDEF_LITERAL_VALUE (literal);
+  len = TREE_STRING_LENGTH (value) - 1;
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  vec = make_tree_vector ();
+  VEC_safe_push (tree, gc, vec, value);
+  VEC_safe_push (tree, gc, vec, build_int_cst (size_type_node, len));
+  decl = lookup_function_nonclass (name, vec, /*block_p=*/false);
+  if (decl == error_mark_node)
+    {
+      error ("unable to find user-defined literal operator declaration");
+      release_tree_vector (vec);
+      return error_mark_node;
+    }
+  result = finish_call_expr (decl, &vec, false, true, tf_warning_or_error);
+  release_tree_vector (vec);
+
+  return result;
+}
+
+
 /* Basic concepts [gram.basic]  */
 
 /* Parse a translation-unit.
@@ -3338,12 +3602,16 @@
 	   character-literal
 	   floating-literal
 	   string-literal
-	   boolean-literal  */
+	   boolean-literal
+	   pointer-literal
+	   user-defined-literal  */
     case CPP_CHAR:
     case CPP_CHAR16:
     case CPP_CHAR32:
     case CPP_WCHAR:
     case CPP_NUMBER:
+      if (TREE_CODE (token->u.value) == USERDEF_LITERAL)
+	return cp_parser_userdef_numeric_literal (parser);
       token = cp_lexer_consume_token (parser->lexer);
       if (TREE_CODE (token->u.value) == FIXED_CST)
 	{
@@ -3397,11 +3665,22 @@
 	}
       return token->u.value;
 
+    case CPP_CHAR_USERDEF:
+    case CPP_CHAR16_USERDEF:
+    case CPP_CHAR32_USERDEF:
+    case CPP_WCHAR_USERDEF:
+      return cp_parser_userdef_char_literal (parser);
+
     case CPP_STRING:
     case CPP_STRING16:
     case CPP_STRING32:
     case CPP_WSTRING:
     case CPP_UTF8STRING:
+    case CPP_STRING_USERDEF:
+    case CPP_STRING16_USERDEF:
+    case CPP_STRING32_USERDEF:
+    case CPP_WSTRING_USERDEF:
+    case CPP_UTF8STRING_USERDEF:
       /* ??? Should wide strings be allowed when parser->translate_strings_p
 	 is false (i.e. in attributes)?  If not, we can kill the third
 	 argument to cp_parser_string_literal.  */
@@ -4879,7 +5158,7 @@
 	/* Restore the saved message.  */
 	parser->type_definition_forbidden_message = saved_message;
 	/* `typeid' may not appear in an integral constant expression.  */
-	if (cp_parser_non_integral_constant_expression(parser, NIC_TYPEID))
+	if (cp_parser_non_integral_constant_expression (parser, NIC_TYPEID))
 	  return error_mark_node;
       }
       break;
@@ -9462,7 +9741,7 @@
   /* If the next token is `extern' and the following token is a string
      literal, then we have a linkage specification.  */
   if (token1.keyword == RID_EXTERN
-      && cp_parser_is_string_literal (&token2))
+      && cp_parser_is_pure_string_literal (&token2))
     cp_parser_linkage_specification (parser);
   /* If the next token is `template', then we have either a template
      declaration, an explicit instantiation, or an explicit
@@ -10893,6 +11172,22 @@
   return cp_parser_operator (parser);
 }
 
+/* Return an identifier node for a user-defined literal operator.
+   The suffix identifier is chained to the operator name identifier.  */
+
+static tree
+cp_literal_operator_id (const char* name)
+{
+  tree identifier;
+  char *buffer = XNEWVEC (char, strlen (UDLIT_OP_ANSI_PREFIX)
+			      + strlen (name) + 10);
+  sprintf (buffer, UDLIT_OP_ANSI_FORMAT, name);
+  identifier = get_identifier (buffer);
+  /*IDENTIFIER_UDLIT_OPNAME_P (identifier) = 1; If we get a flag someday. */
+
+  return identifier;
+}
+
 /* Parse an operator.
 
    operator:
@@ -11112,6 +11407,35 @@
       cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE);
       return ansi_opname (ARRAY_REF);
 
+    case CPP_STRING:
+      if (cxx_dialect == cxx98)
+	maybe_warn_cpp0x (CPP0X_USER_DEFINED_LITERALS);
+      if (TREE_STRING_LENGTH (token->u.value) > 2)
+	{
+	  error ("expected empty string after %<operator%> keyword");
+	  return error_mark_node;
+	}
+      /* Consume the string.  */
+      cp_lexer_consume_token (parser->lexer);
+      /* Look for an identifier.  */
+      id = cp_parser_identifier (parser);
+      if (id != error_mark_node)
+	{
+	  const char *name = IDENTIFIER_POINTER (id);
+
+	  /* 17.6.3.3.5  */
+	  if (name[0] != '_' && !in_system_header)
+	    warning (0, "suffixes not preceded by %<_%> "
+			"are reserved for future standardization");
+
+	  return cp_literal_operator_id(name);
+	}
+      else
+	{
+	  error ("expected suffix identifier");
+	  return error_mark_node;
+	}
+
     default:
       /* Anything else is an error.  */
       break;
@@ -22458,7 +22782,8 @@
   /* If the next token is `extern' and the following token is a string
      literal, then we have a linkage specification.  */
   if (token->keyword == RID_EXTERN
-      && cp_parser_is_string_literal (cp_lexer_peek_nth_token (parser->lexer, 2)))
+      && cp_parser_is_pure_string_literal
+	 (cp_lexer_peek_nth_token (parser->lexer, 2)))
     cp_parser_linkage_specification (parser);
   /* Handle #pragma, if any.  */
   else if (token->type == CPP_PRAGMA)
Index: gcc/cp/cp-objcp-common.c
===================================================================
--- gcc/cp/cp-objcp-common.c	(revision 178919)
+++ gcc/cp/cp-objcp-common.c	(working copy)
@@ -100,6 +100,8 @@
 
     case TEMPLATE_INFO:         return sizeof (struct tree_template_info);
 
+    case USERDEF_LITERAL:	return sizeof (struct tree_userdef_literal);
+
     default:
       gcc_unreachable ();
     }
Index: gcc/cp/mangle.c
===================================================================
--- gcc/cp/mangle.c	(revision 178919)
+++ gcc/cp/mangle.c	(working copy)
@@ -181,6 +181,7 @@
 static void write_unqualified_name (const tree);
 static void write_conversion_operator_name (const tree);
 static void write_source_name (tree);
+static void write_literal_operator_name (tree);
 static void write_unnamed_type_name (const tree);
 static void write_closure_type_name (const tree);
 static int hwint_to_ascii (unsigned HOST_WIDE_INT, const unsigned int, char *,
@@ -1174,6 +1175,8 @@
 	  }
       write_string (mangled_name);
     }
+  else if (UDLIT_OPER_P (identifier))
+    write_literal_operator_name (identifier);
   else
     write_source_name (identifier);
 }
@@ -1227,6 +1230,8 @@
 
 	  write_string (oni[DECL_OVERLOADED_OPERATOR_P (decl)].mangled_name);
 	}
+      else if (UDLIT_OPER_P (DECL_NAME (decl)))
+	write_literal_operator_name (DECL_NAME (decl));
       else
 	found = false;
 
@@ -1286,6 +1291,21 @@
   write_identifier (IDENTIFIER_POINTER (identifier));
 }
 
+/* Write a user-defined literal operator.
+   IDENTIFIER is an LITERAL_IDENTIFIER_NODE.  */
+
+static void
+write_literal_operator_name (tree identifier)
+{
+  const char* suffix = UDLIT_OP_SUFFIX (identifier);
+  char* buffer = XNEWVEC (char, strlen (UDLIT_OP_MANGLED_PREFIX)
+			      + strlen (suffix) + 10);
+  sprintf (buffer, UDLIT_OP_MANGLED_FORMAT, suffix);
+
+  write_unsigned_number (strlen (buffer));
+  write_identifier (buffer);
+}
+
 /* Encode 0 as _, and 1+ as n-1_.  */
 
 static void
Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h	(revision 178919)
+++ gcc/cp/cp-tree.h	(working copy)
@@ -394,7 +394,9 @@
   /* inline namespaces */
   CPP0X_INLINE_NAMESPACES,
   /* override controls, override/final */
-  CPP0X_OVERRIDE_CONTROLS
+  CPP0X_OVERRIDE_CONTROLS,
+  /* user defined literals */
+  CPP0X_USER_DEFINED_LITERALS
 } cpp0x_warn_str;
   
 /* The various kinds of operation used by composite_pointer_type. */
@@ -725,6 +727,7 @@
   TS_CP_TRAIT_EXPR,
   TS_CP_LAMBDA_EXPR,
   TS_CP_TEMPLATE_INFO,
+  TS_CP_USERDEF_LITERAL,
   LAST_TS_CP_ENUM
 };
 
@@ -750,6 +753,8 @@
     lambda_expression;
   struct tree_template_info GTY ((tag ("TS_CP_TEMPLATE_INFO")))
     template_info;
+  struct tree_userdef_literal GTY ((tag ("TS_CP_USERDEF_LITERAL")))
+    userdef_literal;
 };
 
 \f
@@ -4191,6 +4196,17 @@
              LAMBDANAME_PREFIX, \
 	     sizeof (LAMBDANAME_PREFIX) - 1))
 
+#define UDLIT_OP_ANSI_PREFIX "operator\"\" "
+#define UDLIT_OP_ANSI_FORMAT UDLIT_OP_ANSI_PREFIX "%s"
+#define UDLIT_OP_MANGLED_PREFIX "li"
+#define UDLIT_OP_MANGLED_FORMAT UDLIT_OP_MANGLED_PREFIX "%s"
+#define UDLIT_OPER_P(ID_NODE) \
+  (!strncmp (IDENTIFIER_POINTER (ID_NODE), \
+             UDLIT_OP_ANSI_PREFIX, \
+	     sizeof (UDLIT_OP_ANSI_PREFIX) - 1))
+#define UDLIT_OP_SUFFIX(ID_NODE) \
+  (IDENTIFIER_POINTER (ID_NODE) + sizeof (UDLIT_OP_ANSI_PREFIX) - 1)
+
 #if !defined(NO_DOLLAR_IN_LABEL) || !defined(NO_DOT_IN_LABEL)
 
 #define VTABLE_NAME_P(ID_NODE) (IDENTIFIER_POINTER (ID_NODE)[1] == 'v' \
@@ -5713,6 +5729,7 @@
 extern int lvalue_or_else			(tree, enum lvalue_use,
                                                  tsubst_flags_t);
 extern void check_template_keyword		(tree);
+extern bool check_literal_operator_args		(const_tree, bool *, bool *);
 
 /* in typeck2.c */
 extern void require_complete_eh_spec_types	(tree, tree);
Index: libcpp/include/cpplib.h
===================================================================
--- libcpp/include/cpplib.h	(revision 178919)
+++ libcpp/include/cpplib.h	(working copy)
@@ -131,6 +131,16 @@
   TK(OBJC_STRING,	LITERAL) /* @"string" - Objective-C */		\
   TK(HEADER_NAME,	LITERAL) /* <stdio.h> in #include */		\
 									\
+  TK(CHAR_USERDEF,	LITERAL) /* 'char'_suffix - C++-0x */		\
+  TK(WCHAR_USERDEF,	LITERAL) /* L'char'_suffix - C++-0x */		\
+  TK(CHAR16_USERDEF,	LITERAL) /* u'char'_suffix - C++-0x */		\
+  TK(CHAR32_USERDEF,	LITERAL) /* U'char'_suffix - C++-0x */		\
+  TK(STRING_USERDEF,	LITERAL) /* "string"_suffix - C++-0x */		\
+  TK(WSTRING_USERDEF,	LITERAL) /* L"string"_suffix - C++-0x */	\
+  TK(STRING16_USERDEF,	LITERAL) /* u"string"_suffix - C++-0x */	\
+  TK(STRING32_USERDEF,	LITERAL) /* U"string"_suffix - C++-0x */	\
+  TK(UTF8STRING_USERDEF,LITERAL) /* u8"string"_suffix - C++-0x */	\
+									\
   TK(COMMENT,		LITERAL) /* Only if output comments.  */	\
 				 /* SPELL_LITERAL happens to DTRT.  */	\
   TK(MACRO_ARG,		NONE)	 /* Macro argument.  */			\
@@ -402,6 +412,9 @@
   /* True for traditional preprocessing.  */
   unsigned char traditional;
 
+  /* Nonzero for the 2011 C++ Standard.  */
+  unsigned char cxx11;
+
   /* Holds the name of the target (execution) character set.  */
   const char *narrow_charset;
 
@@ -817,13 +830,22 @@
 #define CPP_N_FRACT	0x100000 /* Fract types.  */
 #define CPP_N_ACCUM	0x200000 /* Accum types.  */
 
+#define CPP_N_USERDEF	0x1000000 /* C++0x user-defined literal.  */
+
 /* Classify a CPP_NUMBER token.  The return value is a combination of
    the flags from the above sets.  */
-extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *);
+extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *,
+				     const char **);
 
+/* Return the classification flags for a float suffix.  */
+extern unsigned int cpp_interpret_float_suffix (const char *, size_t);
+
+/* Return the classification flags for an int suffix.  */
+extern unsigned int cpp_interpret_int_suffix (const char *, size_t);
+
 /* Evaluate a token classified as category CPP_N_INTEGER.  */
 extern cpp_num cpp_interpret_integer (cpp_reader *, const cpp_token *,
-				      unsigned int type);
+				      unsigned int);
 
 /* Sign extend a number, with PRECISION significant bits and all
    others assumed clear, to fill out a cpp_num structure.  */
@@ -993,4 +1015,20 @@
 extern void cpp_force_token_locations (cpp_reader *, source_location *);
 extern void cpp_stop_forcing_token_locations (cpp_reader *);
 
+/* In expr.c */
+extern enum cpp_ttype cpp_userdef_string_remove_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_string_add_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_char_remove_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_char_add_type
+  (enum cpp_ttype type);
+extern bool cpp_userdef_string_p
+  (enum cpp_ttype type);
+extern bool cpp_userdef_char_p
+  (enum cpp_ttype type);
+extern void cpp_get_userdef_suffix
+  (cpp_string, char, const char **);
+
 #endif /* ! LIBCPP_CPPLIB_H */
Index: libcpp/init.c
===================================================================
--- libcpp/init.c	(revision 178919)
+++ libcpp/init.c	(working copy)
@@ -80,22 +80,23 @@
   char digraphs;
   char uliterals;
   char rliterals;
+  char cxx11;
 };
 
 static const struct lang_flags lang_defaults[] =
-{ /*              c99 c++ xnum xid std  //   digr ulit rlit */
-  /* GNUC89   */  { 0,  0,  1,   0,  0,   1,   1,   0,   0 },
-  /* GNUC99   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1 },
-  /* GNUC1X   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1 },
-  /* STDC89   */  { 0,  0,  0,   0,  1,   0,   0,   0,   0 },
-  /* STDC94   */  { 0,  0,  0,   0,  1,   0,   1,   0,   0 },
-  /* STDC99   */  { 1,  0,  1,   0,  1,   1,   1,   0,   0 },
-  /* STDC1X   */  { 1,  0,  1,   0,  1,   1,   1,   1,   0 },
-  /* GNUCXX   */  { 0,  1,  1,   0,  0,   1,   1,   0,   0 },
-  /* CXX98    */  { 0,  1,  1,   0,  1,   1,   1,   0,   0 },
-  /* GNUCXX0X */  { 1,  1,  1,   0,  0,   1,   1,   1,   1 },
-  /* CXX0X    */  { 1,  1,  1,   0,  1,   1,   1,   1,   1 },
-  /* ASM      */  { 0,  0,  1,   0,  0,   1,   0,   0,   0 }
+{ /*              c99 c++ xnum xid std  //   digr ulit rlit cxx11 */
+  /* GNUC89   */  { 0,  0,  1,   0,  0,   1,   1,   0,   0,    0 },
+  /* GNUC99   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1,    0 },
+  /* GNUC1X   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1,    0 },
+  /* STDC89   */  { 0,  0,  0,   0,  1,   0,   0,   0,   0,    0 },
+  /* STDC94   */  { 0,  0,  0,   0,  1,   0,   1,   0,   0,    0 },
+  /* STDC99   */  { 1,  0,  1,   0,  1,   1,   1,   0,   0,    0 },
+  /* STDC1X   */  { 1,  0,  1,   0,  1,   1,   1,   1,   0,    0 },
+  /* GNUCXX   */  { 0,  1,  1,   0,  0,   1,   1,   0,   0,    0 },
+  /* CXX98    */  { 0,  1,  1,   0,  1,   1,   1,   0,   0,    0 },
+  /* GNUCXX0X */  { 1,  1,  1,   0,  0,   1,   1,   1,   1,    1 },
+  /* CXX0X    */  { 1,  1,  1,   0,  1,   1,   1,   1,   1,    1 },
+  /* ASM      */  { 0,  0,  1,   0,  0,   1,   0,   0,   0,    0 }
   /* xid should be 1 for GNUC99, STDC99, GNUCXX, CXX98, GNUCXX0X, and
      CXX0X when no longer experimental (when all uses of identifiers
      in the compiler have been audited for correct handling of
@@ -120,6 +121,7 @@
   CPP_OPTION (pfile, digraphs)			 = l->digraphs;
   CPP_OPTION (pfile, uliterals)			 = l->uliterals;
   CPP_OPTION (pfile, rliterals)			 = l->rliterals;
+  CPP_OPTION (pfile, cxx11)			 = l->cxx11;
 }
 
 /* Initialize library global state.  */
Index: libcpp/expr.c
===================================================================
--- libcpp/expr.c	(revision 178919)
+++ libcpp/expr.c	(working copy)
@@ -1,6 +1,6 @@
 /* Parse C expressions for cpplib.
    Copyright (C) 1987, 1992, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
-   2002, 2004, 2008, 2009, 2010 Free Software Foundation.
+   2002, 2004, 2008, 2009, 2010, 2011 Free Software Foundation.
    Contributed by Per Bothner, 1994.
 
 This program is free software; you can redistribute it and/or modify it
@@ -185,6 +185,13 @@
 	     q ? CPP_N_MD_Q : CPP_N_DEFAULT));
 }
 
+/* Return the classification flags for a float suffix.  */
+unsigned int
+cpp_interpret_float_suffix (const char *s, size_t len)
+{
+  return interpret_float_suffix ((const unsigned char *)s, len);
+}
+
 /* Subroutine of cpp_classify_number.  S points to an integer suffix
    of length LEN, possibly zero. Returns 0 for an invalid suffix, or a
    flag vector describing the suffix.  */
@@ -219,11 +226,138 @@
 	     : (l == 1) ? CPP_N_MEDIUM : CPP_N_LARGE));
 }
 
+/* Return the classification flags for an int suffix.  */
+unsigned int
+cpp_interpret_int_suffix (const char *s, size_t len)
+{
+  return interpret_int_suffix ((const unsigned char *)s, len);
+}
+
+/* Return the string type corresponding to the the input user-defined string
+   literal type.  If the input type is not a user-defined string literal
+   type return the input type.  */
+enum cpp_ttype
+cpp_userdef_string_remove_type (enum cpp_ttype type)
+{
+  if (type == CPP_STRING_USERDEF)
+    return CPP_STRING;
+  else if (type == CPP_WSTRING_USERDEF)
+    return CPP_WSTRING;
+  else if (type == CPP_STRING16_USERDEF)
+    return CPP_STRING16;
+  else if (type == CPP_STRING32_USERDEF)
+    return CPP_STRING32;
+  else if (type == CPP_UTF8STRING_USERDEF)
+    return CPP_UTF8STRING;
+  else
+    return type;
+}
+
+/* Return the user-defined string literal type corresponding to the input
+   string type.  If the input type is not a string type return the input
+   type.  */
+enum cpp_ttype
+cpp_userdef_string_add_type (enum cpp_ttype type)
+{
+  if (type == CPP_STRING)
+    return CPP_STRING_USERDEF;
+  else if (type == CPP_WSTRING)
+    return CPP_WSTRING_USERDEF;
+  else if (type == CPP_STRING16)
+    return CPP_STRING16_USERDEF;
+  else if (type == CPP_STRING32)
+    return CPP_STRING32_USERDEF;
+  else if (type == CPP_UTF8STRING)
+    return CPP_UTF8STRING_USERDEF;
+  else
+    return type;
+}
+
+/* Return the char type corresponding to the the input user-defined char
+   literal type.  If the input type is not a user-defined char literal
+   type return the input type.  */
+enum cpp_ttype
+cpp_userdef_char_remove_type (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR_USERDEF)
+    return CPP_CHAR;
+  else if (type == CPP_WCHAR_USERDEF)
+    return CPP_WCHAR;
+  else if (type == CPP_CHAR16_USERDEF)
+    return CPP_STRING16;
+  else if (type == CPP_CHAR32_USERDEF)
+    return CPP_STRING32;
+  else
+    return type;
+}
+
+/* Return the user-defined char literal type corresponding to the input
+   char type.  If the input type is not a char type return the input
+   type.  */
+enum cpp_ttype
+cpp_userdef_char_add_type (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR)
+    return CPP_CHAR_USERDEF;
+  else if (type == CPP_WCHAR)
+    return CPP_WCHAR_USERDEF;
+  else if (type == CPP_CHAR16)
+    return CPP_CHAR16_USERDEF;
+  else if (type == CPP_CHAR32)
+    return CPP_CHAR32_USERDEF;
+  else
+    return type;
+}
+
+/* Return true if the token type is a user-defined string literal.  */
+bool
+cpp_userdef_string_p (enum cpp_ttype type)
+{
+  if (type == CPP_STRING_USERDEF
+   || type == CPP_WSTRING_USERDEF
+   || type == CPP_STRING16_USERDEF
+   || type == CPP_STRING32_USERDEF
+   || type == CPP_UTF8STRING_USERDEF)
+    return true;
+  else
+    return false;
+}
+
+/* Return true if the token type is a user-defined char literal.  */
+bool
+cpp_userdef_char_p (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR_USERDEF
+   || type == CPP_WCHAR_USERDEF
+   || type == CPP_CHAR16_USERDEF
+   || type == CPP_CHAR32_USERDEF)
+    return true;
+  else
+    return false;
+}
+
+/* Extract the suffix from a user-defined literal string or char.  */
+void
+cpp_get_userdef_suffix (cpp_string string, char delim, const char **suffix)
+{
+  unsigned int len = string.len;
+  const char *text = (const char *)string.text;
+  int i;
+  for (i = len; i > 0; --i)
+    {
+      if (text[i - 1] == delim)
+	break;
+    }
+  *suffix = text + i;
+}
+
 /* Categorize numeric constants according to their field (integer,
    floating point, or invalid), radix (decimal, octal, hexadecimal),
-   and type suffixes.  */
+   and type suffixes.  In C++0X if UD_SUFFIX is non null it will be
+   assigned any unrecognized suffix for a user-defined literal.  */
 unsigned int
-cpp_classify_number (cpp_reader *pfile, const cpp_token *token)
+cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
+		     const char **ud_suffix)
 {
   const uchar *str = token->val.str.text;
   const uchar *limit;
@@ -231,6 +365,9 @@
   enum {NOT_FLOAT = 0, AFTER_POINT, AFTER_EXPON} float_flag;
   bool seen_digit;
 
+  if (ud_suffix)
+    *ud_suffix = NULL;
+
   /* If the lexer has done its job, length one can only be a single
      digit.  Fast-path this very common case.  */
   if (token->val.str.len == 1)
@@ -361,10 +498,19 @@
       result = interpret_float_suffix (str, limit - str);
       if (result == 0)
 	{
-	  cpp_error (pfile, CPP_DL_ERROR,
-		     "invalid suffix \"%.*s\" on floating constant",
-		     (int) (limit - str), str);
-	  return CPP_N_INVALID;
+	  if (CPP_OPTION (pfile, cxx11))
+	    {
+	      if (ud_suffix)
+		*ud_suffix = (const char *) str;
+	      result = CPP_N_LARGE | CPP_N_USERDEF;
+	    }
+	  else
+	    {
+	      cpp_error (pfile, CPP_DL_ERROR,
+			 "invalid suffix \"%.*s\" on floating constant",
+			 (int) (limit - str), str);
+	      return CPP_N_INVALID;
+	    }
 	}
 
       /* Traditional C didn't accept any floating suffixes.  */
@@ -406,10 +552,19 @@
       result = interpret_int_suffix (str, limit - str);
       if (result == 0)
 	{
-	  cpp_error (pfile, CPP_DL_ERROR,
-		     "invalid suffix \"%.*s\" on integer constant",
-		     (int) (limit - str), str);
-	  return CPP_N_INVALID;
+	  if (CPP_OPTION (pfile, cxx11))
+	    {
+	      if (ud_suffix)
+		*ud_suffix = (const char *) str;
+	      result = CPP_N_UNSIGNED | CPP_N_LARGE | CPP_N_USERDEF;
+	    }
+	  else
+	    {
+	      cpp_error (pfile, CPP_DL_ERROR,
+			 "invalid suffix \"%.*s\" on integer constant",
+			 (int) (limit - str), str);
+	      return CPP_N_INVALID;
+	    }
 	}
 
       /* Traditional C only accepted the 'L' suffix.
@@ -748,7 +903,7 @@
   switch (token->type)
     {
     case CPP_NUMBER:
-      temp = cpp_classify_number (pfile, token);
+      temp = cpp_classify_number (pfile, token, NULL);
       switch (temp & CPP_N_CATEGORY)
 	{
 	case CPP_N_FLOATING:
Index: libcpp/lex.c
===================================================================
--- libcpp/lex.c	(revision 178919)
+++ libcpp/lex.c	(working copy)
@@ -1227,6 +1227,7 @@
   token->type = type;
   token->val.str.len = len;
   token->val.str.text = dest;
+/*printf("\ntoken: %s", token->val.str.text);*/
 }
 
 /* Subroutine of lex_raw_string: Append LEN chars from BASE to the buffer
@@ -1478,6 +1479,21 @@
     }
  break_outer_loop:
 
+  if (CPP_OPTION (pfile, cxx11))
+    {
+      /* Grab user defined literal suffix.  */
+      if (ISIDST(*cur))
+	{
+	  type = cpp_userdef_char_add_type (type);
+	  type = cpp_userdef_string_add_type (type);
+	  ++cur;
+	}
+      while (ISIDNUM(*cur))
+	{
+	  ++cur;
+	}
+    }
+
   pfile->buffer->cur = cur;
   if (first_buff == NULL)
     create_literal (pfile, token, base, cur - base, type);
@@ -1581,6 +1597,21 @@
     cpp_error (pfile, CPP_DL_PEDWARN, "missing terminating %c character",
 	       (int) terminator);
 
+  if (CPP_OPTION (pfile, cxx11))
+    {
+      /* Grab user defined literal suffix.  */
+      if (ISIDST(*cur))
+	{
+	  type = cpp_userdef_char_add_type (type);
+	  type = cpp_userdef_string_add_type (type);
+          ++cur;
+	}
+      while (ISIDNUM(*cur))
+	{
+	  ++cur;
+	}
+    }
+
   pfile->buffer->cur = cur;
   create_literal (pfile, token, base, cur - base, type);
 }

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-09-19  8:33   ` Ed Smith-Rowland
@ 2011-09-19 22:43     ` Jason Merrill
  2011-09-20  7:23       ` Ed Smith-Rowland
  0 siblings, 1 reply; 36+ messages in thread
From: Jason Merrill @ 2011-09-19 22:43 UTC (permalink / raw)
  To: Ed Smith-Rowland; +Cc: gcc-patches

On 09/19/2011 04:22 AM, Ed Smith-Rowland wrote:
> +check_literal_operator_args( const_tree decl,

Space before the (, not after.

> Done.  I am now storing the numeric string along with the number and the suffix ID for numeric operators.  I'm keeping the numeric value because we need it too.

Can't you store the string and the suffix, and then interpret the number 
later if you end up calling an operator that takes the value?

Jason

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-09-14  8:00 ` Jason Merrill
@ 2011-09-19  8:33   ` Ed Smith-Rowland
  2011-09-19 22:43     ` Jason Merrill
  0 siblings, 1 reply; 36+ messages in thread
From: Ed Smith-Rowland @ 2011-09-19  8:33 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 7070 bytes --]

On 09/13/2011 09:52 PM, Jason Merrill wrote:
> Since we're starting to come up on the end of stage 1, I'll go ahead 
> and review the current patch even though it isn't finished yet.  
> Thanks for all your work on this, it definitely seems to be coming 
> together.
>
> On 09/13/2011 10:35 AM, Ed Smith-Rowland wrote:
>> +#define CPP_N_USERDEF  0x1000000 /* C++0x user-defned literal.  */
>
> "defined"
Done.
>
>> -extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *);
>> +extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *,
>> +                                    char **ud_suffix);
>> +
>> +/* Return the classification flags for a float suffix.  */
>> +unsigned int cpp_interpret_float_suffix (const char *s, size_t len);
>> +
>> +/* Return the classification flags for an int suffix.  */
>> +unsigned int cpp_interpret_int_suffix (const char *s, size_t len);
>>
>>  /* Evaluate a token classified as category CPP_N_INTEGER.  */
>>  extern cpp_num cpp_interpret_integer (cpp_reader *, const cpp_token *,
>
> Let's follow the pattern of the existing declarations by adding 
> explicit 'extern' and not naming the parameters.
Done.
>
>> @@ -327,6 +327,10 @@ pp_cxx_constant (cxx_pretty_printer *pp, tree t)
>> +    case USERDEF_LITERAL:
>> +      pp_c_constant (pp_c_base (pp), USERDEF_LITERAL_VALUE (t));
>> +      break;
>> @@ -1755,6 +1757,11 @@ dump_expr (tree t, int flags)
>> +    case USERDEF_LITERAL:
>> +      pp_constant (cxx_pp, USERDEF_LITERAL_VALUE (t));
>> +      dump_decl (USERDEF_LITERAL_SUFFIX_ID (t), flags);
>> +      break;
>
> These should be the same--or just call pp_cxx_constant from dump_expr.
Done, I think.
>
>> +/* Extract the suffix from a user-defined literal string or char.  */
>> +void
>> +cpp_get_userdef_suffix (cpp_string string, char delim, char *suffix)
>> +{
>> +  unsigned int len = string.len;
>> +  const char *text = (const char *)string.text;
>> +  int i;
>> +  for (i = len; i > 0; --i)
>> +    {
>> +      if (text[i - 1] == delim)
>> +       break;
>> +    }
>> +  strncpy (suffix, text + i, len - i);
>> +  suffix[len - i] = '\0';
>> +}
>
> Since you're just going to be passing the pointer to get_identifier 
> anyway, we don't need to copy the suffix into the pointer.  Just 
> return a pointer to the start of the suffix.
Done.
>
>> +             if (ud_suffix)
>> +               *ud_suffix = xstrdup ((const char *)str);
>
> Similarly here.
Done.
>
>> +             const char *curr_suffix = NULL;
>> +             suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value);
>> +             curr_suffix = IDENTIFIER_POINTER (suffix_id);
>> +             if (have_suffix_p == 0)
>> +               {
>> +                 suffix = xstrdup (curr_suffix);
>> +                 have_suffix_p = 1;
>> +               }
>> +             else if (have_suffix_p == 1 && strcmp (suffix, 
>> curr_suffix) != 0)
>
> And here, you can compare the identifiers with ==, since identifiers 
> are unique.
Done.
>
>> +                 error ("inconsistent user-defined literal suffixes");
>
> Let's print the suffixes involved.
Done.
>
>> +             error ("%qD has illegal argument list", decl);
>
> Use "invalid" rather than "illegal".
Done.
>
>> +         suffix = UDLIT_OP_SUFFIX (DECL_NAME (decl));
>> +         if (long_long_unsigned_p)
>> +           {
>> +             if (cpp_interpret_int_suffix (suffix, strlen (suffix)))
>> +               warning (0, "integer suffix shadowed by 
>> implementation");
>> +           }
>> +         else if (long_double_p)
>> +           {
>> +             if (cpp_interpret_float_suffix (suffix, strlen (suffix)))
>> +               warning (0, "floating point suffix"
>> +                           " shadowed by implementation");
>> +           }
>
> Let's print the suffix as part of the warning.
Done.
>
>> +  if (dname
>> + && TREE_CODE (dname) == IDENTIFIER_NODE
>> + && UDLIT_OPER_P (dname)
>> + && innermost_code != cdk_function
>> + && ! (ctype && !declspecs->any_specifiers_p))
>
> I think we can drop the last check, as it only applies to constructors.
Done.
>
>> +/* User-defined literal operator.
>> +DEF_SIMPLE_OPERATOR ("\"\"", USERDEF_LITERAL_EXPR, "ud", 1)  */
>
> Are you planning to use this for something?
Removed.
>
>> +/* Parse a user-defined char constant.  Returns a call to a 
>> user-defined
>> +   literal operator taking the character as an argument.  */
>> +static tree
>> +cp_parser_userdef_char_literal (cp_parser *parser)
>
> There should be a blank line after the comment here and before the 
> other new functions, at least in gcc/.
Done in as many of my places as I could find.
>
>> +make_numeric_string(tree value)
>
> This function tries to recreate a printed form for a numeric constant, 
> but that's not right; we need the actual source characters, which are 
> likely to be different, especially for floating-point numbers.  So we 
> need to get back to the actual spelling of the token here.
>
> I notice that later in cp_parser_userdef_numeric_literal when calling 
> the variadic template version you assume that you have the spelling of 
> the token, which is indeed what we want.
Done.  I am now storing the numeric string along with the number and the 
suffix ID for numeric operators.  I'm keeping the numeric value because 
we need it too.
>
>> +check_literal_operator_args(const_tree decl,
>
> Space before (.
Done.
>
>> +      tree const_char_ptr_type_node
>> +          = build_pointer_type(build_type_variant(char_type_node, 1, 
>> 0));
>> +      tree const_wchar_ptr_type_node
>> +          = build_pointer_type(build_type_variant(wchar_type_node, 
>> 1, 0));
>> +      tree const_char16_ptr_type_node
>> +          = build_pointer_type(build_type_variant(char16_type_node, 
>> 1, 0));
>> +      tree const_char32_ptr_type_node
>> +          = build_pointer_type(build_type_variant(char32_type_node, 
>> 1, 0));
>
> It seems to me that rather than build these up to compare against, it 
> it would be faster to check for POINTER_TYPE, then check that the 
> pointed-to type is CP_TYPE_CONST_NON_VOLATILE_P, and then compare the 
> TYPE_MAIN_VARIANT to char_type_node, etc.
I tried this and couldn't get it to work.  I got a bunch of false 
negatives and then a crash.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
>
>> +++ b/gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C
>> @@ -0,0 +1,16 @@
>> +// { dg-options "-std=c++0x" }
>> +
>> +//  Both of these can't have *both* of these.
>> +
>> +int
>> +operator"" _abc(const char*)
>> +  {
>> +    return 42;
>> +  }
>> +
>> +template<char...>
>> +  int
>> +  operator"" _abc()
>> +  {
>> +    return 13;
>> +  }
>
> Shouldn't this have a dg-error tag somewhere?
I'm working on checking this.  I need to test if both
   operator"" _foo(char*)
and
   template <char...>
     _foo();
are declared and error.  I'l looking over decl.c for this.
If I can't figure that out I'll take out the test.
>
> Jason
>
Attached are the results to date.

[-- Attachment #2: patch19 --]
[-- Type: text/plain, Size: 67659 bytes --]

Index: gcc/c-family/c-common.c
===================================================================
--- gcc/c-family/c-common.c	(revision 178919)
+++ gcc/c-family/c-common.c	(working copy)
@@ -9919,4 +9919,17 @@
   MARK_TS_TYPED (EXCESS_PRECISION_EXPR);
 }
 
+/* Build a user-defined numeric literal out of an integer constant type VALUE
+   with identifier SUFFIX.  */
+
+tree
+build_userdef_literal (tree suffix_id, tree value, tree num_string)
+{
+  tree literal = make_node (USERDEF_LITERAL);
+  USERDEF_LITERAL_SUFFIX_ID (literal) = suffix_id;
+  USERDEF_LITERAL_VALUE (literal) = value;
+  USERDEF_LITERAL_NUM_STRING (literal) = num_string;
+  return literal;
+}
+
 #include "gt-c-family-c-common.h"
Index: gcc/c-family/c-lex.c
===================================================================
--- gcc/c-family/c-lex.c	(revision 178919)
+++ gcc/c-family/c-lex.c	(working copy)
@@ -44,8 +44,8 @@
 int pending_lang_change; /* If we need to switch languages - C++ only */
 int c_header_level;	 /* depth in C headers - C++ only */
 
-static tree interpret_integer (const cpp_token *, unsigned int);
-static tree interpret_float (const cpp_token *, unsigned int);
+static tree interpret_integer (const cpp_token *, unsigned int, const char *);
+static tree interpret_float (const cpp_token *, unsigned int, const char *);
 static tree interpret_fixed (const cpp_token *, unsigned int);
 static enum integer_type_kind narrowest_unsigned_type
 	(unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned int);
@@ -314,7 +314,8 @@
 
     case CPP_NUMBER:
       {
-	unsigned int flags = cpp_classify_number (parse_in, tok);
+	const char *suffix = NULL;
+	unsigned int flags = cpp_classify_number (parse_in, tok, &suffix);
 
 	switch (flags & CPP_N_CATEGORY)
 	  {
@@ -328,16 +329,27 @@
 	       Set PURE_ZERO to pass this information to the C++ parser.  */
 	    if (tok->val.str.len == 1 && *tok->val.str.text == '0')
 	      add_flags = PURE_ZERO;
-	    *value = interpret_integer (tok, flags);
+	    *value = interpret_integer (tok, flags, suffix);
 	    break;
 
 	  case CPP_N_FLOATING:
-	    *value = interpret_float (tok, flags);
+	    *value = interpret_float (tok, flags, suffix);
 	    break;
 
 	  default:
 	    gcc_unreachable ();
 	  }
+
+	if (flags & CPP_N_USERDEF)
+	  {
+	    tree num_string = build_string (tok->val.str.len - strlen (suffix),
+					    (const char *) tok->val.str.text);
+	    TREE_TYPE (num_string) = char_array_type_node;
+	    num_string = fix_string_type (num_string);
+	    tree literal = build_userdef_literal (get_identifier (suffix),
+						  *value, num_string);
+	    *value = literal;
+	  }
       }
       break;
 
@@ -415,6 +427,23 @@
       }
       goto retry;
 
+    case CPP_CHAR_USERDEF:
+    case CPP_WCHAR_USERDEF:
+    case CPP_CHAR16_USERDEF:
+    case CPP_CHAR32_USERDEF:
+      {
+	tree literal;
+	cpp_token temp_tok = *tok;
+	const char *suffix;
+	cpp_get_userdef_suffix (tok->val.str, '\'', &suffix);
+	temp_tok.val.str.len -= strlen (suffix);
+	temp_tok.type = cpp_userdef_char_remove_type (type);
+	literal = build_userdef_literal (get_identifier (suffix),
+					 lex_charconst (&temp_tok), NULL_TREE);
+	*value = literal;
+      }
+      break;
+
     case CPP_CHAR:
     case CPP_WCHAR:
     case CPP_CHAR16:
@@ -422,6 +451,23 @@
       *value = lex_charconst (tok);
       break;
 
+    case CPP_STRING_USERDEF:
+    case CPP_WSTRING_USERDEF:
+    case CPP_STRING16_USERDEF:
+    case CPP_STRING32_USERDEF:
+    case CPP_UTF8STRING_USERDEF:
+      {
+	tree literal, string;
+	const char *suffix;
+	cpp_get_userdef_suffix (tok->val.str, '"', &suffix);
+	string = build_string (tok->val.str.len - strlen (suffix),
+			       (const char *) tok->val.str.text);
+	literal = build_userdef_literal (get_identifier (suffix),
+					 string, NULL_TREE);
+	*value = literal;
+      }
+      break;
+
     case CPP_STRING:
     case CPP_WSTRING:
     case CPP_STRING16:
@@ -536,9 +582,11 @@
   return itk_none;
 }
 
-/* Interpret TOKEN, an integer with FLAGS as classified by cpplib.  */
+/* Interpret TOKEN, an integer with FLAGS as classified by cpplib.
+   For C++0X SUFFIX may contain a user-defined literal suffix.  */
 static tree
-interpret_integer (const cpp_token *token, unsigned int flags)
+interpret_integer (const cpp_token *token, unsigned int flags,
+		   const char *suffix)
 {
   tree value, type;
   enum integer_type_kind itk;
@@ -621,9 +669,10 @@
 }
 
 /* Interpret TOKEN, a floating point number with FLAGS as classified
-   by cpplib.  */
+   by cpplib.  For C++0X SUFFIX may contain a user-defined literal suffix.  */
 static tree
-interpret_float (const cpp_token *token, unsigned int flags)
+interpret_float (const cpp_token *token, unsigned int flags,
+		 const char *suffix)
 {
   tree type;
   tree const_type;
@@ -702,7 +751,9 @@
      has any suffixes, cut them off; REAL_VALUE_ATOF/ REAL_VALUE_HTOF
      can't handle them.  */
   copylen = token->val.str.len;
-  if (flags & CPP_N_DFLOAT)
+  if (flags & CPP_N_USERDEF)
+    copylen -= strlen (suffix);
+  else if (flags & CPP_N_DFLOAT)
     copylen -= 2;
   else
     {
Index: gcc/c-family/c-common.h
===================================================================
--- gcc/c-family/c-common.h	(revision 178919)
+++ gcc/c-family/c-common.h	(working copy)
@@ -1067,4 +1067,27 @@
   return NULL;
 }
 
+/* A suffix-identifier value doublet that represents user-defined literals
+   for C++-0x.  */
+struct GTY(()) tree_userdef_literal {
+  struct tree_common common;
+  tree suffix_id;
+  tree value;
+  tree num_string;
+};
+
+#define USERDEF_LITERAL_SUFFIX_ID(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->suffix_id)
+
+#define USERDEF_LITERAL_VALUE(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->value)
+
+#define USERDEF_LITERAL_NUM_STRING(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->num_string)
+
+#define USERDEF_LITERAL_TYPE(NODE) \
+  (TREE_TYPE (USERDEF_LITERAL_VALUE (NODE)))
+
+extern tree build_userdef_literal (tree suffix_id, tree value, tree num_string);
+
 #endif /* ! GCC_C_COMMON_H */
Index: gcc/c-family/c-common.def
===================================================================
--- gcc/c-family/c-common.def	(revision 178919)
+++ gcc/c-family/c-common.def	(working copy)
@@ -47,6 +47,12 @@
    evaluated.  */
 DEFTREECODE (EXCESS_PRECISION_EXPR, "excess_precision_expr", tcc_expression, 1)
 
+/* Used to represent a user-defined literal.
+   The operands are an IDENTIFIER for the suffix, the VALUE of the literal,
+   and for numeric literals the original string representation of the
+   number.  */
+DEFTREECODE (USERDEF_LITERAL, "userdef_literal", tcc_exceptional, 3)
+
 /*
 Local variables:
 mode:c
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C	(revision 0)
@@ -0,0 +1,4 @@
+// { dg-options -std=c++0x }
+
+template<char...>
+  int operator"" _xyz(unsigned long long);	// { dg-error "has illegal argument list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit_system_header
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit_system_header	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit_system_header	(revision 0)
@@ -0,0 +1,6 @@
+
+#pragma GCC system_header
+
+char
+operator"" stdsuffix(char __c)
+{ return __c/2; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C	(revision 0)
@@ -0,0 +1,16 @@
+// { dg-options "-std=c++0x" }
+
+//  Both of these can't have *both* of these.
+
+int
+operator"" _abc(const char*)
+  {
+    return 42;
+  }
+
+template<char...>
+  int
+  operator"" _abc()
+  {
+    return 13;
+  }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C	(revision 0)
@@ -0,0 +1,43 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test simple operator declaration and definition in namespaces.
+
+#include <cmath>
+#include <limits>
+
+namespace Long
+{
+  long double operator"" _LL(long double);
+}
+
+namespace Short
+{
+  short
+  operator"" _SS(long double x)
+  { return std::fmod(x, static_cast<long double>(std::numeric_limits<short>::max())); }
+}
+
+void
+test1()
+{
+  long double x = Long::operator "" _LL(1.2L);
+
+  using namespace Short;
+  short s = operator"" _SS(1.2L);
+  short s2 = 1.2_SS;
+}
+
+int
+main()
+{
+  test1();
+}
+
+namespace Long
+{
+  long double
+  operator"" _LL(long double x)
+  { return x + 2.0L; }
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C	(revision 0)
@@ -0,0 +1,8 @@
+// { dg-options -std=c++0x }
+
+class Foo
+{
+public:
+  Foo() { }
+  int operator"" _Bar(char32_t) { return 42; }	// { dg-error "must be a non-member function" }
+};
Index: gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C	(revision 0)
@@ -0,0 +1,38 @@
+// { dg-options -std=c++0x }
+
+#include <cstddef>
+
+class Foo { };
+
+Foo
+operator"" _Foo(int *);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(unsigned long int);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(double);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(const float *, std::size_t);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(const wchar_t *, int);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(const char16_t *);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(char...);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(unsigned long long int, char);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(const char *, std::size_t, int);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(long double &);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(std::size_t, const char16_t *);	// { dg-error "has illegal argument list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C	(revision 0)
@@ -0,0 +1,17 @@
+// { dg-options "-std=c++98" }
+
+#include <cstddef>
+
+int
+operator"" _mm(long double m)	// { dg-warning "user-defined literals only available with" }
+{ return int(1000.0L * m); }
+
+int in = 0.0254_mm;	// { dg-error "invalid suffix" }
+
+int
+operator"" _Q(const char *, std::size_t)	// { dg-warning "user-defined literals only available with" }
+{ return 42; }
+
+int x = "Hello"_Q;	// { dg-error "invalid conversion from" }
+
+// { dg-error "expected" "" { target *-*-* } 15 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+#include <string>
+
+std::string operator"" 5X(const char*, std::size_t);	// { dg-error "expected suffix identifier" }
+
+// { dg-error "expected type-specifier before string constant" "" { target *-*-* } 5 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+constexpr unsigned long long
+operator"" _grow(unsigned long long n)
+{ return 2 * n; }
+
+double buffer[25_grow];
Index: gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C	(revision 0)
@@ -0,0 +1,49 @@
+// { dg-options -std=c++0x }
+
+//  Test that the standard suffixes shadow any user-defined suffixes of the same name.
+long double
+operator"" L(long double x)	// { dg-warning "floating point suffix shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ULL(unsigned long long int k)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return k; }
+
+long double
+operator"" l(long double x)	// { dg-warning "floating point suffix shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ull(unsigned long long int k)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return k; }
+
+//  Namespaces are no hiding place.
+namespace Long
+{
+
+long double
+operator"" L(long double x)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ULL(unsigned long long int k)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return k; }
+
+long double
+operator"" l(long double x)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ull(unsigned long long int k)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return k; }
+
+}
+
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 5 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 9 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 13 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 17 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 25 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 29 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 33 }
+// { dg-warning "suffixes not preceded by|are reserved for future standardization" "" { target *-*-* } 37 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test warning on declaration without leading underscore.
+
+long double operator"" nounder(long double); // { dg-warning "suffixes not preceded by|are reserved for future standardization" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options -std=c++0x }
+
+class Foo { };
+
+template<wchar_t...>	// { dg-error "" }
+  Foo operator"" _Foo();
Index: gcc/testsuite/g++.dg/cpp0x/udlit-general.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-general.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-general.C	(revision 0)
@@ -0,0 +1,47 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test simple operator declaration and definition.
+
+#include <string>
+#include <complex>
+
+long double operator"" _v(long double);
+std::string operator"" _w(const char16_t*, size_t);
+unsigned operator"" _w(const char*);
+
+std::complex<double>
+operator"" _i(long double y)
+{ return std::complex<double>(0.0L, y); }
+
+void
+test1()
+{
+  long double x = operator"" _v(1.2L);
+
+  std::string s = operator"" _w(u"one", 3);
+
+  unsigned u = operator"" _w("Hello, World!");
+  unsigned u2 = operator"" _w("Hello, World!");
+
+  std::complex<double> i = operator"" _i(2.0);
+}
+
+int
+main()
+{
+  test1();
+}
+
+long double
+operator"" _v(long double x)
+{ return x + 1.0L; }
+
+std::string
+operator"" _w(const char16_t*, size_t)
+{ return std::string("boo"); }
+
+unsigned
+operator"" _w(const char*)
+{ return 0U; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-systemheader.C	(revision 0)
@@ -0,0 +1,3 @@
+// { dg-options -std=c++0x }
+
+#include "udlit_system_header"
Index: gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C	(revision 0)
@@ -0,0 +1,15 @@
+// { dg-options -std=c++0x }
+
+#include <string>
+
+std::string operator"" _i18n(const char*, std::size_t);
+
+std::string vogon_poem = R"V0G0N(
+                O freddled gruntbuggly thy micturations are to me
+                    As plured gabbleblochits on a lurgid bee.
+                 Groop, I implore thee my foonting turlingdromes.   
+              And hooptiously drangle me with crinkly bindlewurdles,
+  Or I will rend thee in the gobberwarts with my blurlecruncheon, see if I don't.
+
+                    (by Prostetnic Vogon Jeltz; see p. 56/57)
+)V0G0N"_i18n;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test error on non-function declaration.
+
+double operator"" _baddecl; // { dg-error "as non-function" }
+
+template<char...>
+  int operator"" _badtmpldecl; // { dg-error "as non-function" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-addr.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-addr.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-addr.C	(revision 0)
@@ -0,0 +1,10 @@
+// { dg-options "-std=c++0x" }
+
+#include <cstddef>
+
+bool operator"" _yn(const char*, size_t);
+
+typedef bool (*pfunk)(const char*, size_t);
+pfunk p = &operator"" _yn;
+
+bool tf = p("Hello,\0 World!", 14);
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C	(revision 0)
@@ -0,0 +1,4 @@
+// { dg-options -std=c++0x }
+
+template<char...>
+  int operator"" _abc();
Index: gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C	(revision 0)
@@ -0,0 +1,8 @@
+// { dg-options -std=c++0x }
+
+extern "C" {
+
+int
+operator"" _badclinkage(unsigned long long);	// { dg-error "operator with C linkage" }
+
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-template.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-template.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-template.C	(revision 0)
@@ -0,0 +1,25 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test template operator declaration and definition.
+
+template<char...>
+  int operator"" _abc();
+
+int
+test1()
+{
+  int universal_meaning = operator"" _abc<'L','U','E'>();
+  int j = 1234567890_abc;
+}
+
+int
+main()
+{
+  test1();
+}
+
+template<char...>
+  int operator"" _abc()
+  { return 42; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-args.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-args.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-args.C	(revision 0)
@@ -0,0 +1,38 @@
+// { dg-options -std=c++0x }
+
+#include <cstddef>
+
+class Foo { };
+
+Foo
+operator"" _Foo(const char *);
+
+Foo
+operator"" _Foo(unsigned long long int);
+
+Foo
+operator"" _Foo(long double);
+
+Foo
+operator"" _Foo(char);
+
+Foo
+operator"" _Foo(wchar_t);
+
+Foo
+operator"" _Foo(char16_t);
+
+Foo
+operator"" _Foo(char32_t);
+
+Foo
+operator"" _Foo(const char *, std::size_t);
+
+Foo
+operator"" _Foo(const wchar_t *, std::size_t);
+
+Foo
+operator"" _Foo(const char16_t *, std::size_t);
+
+Foo
+operator"" _Foo(const char32_t *, std::size_t);
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+char32_t
+operator"" (char32_t C)
+{ return C; }	// { dg-error "expected suffix identifier" }
+
+// { dg-error "expected type-specifier before string constant" "" { target *-*-* } 4 }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test error on non-empty string after 'operator' keyword.
+
+double operator"hi" _badword(long double); // { dg-error "expected empty string after" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+extern "C"_badlinkage {	// { dg-error "expected unqualified-id before" }
+
+int foo();
+
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-friend.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-friend.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-friend.C	(revision 0)
@@ -0,0 +1,10 @@
+// { dg-options -std=c++0x }
+
+class Foo
+{
+public:
+  Foo() { }
+  friend Foo operator"" _Bar(char) { return Foo(); }
+};
+
+Foo f = 'x'_Bar;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+#include <string>
+
+std::string operator"" _xxx(const char*, size_t);
+
+std::string operator"" _yyy(const char*, size_t);
+
+std::string concat = "Hello, "_xxx "World!"_yyy;	// { dg-error "inconsistent user-defined literal suffixes" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options -std=c++0x }
+
+class Foo { };
+
+template<char...>
+  Foo operator"" _Foo();
Index: gcc/testsuite/g++.dg/cpp0x/udlit-concat.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-concat.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-concat.C	(revision 0)
@@ -0,0 +1,24 @@
+// { dg-options "-std=c++0x" }
+
+#include <string>
+
+std::string operator"" _www(const char*, size_t);
+
+std::string concat01 = "Hello, " "World!"_www;
+
+std::string concat10 = "Hello, "_www "World!";
+
+std::string concat11 = "Hello, "_www "World!"_www;
+
+
+class Tachyon { };
+
+Tachyon operator"" _fast(const char*, size_t);
+
+int operator"" _fast(const char32_t*, size_t);
+
+int speedy01 = "Hello, " U"World!"_fast;
+
+int speedy10 = "Hello, "_fast U"World!";
+
+int speedy11 = "Hello, "_fast U"World!"_fast;
Index: gcc/cp/typeck.c
===================================================================
--- gcc/cp/typeck.c	(revision 178919)
+++ gcc/cp/typeck.c	(working copy)
@@ -8321,3 +8321,94 @@
   return 1;
 }
 
+
+/* Return true if a user-defined literal operator has one of the allowed
+   argument types.  */
+
+bool
+check_literal_operator_args( const_tree decl,
+			     bool *long_long_unsigned_p, bool *long_double_p)
+{
+  tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
+  if (processing_template_decl)
+    return (argtypes == NULL_TREE
+	    || same_type_p (TREE_VALUE (argtypes), void_type_node));
+  else
+    {
+      tree argtype;
+      int arity;
+      int max_arity = 2;
+      bool found_string_p = false;
+      bool maybe_raw_p = false;
+      bool found_size_p = false;
+      tree const_char_ptr_type_node
+	   = build_pointer_type(build_type_variant(char_type_node, 1, 0));
+      tree const_wchar_ptr_type_node
+	   = build_pointer_type(build_type_variant(wchar_type_node, 1, 0));
+      tree const_char16_ptr_type_node
+	   = build_pointer_type(build_type_variant(char16_type_node, 1, 0));
+      tree const_char32_ptr_type_node
+	   = build_pointer_type(build_type_variant(char32_type_node, 1, 0));
+
+      *long_long_unsigned_p = false;
+      *long_double_p = false;
+
+      /* Count the number and type of arguments and check for ellipsis.  */
+      for (argtype = argtypes, arity = 0;
+	   argtype && argtype != void_list_node;
+	   argtype = TREE_CHAIN (argtype))
+	{
+	  tree t = TREE_VALUE (argtype);
+	  ++arity;
+
+	  if (same_type_p (t, const_char_ptr_type_node))
+	    {
+	      found_string_p = true;
+	      maybe_raw_p = true;
+	    }
+	  else if (same_type_p (t, const_wchar_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, const_char16_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, const_char32_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, size_type_node))
+	    {
+	      if (!found_string_p)
+		return false;
+	      found_size_p = true;
+	    }
+	  else if (same_type_p (t, long_long_unsigned_type_node))
+	    {
+	      max_arity = 1;
+	      *long_long_unsigned_p = true;
+	    }
+	  else if (same_type_p (t, long_double_type_node))
+	    {
+	      max_arity = 1;
+	      *long_double_p = true;
+	    }
+	  else if (same_type_p (t, char_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, wchar_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, char16_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, char32_type_node))
+	    max_arity = 1;
+	  else
+	    return false;
+	}
+      if (!argtype)
+	return false; /* Found ellipsis.  */
+
+      if (arity > max_arity)
+	return false;
+
+      if (found_string_p && !maybe_raw_p && !found_size_p)
+	return false;
+
+      return true;
+    }
+}
+
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 178919)
+++ gcc/cp/decl.c	(working copy)
@@ -7314,7 +7314,48 @@
   if (IDENTIFIER_OPNAME_P (DECL_NAME (decl))
       && !grok_op_properties (decl, /*complain=*/true))
     return NULL_TREE;
+  else if (UDLIT_OPER_P (DECL_NAME (decl)))
+    {
+      bool long_long_unsigned_p;
+      bool long_double_p;
+      const char *suffix = NULL;
+      /* [over.literal]/6: Literal operators shall not have C linkage. */
+      if (DECL_LANGUAGE(decl) == lang_c)
+	{
+	  error ("literal operator with C linkage");
+	  return NULL_TREE;
+	}
 
+      if (DECL_NAMESPACE_SCOPE_P (decl))
+	{
+	  if (!check_literal_operator_args(decl,
+					   &long_long_unsigned_p, &long_double_p))
+	    {
+	      error ("%qD has invalid argument list", decl);
+	      return NULL_TREE;
+	    }
+
+	  suffix = UDLIT_OP_SUFFIX (DECL_NAME (decl));
+	  if (long_long_unsigned_p)
+	    {
+	      if (cpp_interpret_int_suffix (suffix, strlen (suffix)))
+		warning (0, "integer suffix %<%s%>"
+			    " shadowed by implementation", suffix);
+	    }
+	  else if (long_double_p)
+	    {
+	      if (cpp_interpret_float_suffix (suffix, strlen (suffix)))
+		warning (0, "floating point suffix %<%s%>"
+			    " shadowed by implementation", suffix);
+	    }
+	}
+      else
+	{
+	  error ("%qD must be a non-member function", decl);
+	  return NULL_TREE;
+	}
+    }
+
   if (funcdef_flag)
     /* Make the init_value nonzero so pushdecl knows this is not
        tentative.  error_mark_node is replaced later with the BLOCK.  */
@@ -8498,6 +8539,15 @@
       error ("declaration of %qD as non-function", dname);
       return error_mark_node;
     }
+ 
+  if (dname
+      && TREE_CODE (dname) == IDENTIFIER_NODE
+      && UDLIT_OPER_P (dname)
+      && innermost_code != cdk_function)
+    {
+      error ("declaration of %qD as non-function", dname);
+      return error_mark_node;
+    }
 
   if (dname && IDENTIFIER_OPNAME_P (dname))
     {
@@ -13746,6 +13796,7 @@
     case TRAIT_EXPR:		return TS_CP_TRAIT_EXPR;
     case LAMBDA_EXPR:		return TS_CP_LAMBDA_EXPR;
     case TEMPLATE_INFO:		return TS_CP_TEMPLATE_INFO;
+    case USERDEF_LITERAL:	return TS_CP_USERDEF_LITERAL;
     default:			return TS_CP_GENERIC;
     }
 }
Index: gcc/cp/error.c
===================================================================
--- gcc/cp/error.c	(revision 178919)
+++ gcc/cp/error.c	(working copy)
@@ -1533,6 +1533,8 @@
     }
   else if (name && IDENTIFIER_OPNAME_P (name))
     pp_cxx_tree_identifier (cxx_pp, name);
+  else if (name && UDLIT_OPER_P (name))
+    pp_cxx_tree_identifier (cxx_pp, name);
   else
     dump_decl (name, flags);
 
@@ -1755,6 +1757,10 @@
       pp_constant (cxx_pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (cxx_pp, t);
+      break;
+
     case THROW_EXPR:
       /* While waiting for caret diagnostics, avoid printing
 	 __cxa_allocate_exception, __cxa_throw, and the like.  */
@@ -3230,14 +3236,19 @@
 	pedwarn (input_location, OPT_pedantic,
 		 "inline namespaces "
 		 "only available with -std=c++0x or -std=gnu++0x");
-	break;	
+	break;
       case CPP0X_OVERRIDE_CONTROLS:
 	pedwarn (input_location, 0,
 		 "override controls (override/final) "
 		 "only available with -std=c++0x or -std=gnu++0x");
         break;
+      case CPP0X_USER_DEFINED_LITERALS:
+	pedwarn (input_location, 0,
+		 "user-defined literals "
+		 "only available with -std=c++0x or -std=gnu++0x");
+	break;
       default:
-	gcc_unreachable();
+	gcc_unreachable ();
       }
 }
 
Index: gcc/cp/cxx-pretty-print.c
===================================================================
--- gcc/cp/cxx-pretty-print.c	(revision 178919)
+++ gcc/cp/cxx-pretty-print.c	(working copy)
@@ -367,6 +367,17 @@
     pp_cxx_unqualified_id (pp, t);
 }
 
+/* user-defined literal:
+      literal ud-suffix  */
+
+void
+pp_cxx_userdef_literal (cxx_pretty_printer *pp, tree t)
+{
+  pp_cxx_constant (pp, USERDEF_LITERAL_VALUE (t));
+  pp_cxx_id_expression (pp, USERDEF_LITERAL_SUFFIX_ID (t));
+}
+
+
 /* primary-expression:
      literal
      this
@@ -413,6 +424,10 @@
       pp_cxx_constant (pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (pp, t);
+      break;
+
     case BASELINK:
       t = BASELINK_FUNCTIONS (t);
     case VAR_DECL:
@@ -1023,6 +1038,10 @@
       pp_cxx_constant (pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_cxx_userdef_literal (pp, t);
+      break;
+
     case RESULT_DECL:
       pp_cxx_unqualified_id (pp, t);
       break;
Index: gcc/cp/semantics.c
===================================================================
--- gcc/cp/semantics.c	(revision 178919)
+++ gcc/cp/semantics.c	(working copy)
@@ -7748,6 +7748,7 @@
     case TEMPLATE_PARM_INDEX:
     case TRAIT_EXPR:
     case IDENTIFIER_NODE:
+    case USERDEF_LITERAL:
       /* We can see a FIELD_DECL in a pointer-to-member expression.  */
     case FIELD_DECL:
     case PARM_DECL:
Index: gcc/cp/cxx-pretty-print.h
===================================================================
--- gcc/cp/cxx-pretty-print.h	(revision 178919)
+++ gcc/cp/cxx-pretty-print.h	(working copy)
@@ -74,5 +74,7 @@
 void pp_cxx_trait_expression (cxx_pretty_printer *, tree);
 void pp_cxx_va_arg_expression (cxx_pretty_printer *, tree);
 void pp_cxx_offsetof_expression (cxx_pretty_printer *, tree);
+void pp_cxx_userdef_literal (cxx_pretty_printer *, tree);
 
+
 #endif /* GCC_CXX_PRETTY_PRINT_H */
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 178919)
+++ gcc/cp/parser.c	(working copy)
@@ -210,6 +210,8 @@
   (cp_lexer *);
 static void cp_lexer_rollback_tokens
   (cp_lexer *);
+static tree cp_literal_operator_id
+  (const char *);
 #ifdef ENABLE_CHECKING
 static void cp_lexer_print_token
   (FILE *, cp_token *);
@@ -501,20 +503,20 @@
 	}
       else
 	{
-          if (warn_cxx0x_compat
-              && C_RID_CODE (token->u.value) >= RID_FIRST_CXX0X
-              && C_RID_CODE (token->u.value) <= RID_LAST_CXX0X)
-            {
-              /* Warn about the C++0x keyword (but still treat it as
-                 an identifier).  */
-              warning (OPT_Wc__0x_compat, 
-                       "identifier %qE will become a keyword in C++0x",
-                       token->u.value);
+	  if (warn_cxx0x_compat
+	      && C_RID_CODE (token->u.value) >= RID_FIRST_CXX0X
+	      && C_RID_CODE (token->u.value) <= RID_LAST_CXX0X)
+	    {
+	      /* Warn about the C++0x keyword (but still treat it as
+		 an identifier).  */
+	      warning (OPT_Wc__0x_compat, 
+		       "identifier %qE will become a keyword in C++0x",
+		       token->u.value);
 
-              /* Clear out the C_RID_CODE so we don't warn about this
-                 particular identifier-turned-keyword again.  */
-              C_SET_RID_CODE (token->u.value, RID_MAX);
-            }
+	      /* Clear out the C_RID_CODE so we don't warn about this
+		 particular identifier-turned-keyword again.  */
+	      C_SET_RID_CODE (token->u.value, RID_MAX);
+	    }
 
 	  token->ambiguous_p = false;
 	  token->keyword = RID_MAX;
@@ -1528,6 +1530,12 @@
   (cp_parser *);
 static tree cp_parser_string_literal
   (cp_parser *, bool, bool);
+static tree cp_parser_userdef_char_literal
+  (cp_parser *);
+static tree cp_parser_userdef_string_literal
+  (cp_token *);
+static tree cp_parser_userdef_numeric_literal
+  (cp_parser *);
 
 /* Basic concepts [gram.basic]  */
 
@@ -2030,6 +2038,8 @@
   (cp_parser *);
 static bool cp_parser_allow_gnu_extensions_p
   (cp_parser *);
+static bool cp_parser_is_pure_string_literal
+  (cp_token *);
 static bool cp_parser_is_string_literal
   (cp_token *);
 static bool cp_parser_is_keyword
@@ -2050,7 +2060,7 @@
 /* Returns nonzero if TOKEN is a string literal.  */
 
 static bool
-cp_parser_is_string_literal (cp_token* token)
+cp_parser_is_pure_string_literal (cp_token* token)
 {
   return (token->type == CPP_STRING ||
 	  token->type == CPP_STRING16 ||
@@ -2059,6 +2069,20 @@
 	  token->type == CPP_UTF8STRING);
 }
 
+/* Returns nonzero if TOKEN is a string literal
+   of a user-defined string literal.  */
+
+static bool
+cp_parser_is_string_literal (cp_token* token)
+{
+  return (cp_parser_is_pure_string_literal (token) ||
+	  token->type == CPP_STRING_USERDEF ||
+	  token->type == CPP_STRING16_USERDEF ||
+	  token->type == CPP_STRING32_USERDEF ||
+	  token->type == CPP_WSTRING_USERDEF ||
+	  token->type == CPP_UTF8STRING_USERDEF);
+}
+
 /* Returns nonzero if TOKEN is the indicated KEYWORD.  */
 
 static bool
@@ -3098,7 +3122,11 @@
   struct obstack str_ob;
   cpp_string str, istr, *strs;
   cp_token *tok;
-  enum cpp_ttype type;
+  enum cpp_ttype type, curr_type;
+  int have_suffix_p = 0;
+  tree string_tree;
+  tree suffix_id = NULL_TREE;
+  bool curr_tok_is_userdef_p = false;
 
   tok = cp_lexer_peek_token (parser->lexer);
   if (!cp_parser_is_string_literal (tok))
@@ -3107,7 +3135,18 @@
       return error_mark_node;
     }
 
-  type = tok->type;
+  if (cpp_userdef_string_p (tok->type))
+    {
+      string_tree = USERDEF_LITERAL_VALUE (tok->u.value);
+      curr_type = cpp_userdef_string_remove_type (tok->type);
+      curr_tok_is_userdef_p = true;
+    }
+  else
+    {
+      string_tree = tok->u.value;
+      curr_type = tok->type;
+    }
+  type = curr_type;
 
   /* Try to avoid the overhead of creating and destroying an obstack
      for the common case of just one string.  */
@@ -3116,10 +3155,19 @@
     {
       cp_lexer_consume_token (parser->lexer);
 
-      str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value);
-      str.len = TREE_STRING_LENGTH (tok->u.value);
+      str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree);
+      str.len = TREE_STRING_LENGTH (string_tree);
       count = 1;
 
+      if (curr_tok_is_userdef_p)
+	{
+	  suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value);
+	  have_suffix_p = 1;
+	  curr_type = cpp_userdef_string_remove_type (tok->type);
+	}
+      else
+	curr_type = tok->type;
+
       strs = &str;
     }
   else
@@ -3131,14 +3179,35 @@
 	{
 	  cp_lexer_consume_token (parser->lexer);
 	  count++;
-	  str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value);
-	  str.len = TREE_STRING_LENGTH (tok->u.value);
+	  str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree);
+	  str.len = TREE_STRING_LENGTH (string_tree);
 
-	  if (type != tok->type)
+	  if (curr_tok_is_userdef_p)
 	    {
+	      tree curr_suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value);
+	      if (have_suffix_p == 0)
+		{
+		  suffix_id = curr_suffix_id;
+		  have_suffix_p = 1;
+		}
+	      else if (have_suffix_p == 1
+		       && curr_suffix_id != suffix_id)
+		{
+		  error ("inconsistent user-defined literal suffixes"
+			 " %qD and %qD in string literal",
+			 suffix_id, curr_suffix_id);
+		  have_suffix_p = -1;
+		}
+	      curr_type = cpp_userdef_string_remove_type (tok->type);
+	    }
+	  else
+	    curr_type = tok->type;
+
+	  if (type != curr_type)
+	    {
 	      if (type == CPP_STRING)
-		type = tok->type;
-	      else if (tok->type != CPP_STRING)
+		type = curr_type;
+	      else if (curr_type != CPP_STRING)
 		error_at (tok->location,
 			  "unsupported non-standard concatenation "
 			  "of string literals");
@@ -3147,6 +3216,18 @@
 	  obstack_grow (&str_ob, &str, sizeof (cpp_string));
 
 	  tok = cp_lexer_peek_token (parser->lexer);
+	  if (cpp_userdef_string_p (tok->type))
+	    {
+	      string_tree = USERDEF_LITERAL_VALUE (tok->u.value);
+	      curr_type = cpp_userdef_string_remove_type (tok->type);
+	      curr_tok_is_userdef_p = true;
+	    }
+	  else
+	    {
+	      string_tree = tok->u.value;
+	      curr_type = tok->type;
+	      curr_tok_is_userdef_p = false;
+	    }
 	}
       while (cp_parser_is_string_literal (tok));
 
@@ -3184,6 +3265,13 @@
 	}
 
       value = fix_string_type (value);
+
+      if (have_suffix_p)
+	{
+	  tree literal = build_userdef_literal (suffix_id, value, NULL_TREE);
+	  tok->u.value = literal;
+	  return cp_parser_userdef_string_literal (tok);
+	}
     }
   else
     /* cpp_interpret_string has issued an error.  */
@@ -3195,7 +3283,183 @@
   return value;
 }
 
+/* Parse a user-defined char constant.  Returns a call to a user-defined
+   literal operator taking the character as an argument.  */
 
+static tree
+cp_parser_userdef_char_literal (cp_parser *parser)
+{
+  cp_token *token = NULL;
+  tree literal, suffix_id, value;
+  tree name, decl;
+  tree result;
+  VEC(tree,gc) *vec;
+
+  token = cp_lexer_consume_token (parser->lexer);
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  value = USERDEF_LITERAL_VALUE (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  vec = make_tree_vector ();
+  VEC_safe_push (tree, gc, vec, value);
+  decl = lookup_function_nonclass (name, vec, /*block_p=*/false);
+  if (decl == error_mark_node)
+    {
+      error ("unable to find user-defined literal operator declaration");
+      release_tree_vector (vec);
+      return error_mark_node;
+    }
+  result = finish_call_expr (decl, &vec, false, true, tf_warning_or_error);
+  release_tree_vector (vec);
+
+  return result;
+}
+
+/* A subroutine of cp_parser_userdef_numeric_literal to
+   create a char... template parameter pack from a string node.  */
+
+static tree
+make_char_string_pack (tree value)
+{
+  tree parmvec;
+  tree argpack = make_node (NONTYPE_ARGUMENT_PACK);
+  const char *str = TREE_STRING_POINTER (value);
+  int i, len = TREE_STRING_LENGTH (value) - 1;
+  /*  Do I need to stuff THIS into a tree? */
+  tree argvec = make_tree_vec (1);
+
+  /* Fill in PARMVEC with all of the parameters.  */
+  parmvec = make_tree_vec (len);
+  for (i = 0; i < len; ++i)
+    TREE_VEC_ELT (parmvec, i) = build_int_cst (char_type_node, str[i]);
+
+  /* Build the argument packs.  */
+  SET_ARGUMENT_PACK_ARGS (argpack, parmvec);
+  TREE_TYPE (argpack) = char_type_node;
+
+  /*  Do I need to stuff THIS into a tree? */
+  TREE_VEC_ELT (argvec, 0) = argpack;
+
+  return argvec;
+}
+
+/* Parse a user-defined numeric constant.  returns a call to a user-defined
+   literal operator.  */
+static tree
+cp_parser_userdef_numeric_literal (cp_parser *parser)
+{
+  cp_token *token = NULL;
+  tree literal, suffix_id, value, num_string;
+  tree name, decl;
+  tree result = error_mark_node;
+  VEC(tree,gc) *args;
+
+  token = cp_lexer_consume_token (parser->lexer);
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  value = USERDEF_LITERAL_VALUE (literal);
+  num_string = USERDEF_LITERAL_NUM_STRING (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  /* Try to find the literal operator by finishing the call expression
+     with the numeric argument.  */
+  args = make_tree_vector ();
+  VEC_safe_push (tree, gc, args, value);
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl != error_mark_node)
+    {
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  /* If the numeric argument didn't work, look for a raw literal
+     operator taking a const char* argument consisting of the number
+     in string format.  */
+  args = make_tree_vector ();
+  VEC_safe_push (tree, gc, args, num_string);
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl != error_mark_node)
+    {
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  /* If the raw literal didn't work, look for a non-type template
+     function with parameter pack char....  Call the function with
+     template parameter characters representing the number.  */
+  args = make_tree_vector ();
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl != error_mark_node)
+    {
+      decl = finish_call_expr (decl, &args, false, true, tf_none);
+      if (decl != error_mark_node)
+	{
+	  tree tmpl_args = make_char_string_pack (num_string);
+	  result = lookup_template_function (decl, tmpl_args);
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  if (result == error_mark_node)
+    error ("unable to find appropriate call for user-defined literal");
+
+  return result;
+}
+
+/* Parse a user-defined string constant.  Returns a call to a user-defined
+   literal operator taking a character pointer and the length of the string
+   as arguments.  */
+static tree
+cp_parser_userdef_string_literal (cp_token *token)
+{
+  tree literal, suffix_id, value;
+  tree name, decl;
+  tree result;
+  VEC(tree,gc) *vec;
+  int len;
+
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+  value = USERDEF_LITERAL_VALUE (literal);
+  len = TREE_STRING_LENGTH (value) - 1;
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  vec = make_tree_vector ();
+  VEC_safe_push (tree, gc, vec, value);
+  VEC_safe_push (tree, gc, vec, build_int_cst (size_type_node, len));
+  decl = lookup_function_nonclass (name, vec, /*block_p=*/false);
+  if (decl == error_mark_node)
+    {
+      error ("unable to find user-defined literal operator declaration");
+      release_tree_vector (vec);
+      return error_mark_node;
+    }
+  result = finish_call_expr (decl, &vec, false, true, tf_warning_or_error);
+  release_tree_vector (vec);
+
+  return result;
+}
+
+
 /* Basic concepts [gram.basic]  */
 
 /* Parse a translation-unit.
@@ -3338,12 +3602,16 @@
 	   character-literal
 	   floating-literal
 	   string-literal
-	   boolean-literal  */
+	   boolean-literal
+	   pointer-literal
+	   user-defined-literal  */
     case CPP_CHAR:
     case CPP_CHAR16:
     case CPP_CHAR32:
     case CPP_WCHAR:
     case CPP_NUMBER:
+      if (TREE_CODE (token->u.value) == USERDEF_LITERAL)
+	return cp_parser_userdef_numeric_literal (parser);
       token = cp_lexer_consume_token (parser->lexer);
       if (TREE_CODE (token->u.value) == FIXED_CST)
 	{
@@ -3397,11 +3665,22 @@
 	}
       return token->u.value;
 
+    case CPP_CHAR_USERDEF:
+    case CPP_CHAR16_USERDEF:
+    case CPP_CHAR32_USERDEF:
+    case CPP_WCHAR_USERDEF:
+      return cp_parser_userdef_char_literal (parser);
+
     case CPP_STRING:
     case CPP_STRING16:
     case CPP_STRING32:
     case CPP_WSTRING:
     case CPP_UTF8STRING:
+    case CPP_STRING_USERDEF:
+    case CPP_STRING16_USERDEF:
+    case CPP_STRING32_USERDEF:
+    case CPP_WSTRING_USERDEF:
+    case CPP_UTF8STRING_USERDEF:
       /* ??? Should wide strings be allowed when parser->translate_strings_p
 	 is false (i.e. in attributes)?  If not, we can kill the third
 	 argument to cp_parser_string_literal.  */
@@ -4879,7 +5158,7 @@
 	/* Restore the saved message.  */
 	parser->type_definition_forbidden_message = saved_message;
 	/* `typeid' may not appear in an integral constant expression.  */
-	if (cp_parser_non_integral_constant_expression(parser, NIC_TYPEID))
+	if (cp_parser_non_integral_constant_expression (parser, NIC_TYPEID))
 	  return error_mark_node;
       }
       break;
@@ -9462,7 +9741,7 @@
   /* If the next token is `extern' and the following token is a string
      literal, then we have a linkage specification.  */
   if (token1.keyword == RID_EXTERN
-      && cp_parser_is_string_literal (&token2))
+      && cp_parser_is_pure_string_literal (&token2))
     cp_parser_linkage_specification (parser);
   /* If the next token is `template', then we have either a template
      declaration, an explicit instantiation, or an explicit
@@ -10893,6 +11172,22 @@
   return cp_parser_operator (parser);
 }
 
+/* Return an identifier node for a user-defined literal operator.
+   The suffix identifier is chained to the operator name identifier.  */
+
+static tree
+cp_literal_operator_id (const char* name)
+{
+  tree identifier;
+  char *buffer = XNEWVEC (char, strlen (UDLIT_OP_ANSI_PREFIX)
+			      + strlen (name) + 10);
+  sprintf (buffer, UDLIT_OP_ANSI_FORMAT, name);
+  identifier = get_identifier (buffer);
+  /*IDENTIFIER_UDLIT_OPNAME_P (identifier) = 1; If we get a flag someday. */
+
+  return identifier;
+}
+
 /* Parse an operator.
 
    operator:
@@ -11112,6 +11407,35 @@
       cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE);
       return ansi_opname (ARRAY_REF);
 
+    case CPP_STRING:
+      if (cxx_dialect == cxx98)
+	maybe_warn_cpp0x (CPP0X_USER_DEFINED_LITERALS);
+      if (TREE_STRING_LENGTH (token->u.value) > 2)
+	{
+	  error ("expected empty string after %<operator%> keyword");
+	  return error_mark_node;
+	}
+      /* Consume the string.  */
+      cp_lexer_consume_token (parser->lexer);
+      /* Look for an identifier.  */
+      id = cp_parser_identifier (parser);
+      if (id != error_mark_node)
+	{
+	  const char *name = IDENTIFIER_POINTER (id);
+
+	  /* 17.6.3.3.5  */
+	  if (name[0] != '_' && !in_system_header)
+	    warning (0, "suffixes not preceded by %<_%> "
+			"are reserved for future standardization");
+
+	  return cp_literal_operator_id(name);
+	}
+      else
+	{
+	  error ("expected suffix identifier");
+	  return error_mark_node;
+	}
+
     default:
       /* Anything else is an error.  */
       break;
@@ -22458,7 +22782,8 @@
   /* If the next token is `extern' and the following token is a string
      literal, then we have a linkage specification.  */
   if (token->keyword == RID_EXTERN
-      && cp_parser_is_string_literal (cp_lexer_peek_nth_token (parser->lexer, 2)))
+      && cp_parser_is_pure_string_literal
+	 (cp_lexer_peek_nth_token (parser->lexer, 2)))
     cp_parser_linkage_specification (parser);
   /* Handle #pragma, if any.  */
   else if (token->type == CPP_PRAGMA)
Index: gcc/cp/cp-objcp-common.c
===================================================================
--- gcc/cp/cp-objcp-common.c	(revision 178919)
+++ gcc/cp/cp-objcp-common.c	(working copy)
@@ -100,6 +100,8 @@
 
     case TEMPLATE_INFO:         return sizeof (struct tree_template_info);
 
+    case USERDEF_LITERAL:	return sizeof (struct tree_userdef_literal);
+
     default:
       gcc_unreachable ();
     }
Index: gcc/cp/mangle.c
===================================================================
--- gcc/cp/mangle.c	(revision 178919)
+++ gcc/cp/mangle.c	(working copy)
@@ -181,6 +181,7 @@
 static void write_unqualified_name (const tree);
 static void write_conversion_operator_name (const tree);
 static void write_source_name (tree);
+static void write_literal_operator_name (tree);
 static void write_unnamed_type_name (const tree);
 static void write_closure_type_name (const tree);
 static int hwint_to_ascii (unsigned HOST_WIDE_INT, const unsigned int, char *,
@@ -1174,6 +1175,8 @@
 	  }
       write_string (mangled_name);
     }
+  else if (UDLIT_OPER_P (identifier))
+    write_literal_operator_name (identifier);
   else
     write_source_name (identifier);
 }
@@ -1227,6 +1230,8 @@
 
 	  write_string (oni[DECL_OVERLOADED_OPERATOR_P (decl)].mangled_name);
 	}
+      else if (UDLIT_OPER_P (DECL_NAME (decl)))
+	write_literal_operator_name (DECL_NAME (decl));
       else
 	found = false;
 
@@ -1286,6 +1291,21 @@
   write_identifier (IDENTIFIER_POINTER (identifier));
 }
 
+/* Write a user-defined literal operator.
+   IDENTIFIER is an LITERAL_IDENTIFIER_NODE.  */
+
+static void
+write_literal_operator_name (tree identifier)
+{
+  const char* suffix = UDLIT_OP_SUFFIX (identifier);
+  char* buffer = XNEWVEC (char, strlen (UDLIT_OP_MANGLED_PREFIX)
+			      + strlen (suffix) + 10);
+  sprintf (buffer, UDLIT_OP_MANGLED_FORMAT, suffix);
+
+  write_unsigned_number (strlen (buffer));
+  write_identifier (buffer);
+}
+
 /* Encode 0 as _, and 1+ as n-1_.  */
 
 static void
Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h	(revision 178919)
+++ gcc/cp/cp-tree.h	(working copy)
@@ -394,7 +394,9 @@
   /* inline namespaces */
   CPP0X_INLINE_NAMESPACES,
   /* override controls, override/final */
-  CPP0X_OVERRIDE_CONTROLS
+  CPP0X_OVERRIDE_CONTROLS,
+  /* user defined literals */
+  CPP0X_USER_DEFINED_LITERALS
 } cpp0x_warn_str;
   
 /* The various kinds of operation used by composite_pointer_type. */
@@ -725,6 +727,7 @@
   TS_CP_TRAIT_EXPR,
   TS_CP_LAMBDA_EXPR,
   TS_CP_TEMPLATE_INFO,
+  TS_CP_USERDEF_LITERAL,
   LAST_TS_CP_ENUM
 };
 
@@ -750,6 +753,8 @@
     lambda_expression;
   struct tree_template_info GTY ((tag ("TS_CP_TEMPLATE_INFO")))
     template_info;
+  struct tree_userdef_literal GTY ((tag ("TS_CP_USERDEF_LITERAL")))
+    userdef_literal;
 };
 
 \f
@@ -4191,6 +4196,17 @@
              LAMBDANAME_PREFIX, \
 	     sizeof (LAMBDANAME_PREFIX) - 1))
 
+#define UDLIT_OP_ANSI_PREFIX "operator\"\" "
+#define UDLIT_OP_ANSI_FORMAT UDLIT_OP_ANSI_PREFIX "%s"
+#define UDLIT_OP_MANGLED_PREFIX "li"
+#define UDLIT_OP_MANGLED_FORMAT UDLIT_OP_MANGLED_PREFIX "%s"
+#define UDLIT_OPER_P(ID_NODE) \
+  (!strncmp (IDENTIFIER_POINTER (ID_NODE), \
+             UDLIT_OP_ANSI_PREFIX, \
+	     sizeof (UDLIT_OP_ANSI_PREFIX) - 1))
+#define UDLIT_OP_SUFFIX(ID_NODE) \
+  (IDENTIFIER_POINTER (ID_NODE) + sizeof (UDLIT_OP_ANSI_PREFIX) - 1)
+
 #if !defined(NO_DOLLAR_IN_LABEL) || !defined(NO_DOT_IN_LABEL)
 
 #define VTABLE_NAME_P(ID_NODE) (IDENTIFIER_POINTER (ID_NODE)[1] == 'v' \
@@ -5713,6 +5729,7 @@
 extern int lvalue_or_else			(tree, enum lvalue_use,
                                                  tsubst_flags_t);
 extern void check_template_keyword		(tree);
+extern bool check_literal_operator_args		(const_tree, bool *, bool *);
 
 /* in typeck2.c */
 extern void require_complete_eh_spec_types	(tree, tree);
Index: libcpp/include/cpplib.h
===================================================================
--- libcpp/include/cpplib.h	(revision 178919)
+++ libcpp/include/cpplib.h	(working copy)
@@ -131,6 +131,16 @@
   TK(OBJC_STRING,	LITERAL) /* @"string" - Objective-C */		\
   TK(HEADER_NAME,	LITERAL) /* <stdio.h> in #include */		\
 									\
+  TK(CHAR_USERDEF,	LITERAL) /* 'char'_suffix - C++-0x */		\
+  TK(WCHAR_USERDEF,	LITERAL) /* L'char'_suffix - C++-0x */		\
+  TK(CHAR16_USERDEF,	LITERAL) /* u'char'_suffix - C++-0x */		\
+  TK(CHAR32_USERDEF,	LITERAL) /* U'char'_suffix - C++-0x */		\
+  TK(STRING_USERDEF,	LITERAL) /* "string"_suffix - C++-0x */		\
+  TK(WSTRING_USERDEF,	LITERAL) /* L"string"_suffix - C++-0x */	\
+  TK(STRING16_USERDEF,	LITERAL) /* u"string"_suffix - C++-0x */	\
+  TK(STRING32_USERDEF,	LITERAL) /* U"string"_suffix - C++-0x */	\
+  TK(UTF8STRING_USERDEF,LITERAL) /* u8"string"_suffix - C++-0x */	\
+									\
   TK(COMMENT,		LITERAL) /* Only if output comments.  */	\
 				 /* SPELL_LITERAL happens to DTRT.  */	\
   TK(MACRO_ARG,		NONE)	 /* Macro argument.  */			\
@@ -402,6 +412,9 @@
   /* True for traditional preprocessing.  */
   unsigned char traditional;
 
+  /* Nonzero for the 2011 C++ Standard.  */
+  unsigned char cxx11;
+
   /* Holds the name of the target (execution) character set.  */
   const char *narrow_charset;
 
@@ -817,13 +830,22 @@
 #define CPP_N_FRACT	0x100000 /* Fract types.  */
 #define CPP_N_ACCUM	0x200000 /* Accum types.  */
 
+#define CPP_N_USERDEF	0x1000000 /* C++0x user-defined literal.  */
+
 /* Classify a CPP_NUMBER token.  The return value is a combination of
    the flags from the above sets.  */
-extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *);
+extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *,
+				     const char **);
 
+/* Return the classification flags for a float suffix.  */
+extern unsigned int cpp_interpret_float_suffix (const char *, size_t);
+
+/* Return the classification flags for an int suffix.  */
+extern unsigned int cpp_interpret_int_suffix (const char *, size_t);
+
 /* Evaluate a token classified as category CPP_N_INTEGER.  */
 extern cpp_num cpp_interpret_integer (cpp_reader *, const cpp_token *,
-				      unsigned int type);
+				      unsigned int);
 
 /* Sign extend a number, with PRECISION significant bits and all
    others assumed clear, to fill out a cpp_num structure.  */
@@ -993,4 +1015,20 @@
 extern void cpp_force_token_locations (cpp_reader *, source_location *);
 extern void cpp_stop_forcing_token_locations (cpp_reader *);
 
+/* In expr.c */
+extern enum cpp_ttype cpp_userdef_string_remove_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_string_add_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_char_remove_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_char_add_type
+  (enum cpp_ttype type);
+extern bool cpp_userdef_string_p
+  (enum cpp_ttype type);
+extern bool cpp_userdef_char_p
+  (enum cpp_ttype type);
+extern void cpp_get_userdef_suffix
+  (cpp_string, char, const char **);
+
 #endif /* ! LIBCPP_CPPLIB_H */
Index: libcpp/init.c
===================================================================
--- libcpp/init.c	(revision 178919)
+++ libcpp/init.c	(working copy)
@@ -80,22 +80,23 @@
   char digraphs;
   char uliterals;
   char rliterals;
+  char cxx11;
 };
 
 static const struct lang_flags lang_defaults[] =
-{ /*              c99 c++ xnum xid std  //   digr ulit rlit */
-  /* GNUC89   */  { 0,  0,  1,   0,  0,   1,   1,   0,   0 },
-  /* GNUC99   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1 },
-  /* GNUC1X   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1 },
-  /* STDC89   */  { 0,  0,  0,   0,  1,   0,   0,   0,   0 },
-  /* STDC94   */  { 0,  0,  0,   0,  1,   0,   1,   0,   0 },
-  /* STDC99   */  { 1,  0,  1,   0,  1,   1,   1,   0,   0 },
-  /* STDC1X   */  { 1,  0,  1,   0,  1,   1,   1,   1,   0 },
-  /* GNUCXX   */  { 0,  1,  1,   0,  0,   1,   1,   0,   0 },
-  /* CXX98    */  { 0,  1,  1,   0,  1,   1,   1,   0,   0 },
-  /* GNUCXX0X */  { 1,  1,  1,   0,  0,   1,   1,   1,   1 },
-  /* CXX0X    */  { 1,  1,  1,   0,  1,   1,   1,   1,   1 },
-  /* ASM      */  { 0,  0,  1,   0,  0,   1,   0,   0,   0 }
+{ /*              c99 c++ xnum xid std  //   digr ulit rlit cxx11 */
+  /* GNUC89   */  { 0,  0,  1,   0,  0,   1,   1,   0,   0,    0 },
+  /* GNUC99   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1,    0 },
+  /* GNUC1X   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1,    0 },
+  /* STDC89   */  { 0,  0,  0,   0,  1,   0,   0,   0,   0,    0 },
+  /* STDC94   */  { 0,  0,  0,   0,  1,   0,   1,   0,   0,    0 },
+  /* STDC99   */  { 1,  0,  1,   0,  1,   1,   1,   0,   0,    0 },
+  /* STDC1X   */  { 1,  0,  1,   0,  1,   1,   1,   1,   0,    0 },
+  /* GNUCXX   */  { 0,  1,  1,   0,  0,   1,   1,   0,   0,    0 },
+  /* CXX98    */  { 0,  1,  1,   0,  1,   1,   1,   0,   0,    0 },
+  /* GNUCXX0X */  { 1,  1,  1,   0,  0,   1,   1,   1,   1,    1 },
+  /* CXX0X    */  { 1,  1,  1,   0,  1,   1,   1,   1,   1,    1 },
+  /* ASM      */  { 0,  0,  1,   0,  0,   1,   0,   0,   0,    0 }
   /* xid should be 1 for GNUC99, STDC99, GNUCXX, CXX98, GNUCXX0X, and
      CXX0X when no longer experimental (when all uses of identifiers
      in the compiler have been audited for correct handling of
@@ -120,6 +121,7 @@
   CPP_OPTION (pfile, digraphs)			 = l->digraphs;
   CPP_OPTION (pfile, uliterals)			 = l->uliterals;
   CPP_OPTION (pfile, rliterals)			 = l->rliterals;
+  CPP_OPTION (pfile, cxx11)			 = l->cxx11;
 }
 
 /* Initialize library global state.  */
Index: libcpp/expr.c
===================================================================
--- libcpp/expr.c	(revision 178919)
+++ libcpp/expr.c	(working copy)
@@ -1,6 +1,6 @@
 /* Parse C expressions for cpplib.
    Copyright (C) 1987, 1992, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
-   2002, 2004, 2008, 2009, 2010 Free Software Foundation.
+   2002, 2004, 2008, 2009, 2010, 2011 Free Software Foundation.
    Contributed by Per Bothner, 1994.
 
 This program is free software; you can redistribute it and/or modify it
@@ -185,6 +185,13 @@
 	     q ? CPP_N_MD_Q : CPP_N_DEFAULT));
 }
 
+/* Return the classification flags for a float suffix.  */
+unsigned int
+cpp_interpret_float_suffix (const char *s, size_t len)
+{
+  return interpret_float_suffix ((const unsigned char *)s, len);
+}
+
 /* Subroutine of cpp_classify_number.  S points to an integer suffix
    of length LEN, possibly zero. Returns 0 for an invalid suffix, or a
    flag vector describing the suffix.  */
@@ -219,11 +226,138 @@
 	     : (l == 1) ? CPP_N_MEDIUM : CPP_N_LARGE));
 }
 
+/* Return the classification flags for an int suffix.  */
+unsigned int
+cpp_interpret_int_suffix (const char *s, size_t len)
+{
+  return interpret_int_suffix ((const unsigned char *)s, len);
+}
+
+/* Return the string type corresponding to the the input user-defined string
+   literal type.  If the input type is not a user-defined string literal
+   type return the input type.  */
+enum cpp_ttype
+cpp_userdef_string_remove_type (enum cpp_ttype type)
+{
+  if (type == CPP_STRING_USERDEF)
+    return CPP_STRING;
+  else if (type == CPP_WSTRING_USERDEF)
+    return CPP_WSTRING;
+  else if (type == CPP_STRING16_USERDEF)
+    return CPP_STRING16;
+  else if (type == CPP_STRING32_USERDEF)
+    return CPP_STRING32;
+  else if (type == CPP_UTF8STRING_USERDEF)
+    return CPP_UTF8STRING;
+  else
+    return type;
+}
+
+/* Return the user-defined string literal type corresponding to the input
+   string type.  If the input type is not a string type return the input
+   type.  */
+enum cpp_ttype
+cpp_userdef_string_add_type (enum cpp_ttype type)
+{
+  if (type == CPP_STRING)
+    return CPP_STRING_USERDEF;
+  else if (type == CPP_WSTRING)
+    return CPP_WSTRING_USERDEF;
+  else if (type == CPP_STRING16)
+    return CPP_STRING16_USERDEF;
+  else if (type == CPP_STRING32)
+    return CPP_STRING32_USERDEF;
+  else if (type == CPP_UTF8STRING)
+    return CPP_UTF8STRING_USERDEF;
+  else
+    return type;
+}
+
+/* Return the char type corresponding to the the input user-defined char
+   literal type.  If the input type is not a user-defined char literal
+   type return the input type.  */
+enum cpp_ttype
+cpp_userdef_char_remove_type (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR_USERDEF)
+    return CPP_CHAR;
+  else if (type == CPP_WCHAR_USERDEF)
+    return CPP_WCHAR;
+  else if (type == CPP_CHAR16_USERDEF)
+    return CPP_STRING16;
+  else if (type == CPP_CHAR32_USERDEF)
+    return CPP_STRING32;
+  else
+    return type;
+}
+
+/* Return the user-defined char literal type corresponding to the input
+   char type.  If the input type is not a char type return the input
+   type.  */
+enum cpp_ttype
+cpp_userdef_char_add_type (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR)
+    return CPP_CHAR_USERDEF;
+  else if (type == CPP_WCHAR)
+    return CPP_WCHAR_USERDEF;
+  else if (type == CPP_CHAR16)
+    return CPP_CHAR16_USERDEF;
+  else if (type == CPP_CHAR32)
+    return CPP_CHAR32_USERDEF;
+  else
+    return type;
+}
+
+/* Return true if the token type is a user-defined string literal.  */
+bool
+cpp_userdef_string_p (enum cpp_ttype type)
+{
+  if (type == CPP_STRING_USERDEF
+   || type == CPP_WSTRING_USERDEF
+   || type == CPP_STRING16_USERDEF
+   || type == CPP_STRING32_USERDEF
+   || type == CPP_UTF8STRING_USERDEF)
+    return true;
+  else
+    return false;
+}
+
+/* Return true if the token type is a user-defined char literal.  */
+bool
+cpp_userdef_char_p (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR_USERDEF
+   || type == CPP_WCHAR_USERDEF
+   || type == CPP_CHAR16_USERDEF
+   || type == CPP_CHAR32_USERDEF)
+    return true;
+  else
+    return false;
+}
+
+/* Extract the suffix from a user-defined literal string or char.  */
+void
+cpp_get_userdef_suffix (cpp_string string, char delim, const char **suffix)
+{
+  unsigned int len = string.len;
+  const char *text = (const char *)string.text;
+  int i;
+  for (i = len; i > 0; --i)
+    {
+      if (text[i - 1] == delim)
+	break;
+    }
+  *suffix = text + i;
+}
+
 /* Categorize numeric constants according to their field (integer,
    floating point, or invalid), radix (decimal, octal, hexadecimal),
-   and type suffixes.  */
+   and type suffixes.  In C++0X if UD_SUFFIX is non null it will be
+   assigned any unrecognized suffix for a user-defined literal.  */
 unsigned int
-cpp_classify_number (cpp_reader *pfile, const cpp_token *token)
+cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
+		     const char **ud_suffix)
 {
   const uchar *str = token->val.str.text;
   const uchar *limit;
@@ -231,6 +365,9 @@
   enum {NOT_FLOAT = 0, AFTER_POINT, AFTER_EXPON} float_flag;
   bool seen_digit;
 
+  if (ud_suffix)
+    *ud_suffix = NULL;
+
   /* If the lexer has done its job, length one can only be a single
      digit.  Fast-path this very common case.  */
   if (token->val.str.len == 1)
@@ -361,10 +498,19 @@
       result = interpret_float_suffix (str, limit - str);
       if (result == 0)
 	{
-	  cpp_error (pfile, CPP_DL_ERROR,
-		     "invalid suffix \"%.*s\" on floating constant",
-		     (int) (limit - str), str);
-	  return CPP_N_INVALID;
+	  if (CPP_OPTION (pfile, cxx11))
+	    {
+	      if (ud_suffix)
+		*ud_suffix = (const char *) str;
+	      result = CPP_N_LARGE | CPP_N_USERDEF;
+	    }
+	  else
+	    {
+	      cpp_error (pfile, CPP_DL_ERROR,
+			 "invalid suffix \"%.*s\" on floating constant",
+			 (int) (limit - str), str);
+	      return CPP_N_INVALID;
+	    }
 	}
 
       /* Traditional C didn't accept any floating suffixes.  */
@@ -406,10 +552,19 @@
       result = interpret_int_suffix (str, limit - str);
       if (result == 0)
 	{
-	  cpp_error (pfile, CPP_DL_ERROR,
-		     "invalid suffix \"%.*s\" on integer constant",
-		     (int) (limit - str), str);
-	  return CPP_N_INVALID;
+	  if (CPP_OPTION (pfile, cxx11))
+	    {
+	      if (ud_suffix)
+		*ud_suffix = (const char *) str;
+	      result = CPP_N_UNSIGNED | CPP_N_LARGE | CPP_N_USERDEF;
+	    }
+	  else
+	    {
+	      cpp_error (pfile, CPP_DL_ERROR,
+			 "invalid suffix \"%.*s\" on integer constant",
+			 (int) (limit - str), str);
+	      return CPP_N_INVALID;
+	    }
 	}
 
       /* Traditional C only accepted the 'L' suffix.
@@ -748,7 +903,7 @@
   switch (token->type)
     {
     case CPP_NUMBER:
-      temp = cpp_classify_number (pfile, token);
+      temp = cpp_classify_number (pfile, token, NULL);
       switch (temp & CPP_N_CATEGORY)
 	{
 	case CPP_N_FLOATING:
Index: libcpp/lex.c
===================================================================
--- libcpp/lex.c	(revision 178919)
+++ libcpp/lex.c	(working copy)
@@ -1227,6 +1227,7 @@
   token->type = type;
   token->val.str.len = len;
   token->val.str.text = dest;
+/*printf("\ntoken: %s", token->val.str.text);*/
 }
 
 /* Subroutine of lex_raw_string: Append LEN chars from BASE to the buffer
@@ -1478,6 +1479,21 @@
     }
  break_outer_loop:
 
+  if (CPP_OPTION (pfile, cxx11))
+    {
+      /* Grab user defined literal suffix.  */
+      if (ISIDST(*cur))
+	{
+	  type = cpp_userdef_char_add_type (type);
+	  type = cpp_userdef_string_add_type (type);
+	  ++cur;
+	}
+      while (ISIDNUM(*cur))
+	{
+	  ++cur;
+	}
+    }
+
   pfile->buffer->cur = cur;
   if (first_buff == NULL)
     create_literal (pfile, token, base, cur - base, type);
@@ -1581,6 +1597,21 @@
     cpp_error (pfile, CPP_DL_PEDWARN, "missing terminating %c character",
 	       (int) terminator);
 
+  if (CPP_OPTION (pfile, cxx11))
+    {
+      /* Grab user defined literal suffix.  */
+      if (ISIDST(*cur))
+	{
+	  type = cpp_userdef_char_add_type (type);
+	  type = cpp_userdef_string_add_type (type);
+          ++cur;
+	}
+      while (ISIDNUM(*cur))
+	{
+	  ++cur;
+	}
+    }
+
   pfile->buffer->cur = cur;
   create_literal (pfile, token, base, cur - base, type);
 }

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-09-13 15:36 Ed Smith-Rowland
  2011-09-13 16:43 ` Jason Merrill
@ 2011-09-14  8:00 ` Jason Merrill
  2011-09-19  8:33   ` Ed Smith-Rowland
  1 sibling, 1 reply; 36+ messages in thread
From: Jason Merrill @ 2011-09-14  8:00 UTC (permalink / raw)
  To: Ed Smith-Rowland; +Cc: gcc-patches

Since we're starting to come up on the end of stage 1, I'll go ahead and 
review the current patch even though it isn't finished yet.  Thanks for 
all your work on this, it definitely seems to be coming together.

On 09/13/2011 10:35 AM, Ed Smith-Rowland wrote:
> +#define CPP_N_USERDEF  0x1000000 /* C++0x user-defned literal.  */

"defined"

> -extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *);
> +extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *,
> +                                    char **ud_suffix);
> +
> +/* Return the classification flags for a float suffix.  */
> +unsigned int cpp_interpret_float_suffix (const char *s, size_t len);
> +
> +/* Return the classification flags for an int suffix.  */
> +unsigned int cpp_interpret_int_suffix (const char *s, size_t len);
>
>  /* Evaluate a token classified as category CPP_N_INTEGER.  */
>  extern cpp_num cpp_interpret_integer (cpp_reader *, const cpp_token *,

Let's follow the pattern of the existing declarations by adding explicit 
'extern' and not naming the parameters.

> @@ -327,6 +327,10 @@ pp_cxx_constant (cxx_pretty_printer *pp, tree t)
> +    case USERDEF_LITERAL:
> +      pp_c_constant (pp_c_base (pp), USERDEF_LITERAL_VALUE (t));
> +      break;
> @@ -1755,6 +1757,11 @@ dump_expr (tree t, int flags)
> +    case USERDEF_LITERAL:
> +      pp_constant (cxx_pp, USERDEF_LITERAL_VALUE (t));
> +      dump_decl (USERDEF_LITERAL_SUFFIX_ID (t), flags);
> +      break;

These should be the same--or just call pp_cxx_constant from dump_expr.

> +/* Extract the suffix from a user-defined literal string or char.  */
> +void
> +cpp_get_userdef_suffix (cpp_string string, char delim, char *suffix)
> +{
> +  unsigned int len = string.len;
> +  const char *text = (const char *)string.text;
> +  int i;
> +  for (i = len; i > 0; --i)
> +    {
> +      if (text[i - 1] == delim)
> +       break;
> +    }
> +  strncpy (suffix, text + i, len - i);
> +  suffix[len - i] = '\0';
> +}

Since you're just going to be passing the pointer to get_identifier 
anyway, we don't need to copy the suffix into the pointer.  Just return 
a pointer to the start of the suffix.

> +             if (ud_suffix)
> +               *ud_suffix = xstrdup ((const char *)str);

Similarly here.

> +             const char *curr_suffix = NULL;
> +             suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value);
> +             curr_suffix = IDENTIFIER_POINTER (suffix_id);
> +             if (have_suffix_p == 0)
> +               {
> +                 suffix = xstrdup (curr_suffix);
> +                 have_suffix_p = 1;
> +               }
> +             else if (have_suffix_p == 1 && strcmp (suffix, curr_suffix) != 0)

And here, you can compare the identifiers with ==, since identifiers are 
unique.

> +                 error ("inconsistent user-defined literal suffixes");

Let's print the suffixes involved.

> +             error ("%qD has illegal argument list", decl);

Use "invalid" rather than "illegal".

> +         suffix = UDLIT_OP_SUFFIX (DECL_NAME (decl));
> +         if (long_long_unsigned_p)
> +           {
> +             if (cpp_interpret_int_suffix (suffix, strlen (suffix)))
> +               warning (0, "integer suffix shadowed by implementation");
> +           }
> +         else if (long_double_p)
> +           {
> +             if (cpp_interpret_float_suffix (suffix, strlen (suffix)))
> +               warning (0, "floating point suffix"
> +                           " shadowed by implementation");
> +           }

Let's print the suffix as part of the warning.

> +  if (dname
> +      && TREE_CODE (dname) == IDENTIFIER_NODE
> +      && UDLIT_OPER_P (dname)
> +      && innermost_code != cdk_function
> +      && ! (ctype && !declspecs->any_specifiers_p))

I think we can drop the last check, as it only applies to constructors.

> +/* User-defined literal operator.
> +DEF_SIMPLE_OPERATOR ("\"\"", USERDEF_LITERAL_EXPR, "ud", 1)  */

Are you planning to use this for something?

> +/* Parse a user-defined char constant.  Returns a call to a user-defined
> +   literal operator taking the character as an argument.  */
> +static tree
> +cp_parser_userdef_char_literal (cp_parser *parser)

There should be a blank line after the comment here and before the other 
new functions, at least in gcc/.

> +make_numeric_string(tree value)

This function tries to recreate a printed form for a numeric constant, 
but that's not right; we need the actual source characters, which are 
likely to be different, especially for floating-point numbers.  So we 
need to get back to the actual spelling of the token here.

I notice that later in cp_parser_userdef_numeric_literal when calling 
the variadic template version you assume that you have the spelling of 
the token, which is indeed what we want.

> +check_literal_operator_args(const_tree decl,

Space before (.

> +      tree const_char_ptr_type_node
> +          = build_pointer_type(build_type_variant(char_type_node, 1, 0));
> +      tree const_wchar_ptr_type_node
> +          = build_pointer_type(build_type_variant(wchar_type_node, 1, 0));
> +      tree const_char16_ptr_type_node
> +          = build_pointer_type(build_type_variant(char16_type_node, 1, 0));
> +      tree const_char32_ptr_type_node
> +          = build_pointer_type(build_type_variant(char32_type_node, 1, 0));

It seems to me that rather than build these up to compare against, it it 
would be faster to check for POINTER_TYPE, then check that the 
pointed-to type is CP_TYPE_CONST_NON_VOLATILE_P, and then compare the 
TYPE_MAIN_VARIANT to char_type_node, etc.

> +++ b/gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C
> @@ -0,0 +1,16 @@
> +// { dg-options "-std=c++0x" }
> +
> +//  Both of these can't have *both* of these.
> +
> +int
> +operator"" _abc(const char*)
> +  {
> +    return 42;
> +  }
> +
> +template<char...>
> +  int
> +  operator"" _abc()
> +  {
> +    return 13;
> +  }

Shouldn't this have a dg-error tag somewhere?

Jason

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [C++-11] User defined literals
  2011-09-13 15:36 Ed Smith-Rowland
@ 2011-09-13 16:43 ` Jason Merrill
  2011-09-14  8:00 ` Jason Merrill
  1 sibling, 0 replies; 36+ messages in thread
From: Jason Merrill @ 2011-09-13 16:43 UTC (permalink / raw)
  To: Ed Smith-Rowland; +Cc: gcc-patches

On 09/13/2011 10:35 AM, Ed Smith-Rowland wrote:
> I need to build a TEMPLATE_ID_EXPR whenever I encounter 1234_suffix.
> I need to construct a call
> operator"" _suffix<'1','2','3','4'>();
>
> Is make_char_string_pack (const char* str) in cp/parser.c right?

The TREE_TYPE of a NONTYPE_ARGUMENT_PACK is not a pack itself, but the 
type of an element.  So char_type_node in this case.

Jason

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [C++-11] User defined literals
@ 2011-09-13 15:36 Ed Smith-Rowland
  2011-09-13 16:43 ` Jason Merrill
  2011-09-14  8:00 ` Jason Merrill
  0 siblings, 2 replies; 36+ messages in thread
From: Ed Smith-Rowland @ 2011-09-13 15:36 UTC (permalink / raw)
  To: gcc-patches, Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 338 bytes --]

Greetings,

Here is another iteration of the user-defined literals patch.

Small fixes relative to msg01614.html.

I need to build a TEMPLATE_ID_EXPR whenever I encounter 1234_suffix.
I need to construct a call
   operator"" _suffix<'1','2','3','4'>();

Is make_char_string_pack (const char* str) in cp/parser.c right?

Ed Smith-Rowland


[-- Attachment #2: patch14 --]
[-- Type: text/plain, Size: 66158 bytes --]

Index: gcc/c-family/c-lex.c
===================================================================
--- gcc/c-family/c-lex.c	(revision 178749)
+++ gcc/c-family/c-lex.c	(working copy)
@@ -44,8 +44,8 @@
 int pending_lang_change; /* If we need to switch languages - C++ only */
 int c_header_level;	 /* depth in C headers - C++ only */
 
-static tree interpret_integer (const cpp_token *, unsigned int);
-static tree interpret_float (const cpp_token *, unsigned int);
+static tree interpret_integer (const cpp_token *, unsigned int, const char *);
+static tree interpret_float (const cpp_token *, unsigned int, const char *);
 static tree interpret_fixed (const cpp_token *, unsigned int);
 static enum integer_type_kind narrowest_unsigned_type
 	(unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned int);
@@ -314,7 +314,8 @@
 
     case CPP_NUMBER:
       {
-	unsigned int flags = cpp_classify_number (parse_in, tok);
+	char *suffix = NULL;
+	unsigned int flags = cpp_classify_number (parse_in, tok, &suffix);
 
 	switch (flags & CPP_N_CATEGORY)
 	  {
@@ -328,16 +329,23 @@
 	       Set PURE_ZERO to pass this information to the C++ parser.  */
 	    if (tok->val.str.len == 1 && *tok->val.str.text == '0')
 	      add_flags = PURE_ZERO;
-	    *value = interpret_integer (tok, flags);
+	    *value = interpret_integer (tok, flags, suffix);
 	    break;
 
 	  case CPP_N_FLOATING:
-	    *value = interpret_float (tok, flags);
+	    *value = interpret_float (tok, flags, suffix);
 	    break;
 
 	  default:
 	    gcc_unreachable ();
 	  }
+
+	if (flags & CPP_N_USERDEF)
+	  {
+	    tree literal = build_userdef_literal (get_identifier (suffix),
+						  *value);
+	    *value = literal;
+	  }
       }
       break;
 
@@ -415,6 +423,23 @@
       }
       goto retry;
 
+    case CPP_CHAR_USERDEF:
+    case CPP_WCHAR_USERDEF:
+    case CPP_CHAR16_USERDEF:
+    case CPP_CHAR32_USERDEF:
+      {
+	tree literal;
+	cpp_token temp_tok = *tok;
+	char *suffix = XNEWVEC (char, tok->val.str.len + 1);
+	cpp_get_userdef_suffix (tok->val.str, '\'', suffix);
+	temp_tok.val.str.len -= strlen (suffix);
+	temp_tok.type = cpp_userdef_char_remove_type (type);
+	literal = build_userdef_literal (get_identifier (suffix),
+					 lex_charconst (&temp_tok));
+	*value = literal;
+      }
+      break;
+
     case CPP_CHAR:
     case CPP_WCHAR:
     case CPP_CHAR16:
@@ -422,6 +447,23 @@
       *value = lex_charconst (tok);
       break;
 
+    case CPP_STRING_USERDEF:
+    case CPP_WSTRING_USERDEF:
+    case CPP_STRING16_USERDEF:
+    case CPP_STRING32_USERDEF:
+    case CPP_UTF8STRING_USERDEF:
+      {
+	tree literal, string;
+	char *suffix = XNEWVEC (char, tok->val.str.len + 1);
+	cpp_get_userdef_suffix (tok->val.str, '"', suffix);
+	string = build_string (tok->val.str.len - strlen (suffix),
+			       (const char *) tok->val.str.text);
+	literal = build_userdef_literal (get_identifier (suffix),
+					 string);
+	*value = literal;
+      }
+      break;
+
     case CPP_STRING:
     case CPP_WSTRING:
     case CPP_STRING16:
@@ -536,9 +578,11 @@
   return itk_none;
 }
 
-/* Interpret TOKEN, an integer with FLAGS as classified by cpplib.  */
+/* Interpret TOKEN, an integer with FLAGS as classified by cpplib.
+   For C++0X SUFFIX may contain a user-defined literal suffix.  */
 static tree
-interpret_integer (const cpp_token *token, unsigned int flags)
+interpret_integer (const cpp_token *token, unsigned int flags,
+		   const char *suffix)
 {
   tree value, type;
   enum integer_type_kind itk;
@@ -621,9 +665,10 @@
 }
 
 /* Interpret TOKEN, a floating point number with FLAGS as classified
-   by cpplib.  */
+   by cpplib.  For C++0X SUFFIX may contain a user-defined literal suffix.  */
 static tree
-interpret_float (const cpp_token *token, unsigned int flags)
+interpret_float (const cpp_token *token, unsigned int flags,
+		 const char *suffix)
 {
   tree type;
   tree const_type;
@@ -702,7 +747,9 @@
      has any suffixes, cut them off; REAL_VALUE_ATOF/ REAL_VALUE_HTOF
      can't handle them.  */
   copylen = token->val.str.len;
-  if (flags & CPP_N_DFLOAT)
+  if (flags & CPP_N_USERDEF)
+    copylen -= strlen (suffix);
+  else if (flags & CPP_N_DFLOAT)
     copylen -= 2;
   else
     {
Index: gcc/c-family/c-common.c
===================================================================
--- gcc/c-family/c-common.c	(revision 178749)
+++ gcc/c-family/c-common.c	(working copy)
@@ -9919,4 +9919,16 @@
   MARK_TS_TYPED (EXCESS_PRECISION_EXPR);
 }
 
+/* Build a user-defined numeric literal out of an integer constant type VALUE
+   with identifier SUFFIX.  */
+
+tree
+build_userdef_literal (tree suffix_id, tree value)
+{
+  tree literal = make_node (USERDEF_LITERAL);
+  USERDEF_LITERAL_SUFFIX_ID (literal) = suffix_id;
+  USERDEF_LITERAL_VALUE (literal) = value;
+  return literal;
+}
+
 #include "gt-c-family-c-common.h"
Index: gcc/c-family/c-common.h
===================================================================
--- gcc/c-family/c-common.h	(revision 178749)
+++ gcc/c-family/c-common.h	(working copy)
@@ -1067,4 +1067,23 @@
   return NULL;
 }
 
+/* A suffix-identifier value doublet that represents user-defined literals
+   for C++-0x.  */
+struct GTY(()) tree_userdef_literal {
+  struct tree_common common;
+  tree suffix_id;
+  tree value;
+};
+
+#define USERDEF_LITERAL_SUFFIX_ID(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->suffix_id)
+
+#define USERDEF_LITERAL_VALUE(NODE) \
+  (((struct tree_userdef_literal *)USERDEF_LITERAL_CHECK (NODE))->value)
+
+#define USERDEF_LITERAL_TYPE(NODE) \
+  (TREE_TYPE (USERDEF_LITERAL_VALUE (NODE)))
+
+extern tree build_userdef_literal (tree suffix_id, tree value);
+
 #endif /* ! GCC_C_COMMON_H */
Index: gcc/c-family/c-common.def
===================================================================
--- gcc/c-family/c-common.def	(revision 178749)
+++ gcc/c-family/c-common.def	(working copy)
@@ -47,6 +47,10 @@
    evaluated.  */
 DEFTREECODE (EXCESS_PRECISION_EXPR, "excess_precision_expr", tcc_expression, 1)
 
+/* Used to represent a user-defined literal.
+   The operands are an IDENTIFIER for the suffix and the VALUE of the literal.  */
+DEFTREECODE (USERDEF_LITERAL, "userdef_literal", tcc_exceptional, 2)
+
 /*
 Local variables:
 mode:c
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg.C	(revision 0)
@@ -0,0 +1,4 @@
+// { dg-options -std=c++0x }
+
+template<char...>
+  int operator"" _xyz(unsigned long long);	// { dg-error "has illegal argument list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-operator-neg.C	(revision 0)
@@ -0,0 +1,16 @@
+// { dg-options "-std=c++0x" }
+
+//  Both of these can't have *both* of these.
+
+int
+operator"" _abc(const char*)
+  {
+    return 42;
+  }
+
+template<char...>
+  int
+  operator"" _abc()
+  {
+    return 13;
+  }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-namespace.C	(revision 0)
@@ -0,0 +1,43 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test simple operator declaration and definition in namespaces.
+
+#include <cmath>
+#include <limits>
+
+namespace Long
+{
+  long double operator"" _LL(long double);
+}
+
+namespace Short
+{
+  short
+  operator"" _SS(long double x)
+  { return std::fmod(x, static_cast<long double>(std::numeric_limits<short>::max())); }
+}
+
+void
+test1()
+{
+  long double x = Long::operator "" _LL(1.2L);
+
+  using namespace Short;
+  short s = operator"" _SS(1.2L);
+  short s2 = 1.2_SS;
+}
+
+int
+main()
+{
+  test1();
+}
+
+namespace Long
+{
+  long double
+  operator"" _LL(long double x)
+  { return x + 2.0L; }
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C	(revision 0)
@@ -0,0 +1,8 @@
+// { dg-options -std=c++0x }
+
+class Foo
+{
+public:
+  Foo() { }
+  int operator"" _Bar(char32_t) { return 42; }	// { dg-error "must be a non-member function" }
+};
Index: gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-args-neg.C	(revision 0)
@@ -0,0 +1,35 @@
+// { dg-options -std=c++0x }
+
+#include <cstddef>
+
+class Foo { };
+
+Foo
+operator"" _Foo(int *);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(unsigned long int);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(double);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(const float *, std::size_t);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(const wchar_t *, int);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(const char16_t *);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(char...);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(unsigned long long int, char);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(const char *, std::size_t, int);	// { dg-error "has illegal argument list" }
+
+Foo
+operator"" _Foo(long double &);	// { dg-error "has illegal argument list" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-cpp98-neg.C	(revision 0)
@@ -0,0 +1,15 @@
+// { dg-options "-std=c++98" }
+
+#include <cstddef>
+
+int
+operator"" _mm(long double m)	// { dg-warning "user-defined literals only available with" }
+{ return int(1000.0L * m); }
+
+int in = 0.0254_mm;	// { dg-error "invalid suffix" }
+
+int
+operator"" _Q(const char *, std::size_t)	// { dg-warning "user-defined literals only available with" }
+{ return 42; }
+
+int x = "Hello"_Q;	// { dg-error "invalid conversion from" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-suffix-neg.C	(revision 0)
@@ -0,0 +1,5 @@
+// { dg-options -std=c++0x }
+
+#include <string>
+
+std::string operator"" 5X(const char*, std::size_t);	// { dg-error "expected suffix identifier" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-constexpr.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+constexpr unsigned long long
+operator"" _grow(unsigned long long n)
+{ return 2 * n; }
+
+double buffer[25_grow];
Index: gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C	(revision 0)
@@ -0,0 +1,40 @@
+// { dg-options -std=c++0x }
+
+//  Test that the standard suffixes shadow any user-defined suffixes of the same name.
+long double
+operator"" L(long double x)	// { dg-warning "floating point suffix shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ULL(unsigned long long int k)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return k; }
+
+long double
+operator"" l(long double x)	// { dg-warning "floating point suffix shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ull(unsigned long long int k)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return k; }
+
+//  Namespaces are no hiding place.
+namespace Long
+{
+
+long double
+operator"" L(long double x)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ULL(unsigned long long int k)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return k; }
+
+long double
+operator"" l(long double x)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return x; }
+
+unsigned long long int
+operator"" ull(unsigned long long int k)	// { dg-warning "integer suffix shadowed by implementation" }
+{ return k; }
+
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nounder-neg.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test warning on declaration without leading underscore.
+
+long double operator"" nounder(long double); // { dg-warning "suffixes not preceded by|are reserved for future standardization" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms-neg.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options -std=c++0x }
+
+class Foo { };
+
+template<wchar_t...>	// { dg-error "" }
+  Foo operator"" _Foo();
Index: gcc/testsuite/g++.dg/cpp0x/udlit-general.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-general.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-general.C	(revision 0)
@@ -0,0 +1,47 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test simple operator declaration and definition.
+
+#include <string>
+#include <complex>
+
+long double operator"" _v(long double);
+std::string operator"" _w(const char16_t*, size_t);
+unsigned operator"" _w(const char*);
+
+std::complex<double>
+operator"" _i(long double y)
+{ return std::complex<double>(0.0L, y); }
+
+void
+test1()
+{
+  long double x = operator"" _v(1.2L);
+
+  std::string s = operator"" _w(u"one", 3);
+
+  unsigned u = operator"" _w("Hello, World!");
+  unsigned u2 = operator"" _w("Hello, World!");
+
+  std::complex<double> i = operator"" _i(2.0);
+}
+
+int
+main()
+{
+  test1();
+}
+
+long double
+operator"" _v(long double x)
+{ return x + 1.0L; }
+
+std::string
+operator"" _w(const char16_t*, size_t)
+{ return std::string("boo"); }
+
+unsigned
+operator"" _w(const char*)
+{ return 0U; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-raw-str.C	(revision 0)
@@ -0,0 +1,15 @@
+// { dg-options -std=c++0x }
+
+#include <string>
+
+std::string operator"" _i18n(const char*, std::size_t);
+
+std::string vogon_poem = R"V0G0N(
+                O freddled gruntbuggly thy micturations are to me
+                    As plured gabbleblochits on a lurgid bee.
+                 Groop, I implore thee my foonting turlingdromes.   
+              And hooptiously drangle me with crinkly bindlewurdles,
+  Or I will rend thee in the gobberwarts with my blurlecruncheon, see if I don't.
+
+                    (by Prostetnic Vogon Jeltz; see p. 56/57)
+)V0G0N"_i18n;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nofunc-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test error on non-function declaration.
+
+double operator"" _baddecl; // { dg-error "as non-function" }
+
+template<char...>
+  int operator"" _badtmpldecl; // { dg-error "as non-function" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-addr.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-addr.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-addr.C	(revision 0)
@@ -0,0 +1,10 @@
+// { dg-options "-std=c++0x" }
+
+#include <cstddef>
+
+bool operator"" _yn(const char*, size_t);
+
+typedef bool (*pfunk)(const char*, size_t);
+pfunk p = &operator"" _yn;
+
+bool tf = p("Hello,\0 World!", 14);
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg.C	(revision 0)
@@ -0,0 +1,4 @@
+// { dg-options -std=c++0x }
+
+template<char...>
+  int operator"" _abc();
Index: gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-clink-neg.C	(revision 0)
@@ -0,0 +1,8 @@
+// { dg-options -std=c++0x }
+
+extern "C" {
+
+int
+operator"" _badclinkage(unsigned long long);	// { dg-error "operator with C linkage" }
+
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-template.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-template.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-template.C	(revision 0)
@@ -0,0 +1,25 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test template operator declaration and definition.
+
+template<char...>
+  int operator"" _abc();
+
+int
+test1()
+{
+  int universal_meaning = operator"" _abc<'L','U','E'>();
+  int j = 1234567890_abc;
+}
+
+int
+main()
+{
+  test1();
+}
+
+template<char...>
+  int operator"" _abc()
+  { return 42; }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-args.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-args.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-args.C	(revision 0)
@@ -0,0 +1,38 @@
+// { dg-options -std=c++0x }
+
+#include <cstddef>
+
+class Foo { };
+
+Foo
+operator"" _Foo(const char *);
+
+Foo
+operator"" _Foo(unsigned long long int);
+
+Foo
+operator"" _Foo(long double);
+
+Foo
+operator"" _Foo(char);
+
+Foo
+operator"" _Foo(wchar_t);
+
+Foo
+operator"" _Foo(char16_t);
+
+Foo
+operator"" _Foo(char32_t);
+
+Foo
+operator"" _Foo(const char *, std::size_t);
+
+Foo
+operator"" _Foo(const wchar_t *, std::size_t);
+
+Foo
+operator"" _Foo(const char16_t *, std::size_t);
+
+Foo
+operator"" _Foo(const char32_t *, std::size_t);
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nosuffix-neg.C	(revision 0)
@@ -0,0 +1,5 @@
+// { dg-options -std=c++0x }
+
+char32_t
+operator"" (char32_t C)
+{ return C; }	// { dg-error "expected suffix identifier" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-nonempty-str-neg.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options "-std=c++0x" }
+
+// Test user-defined literals.
+// Test error on non-empty string after 'operator' keyword.
+
+double operator"hi" _badword(long double); // { dg-error "expected empty string after" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-linkage-neg.C	(revision 0)
@@ -0,0 +1,7 @@
+// { dg-options -std=c++0x }
+
+extern "C"_badlinkage {	// { dg-error "expected unqualified-id before" }
+
+int foo();
+
+}
Index: gcc/testsuite/g++.dg/cpp0x/udlit-friend.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-friend.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-friend.C	(revision 0)
@@ -0,0 +1,10 @@
+// { dg-options -std=c++0x }
+
+class Foo
+{
+public:
+  Foo() { }
+  friend Foo operator"" _Bar(char) { return Foo(); }
+};
+
+Foo f = 'x'_Bar;
Index: gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-concat-neg.C	(revision 0)
@@ -0,0 +1,9 @@
+// { dg-options "-std=c++0x" }
+
+#include <string>
+
+std::string operator"" _xxx(const char*, size_t);
+
+std::string operator"" _yyy(const char*, size_t);
+
+std::string concat = "Hello, "_xxx "World!"_yyy;	// { dg-error "inconsistent user-defined literal suffixes" }
Index: gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-parms.C	(revision 0)
@@ -0,0 +1,6 @@
+// { dg-options -std=c++0x }
+
+class Foo { };
+
+template<char...>
+  Foo operator"" _Foo();
Index: gcc/testsuite/g++.dg/cpp0x/udlit-concat.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/udlit-concat.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-concat.C	(revision 0)
@@ -0,0 +1,24 @@
+// { dg-options "-std=c++0x" }
+
+#include <string>
+
+std::string operator"" _www(const char*, size_t);
+
+std::string concat01 = "Hello, " "World!"_www;
+
+std::string concat10 = "Hello, "_www "World!";
+
+std::string concat11 = "Hello, "_www "World!"_www;
+
+
+class Tachyon { };
+
+Tachyon operator"" _fast(const char*, size_t);
+
+int operator"" _fast(const char32_t*, size_t);
+
+int speedy01 = "Hello, " U"World!"_fast;
+
+int speedy10 = "Hello, "_fast U"World!";
+
+int speedy11 = "Hello, "_fast U"World!"_fast;
Index: gcc/cp/typeck.c
===================================================================
--- gcc/cp/typeck.c	(revision 178749)
+++ gcc/cp/typeck.c	(working copy)
@@ -8321,3 +8321,94 @@
   return 1;
 }
 
+
+/* Return true if a user-defined literal operator has one of the allowed
+   argument types.  */
+
+bool
+check_literal_operator_args(const_tree decl,
+			    bool *long_long_unsigned_p, bool *long_double_p)
+{
+  tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
+  if (processing_template_decl)
+    return (argtypes == NULL_TREE
+	    || same_type_p (TREE_VALUE (argtypes), void_type_node));
+  else
+    {
+      tree argtype;
+      int arity;
+      int max_arity = 2;
+      bool found_string_p = false;
+      bool maybe_raw_p = false;
+      bool found_size_p = false;
+      tree const_char_ptr_type_node
+	   = build_pointer_type(build_type_variant(char_type_node, 1, 0));
+      tree const_wchar_ptr_type_node
+	   = build_pointer_type(build_type_variant(wchar_type_node, 1, 0));
+      tree const_char16_ptr_type_node
+	   = build_pointer_type(build_type_variant(char16_type_node, 1, 0));
+      tree const_char32_ptr_type_node
+	   = build_pointer_type(build_type_variant(char32_type_node, 1, 0));
+
+      *long_long_unsigned_p = false;
+      *long_double_p = false;
+
+      /* Count the number and type of arguments and check for ellipsis.  */
+      for (argtype = argtypes, arity = 0;
+	   argtype && argtype != void_list_node;
+	   argtype = TREE_CHAIN (argtype))
+	{
+	  tree t = TREE_VALUE (argtype);
+	  ++arity;
+
+	  if (same_type_p (t, const_char_ptr_type_node))
+	    {
+	      found_string_p = true;
+	      maybe_raw_p = true;
+	    }
+	  else if (same_type_p (t, const_wchar_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, const_char16_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, const_char32_ptr_type_node))
+	    found_string_p = true;
+	  else if (same_type_p (t, size_type_node))
+	    {
+	      if (!found_string_p)
+		return false;
+	      found_size_p = true;
+	    }
+	  else if (same_type_p (t, long_long_unsigned_type_node))
+	    {
+	      max_arity = 1;
+	      *long_long_unsigned_p = true;
+	    }
+	  else if (same_type_p (t, long_double_type_node))
+	    {
+	      max_arity = 1;
+	      *long_double_p = true;
+	    }
+	  else if (same_type_p (t, char_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, wchar_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, char16_type_node))
+	    max_arity = 1;
+	  else if (same_type_p (t, char32_type_node))
+	    max_arity = 1;
+	  else
+	    return false;
+	}
+      if (!argtype)
+	return false; /* Found ellipsis.  */
+
+      if (arity > max_arity)
+	return false;
+
+      if (found_string_p && !maybe_raw_p && !found_size_p)
+	return false;
+
+      return true;
+    }
+}
+
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 178749)
+++ gcc/cp/decl.c	(working copy)
@@ -7312,7 +7312,47 @@
   if (IDENTIFIER_OPNAME_P (DECL_NAME (decl))
       && !grok_op_properties (decl, /*complain=*/true))
     return NULL_TREE;
+  else if (UDLIT_OPER_P (DECL_NAME (decl)))
+    {
+      bool long_long_unsigned_p;
+      bool long_double_p;
+      const char *suffix = NULL;
+      /* [over.literal]/6: Literal operators shall not have C linkage. */
+      if (DECL_LANGUAGE(decl) == lang_c)
+	{
+	  error ("literal operator with C linkage");
+	  return NULL_TREE;
+	}
 
+      if (DECL_NAMESPACE_SCOPE_P (decl))
+	{
+	  if (!check_literal_operator_args(decl,
+					   &long_long_unsigned_p, &long_double_p))
+	    {
+	      error ("%qD has illegal argument list", decl);
+	      return NULL_TREE;
+	    }
+
+	  suffix = UDLIT_OP_SUFFIX (DECL_NAME (decl));
+	  if (long_long_unsigned_p)
+	    {
+	      if (cpp_interpret_int_suffix (suffix, strlen (suffix)))
+		warning (0, "integer suffix shadowed by implementation");
+	    }
+	  else if (long_double_p)
+	    {
+	      if (cpp_interpret_float_suffix (suffix, strlen (suffix)))
+		warning (0, "floating point suffix"
+			    " shadowed by implementation");
+	    }
+	}
+      else
+	{
+	  error ("%qD must be a non-member function", decl);
+	  return NULL_TREE;
+	}
+    }
+
   if (funcdef_flag)
     /* Make the init_value nonzero so pushdecl knows this is not
        tentative.  error_mark_node is replaced later with the BLOCK.  */
@@ -8496,6 +8536,16 @@
       error ("declaration of %qD as non-function", dname);
       return error_mark_node;
     }
+ 
+  if (dname
+      && TREE_CODE (dname) == IDENTIFIER_NODE
+      && UDLIT_OPER_P (dname)
+      && innermost_code != cdk_function
+      && ! (ctype && !declspecs->any_specifiers_p))
+    {
+      error ("declaration of %qD as non-function", dname);
+      return error_mark_node;
+    }
 
   if (dname && IDENTIFIER_OPNAME_P (dname))
     {
@@ -13743,6 +13793,7 @@
     case TRAIT_EXPR:		return TS_CP_TRAIT_EXPR;
     case LAMBDA_EXPR:		return TS_CP_LAMBDA_EXPR;
     case TEMPLATE_INFO:		return TS_CP_TEMPLATE_INFO;
+    case USERDEF_LITERAL:	return TS_CP_USERDEF_LITERAL;
     default:			return TS_CP_GENERIC;
     }
 }
Index: gcc/cp/error.c
===================================================================
--- gcc/cp/error.c	(revision 178749)
+++ gcc/cp/error.c	(working copy)
@@ -1533,6 +1533,8 @@
     }
   else if (name && IDENTIFIER_OPNAME_P (name))
     pp_cxx_tree_identifier (cxx_pp, name);
+  else if (name && UDLIT_OPER_P (name))
+    pp_cxx_tree_identifier (cxx_pp, name);
   else
     dump_decl (name, flags);
 
@@ -1755,6 +1757,11 @@
       pp_constant (cxx_pp, t);
       break;
 
+    case USERDEF_LITERAL:
+      pp_constant (cxx_pp, USERDEF_LITERAL_VALUE (t));
+      dump_decl (USERDEF_LITERAL_SUFFIX_ID (t), flags);
+      break;
+
     case THROW_EXPR:
       /* While waiting for caret diagnostics, avoid printing
 	 __cxa_allocate_exception, __cxa_throw, and the like.  */
@@ -3230,14 +3237,19 @@
 	pedwarn (input_location, OPT_pedantic,
 		 "inline namespaces "
 		 "only available with -std=c++0x or -std=gnu++0x");
-	break;	
+	break;
       case CPP0X_OVERRIDE_CONTROLS:
 	pedwarn (input_location, 0,
 		 "override controls (override/final) "
 		 "only available with -std=c++0x or -std=gnu++0x");
         break;
+      case CPP0X_USER_DEFINED_LITERALS:
+	pedwarn (input_location, 0,
+		 "user-defined literals "
+		 "only available with -std=c++0x or -std=gnu++0x");
+	break;
       default:
-	gcc_unreachable();
+	gcc_unreachable ();
       }
 }
 
Index: gcc/cp/operators.def
===================================================================
--- gcc/cp/operators.def	(revision 178749)
+++ gcc/cp/operators.def	(working copy)
@@ -153,3 +153,6 @@
 
 /* Variadic templates extension. */
 DEF_SIMPLE_OPERATOR ("...", EXPR_PACK_EXPANSION, "sp", 1)
+
+/* User-defined literal operator.
+DEF_SIMPLE_OPERATOR ("\"\"", USERDEF_LITERAL_EXPR, "ud", 1)  */
Index: gcc/cp/cxx-pretty-print.c
===================================================================
--- gcc/cp/cxx-pretty-print.c	(revision 178749)
+++ gcc/cp/cxx-pretty-print.c	(working copy)
@@ -327,6 +327,10 @@
 {
   switch (TREE_CODE (t))
     {
+    case USERDEF_LITERAL:
+      pp_c_constant (pp_c_base (pp), USERDEF_LITERAL_VALUE (t));
+      break;
+
     case STRING_CST:
       {
 	const bool in_parens = PAREN_STRING_LITERAL_P (t);
@@ -410,6 +414,7 @@
     case REAL_CST:
     case COMPLEX_CST:
     case STRING_CST:
+    case USERDEF_LITERAL:
       pp_cxx_constant (pp, t);
       break;
 
@@ -1020,6 +1025,7 @@
     case INTEGER_CST:
     case REAL_CST:
     case COMPLEX_CST:
+    case USERDEF_LITERAL:
       pp_cxx_constant (pp, t);
       break;
 
Index: gcc/cp/semantics.c
===================================================================
--- gcc/cp/semantics.c	(revision 178749)
+++ gcc/cp/semantics.c	(working copy)
@@ -7748,6 +7748,7 @@
     case TEMPLATE_PARM_INDEX:
     case TRAIT_EXPR:
     case IDENTIFIER_NODE:
+    case USERDEF_LITERAL:
       /* We can see a FIELD_DECL in a pointer-to-member expression.  */
     case FIELD_DECL:
     case PARM_DECL:
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 178749)
+++ gcc/cp/parser.c	(working copy)
@@ -210,6 +210,8 @@
   (cp_lexer *);
 static void cp_lexer_rollback_tokens
   (cp_lexer *);
+static tree cp_literal_operator_id
+  (const char *);
 #ifdef ENABLE_CHECKING
 static void cp_lexer_print_token
   (FILE *, cp_token *);
@@ -501,20 +503,20 @@
 	}
       else
 	{
-          if (warn_cxx0x_compat
-              && C_RID_CODE (token->u.value) >= RID_FIRST_CXX0X
-              && C_RID_CODE (token->u.value) <= RID_LAST_CXX0X)
-            {
-              /* Warn about the C++0x keyword (but still treat it as
-                 an identifier).  */
-              warning (OPT_Wc__0x_compat, 
-                       "identifier %qE will become a keyword in C++0x",
-                       token->u.value);
+	  if (warn_cxx0x_compat
+	      && C_RID_CODE (token->u.value) >= RID_FIRST_CXX0X
+	      && C_RID_CODE (token->u.value) <= RID_LAST_CXX0X)
+	    {
+	      /* Warn about the C++0x keyword (but still treat it as
+		 an identifier).  */
+	      warning (OPT_Wc__0x_compat, 
+		       "identifier %qE will become a keyword in C++0x",
+		       token->u.value);
 
-              /* Clear out the C_RID_CODE so we don't warn about this
-                 particular identifier-turned-keyword again.  */
-              C_SET_RID_CODE (token->u.value, RID_MAX);
-            }
+	      /* Clear out the C_RID_CODE so we don't warn about this
+		 particular identifier-turned-keyword again.  */
+	      C_SET_RID_CODE (token->u.value, RID_MAX);
+	    }
 
 	  token->ambiguous_p = false;
 	  token->keyword = RID_MAX;
@@ -1528,6 +1530,12 @@
   (cp_parser *);
 static tree cp_parser_string_literal
   (cp_parser *, bool, bool);
+static tree cp_parser_userdef_char_literal
+  (cp_parser *);
+static tree cp_parser_userdef_string_literal
+  (cp_token *);
+static tree cp_parser_userdef_numeric_literal
+  (cp_parser *);
 
 /* Basic concepts [gram.basic]  */
 
@@ -2030,6 +2038,8 @@
   (cp_parser *);
 static bool cp_parser_allow_gnu_extensions_p
   (cp_parser *);
+static bool cp_parser_is_pure_string_literal
+  (cp_token *);
 static bool cp_parser_is_string_literal
   (cp_token *);
 static bool cp_parser_is_keyword
@@ -2050,7 +2060,7 @@
 /* Returns nonzero if TOKEN is a string literal.  */
 
 static bool
-cp_parser_is_string_literal (cp_token* token)
+cp_parser_is_pure_string_literal (cp_token* token)
 {
   return (token->type == CPP_STRING ||
 	  token->type == CPP_STRING16 ||
@@ -2059,6 +2069,20 @@
 	  token->type == CPP_UTF8STRING);
 }
 
+/* Returns nonzero if TOKEN is a string literal
+   of a user-defined string literal.  */
+
+static bool
+cp_parser_is_string_literal (cp_token* token)
+{
+  return (cp_parser_is_pure_string_literal (token) ||
+	  token->type == CPP_STRING_USERDEF ||
+	  token->type == CPP_STRING16_USERDEF ||
+	  token->type == CPP_STRING32_USERDEF ||
+	  token->type == CPP_WSTRING_USERDEF ||
+	  token->type == CPP_UTF8STRING_USERDEF);
+}
+
 /* Returns nonzero if TOKEN is the indicated KEYWORD.  */
 
 static bool
@@ -3098,7 +3122,12 @@
   struct obstack str_ob;
   cpp_string str, istr, *strs;
   cp_token *tok;
-  enum cpp_ttype type;
+  enum cpp_ttype type, curr_type;
+  char *suffix = NULL;
+  int have_suffix_p = 0;
+  tree string_tree;
+  tree suffix_id = NULL_TREE;
+  bool curr_tok_is_userdef_p = false;
 
   tok = cp_lexer_peek_token (parser->lexer);
   if (!cp_parser_is_string_literal (tok))
@@ -3107,7 +3136,18 @@
       return error_mark_node;
     }
 
-  type = tok->type;
+  if (cpp_userdef_string_p (tok->type))
+    {
+      string_tree = USERDEF_LITERAL_VALUE (tok->u.value);
+      curr_type = cpp_userdef_string_remove_type (tok->type);
+      curr_tok_is_userdef_p = true;
+    }
+  else
+    {
+      string_tree = tok->u.value;
+      curr_type = tok->type;
+    }
+  type = curr_type;
 
   /* Try to avoid the overhead of creating and destroying an obstack
      for the common case of just one string.  */
@@ -3116,10 +3156,20 @@
     {
       cp_lexer_consume_token (parser->lexer);
 
-      str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value);
-      str.len = TREE_STRING_LENGTH (tok->u.value);
+      str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree);
+      str.len = TREE_STRING_LENGTH (string_tree);
       count = 1;
 
+      if (curr_tok_is_userdef_p)
+	{
+	  suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value);
+	  suffix = xstrdup (IDENTIFIER_POINTER (suffix_id));
+	  have_suffix_p = 1;
+	  curr_type = cpp_userdef_string_remove_type (tok->type);
+	}
+      else
+	curr_type = tok->type;
+
       strs = &str;
     }
   else
@@ -3131,14 +3181,34 @@
 	{
 	  cp_lexer_consume_token (parser->lexer);
 	  count++;
-	  str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value);
-	  str.len = TREE_STRING_LENGTH (tok->u.value);
+	  str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree);
+	  str.len = TREE_STRING_LENGTH (string_tree);
 
-	  if (type != tok->type)
+	  if (curr_tok_is_userdef_p)
 	    {
+	      const char *curr_suffix = NULL;
+	      suffix_id = USERDEF_LITERAL_SUFFIX_ID (tok->u.value);
+	      curr_suffix = IDENTIFIER_POINTER (suffix_id);
+	      if (have_suffix_p == 0)
+		{
+		  suffix = xstrdup (curr_suffix);
+		  have_suffix_p = 1;
+		}
+	      else if (have_suffix_p == 1 && strcmp (suffix, curr_suffix) != 0)
+		{
+		  error ("inconsistent user-defined literal suffixes");
+		  have_suffix_p = -1;
+		}
+	      curr_type = cpp_userdef_string_remove_type (tok->type);
+	    }
+	  else
+	    curr_type = tok->type;
+
+	  if (type != curr_type)
+	    {
 	      if (type == CPP_STRING)
-		type = tok->type;
-	      else if (tok->type != CPP_STRING)
+		type = curr_type;
+	      else if (curr_type != CPP_STRING)
 		error_at (tok->location,
 			  "unsupported non-standard concatenation "
 			  "of string literals");
@@ -3147,6 +3217,18 @@
 	  obstack_grow (&str_ob, &str, sizeof (cpp_string));
 
 	  tok = cp_lexer_peek_token (parser->lexer);
+	  if (cpp_userdef_string_p (tok->type))
+	    {
+	      string_tree = USERDEF_LITERAL_VALUE (tok->u.value);
+	      curr_type = cpp_userdef_string_remove_type (tok->type);
+	      curr_tok_is_userdef_p = true;
+	    }
+	  else
+	    {
+	      string_tree = tok->u.value;
+	      curr_type = tok->type;
+	      curr_tok_is_userdef_p = false;
+	    }
 	}
       while (cp_parser_is_string_literal (tok));
 
@@ -3184,6 +3266,13 @@
 	}
 
       value = fix_string_type (value);
+
+      if (have_suffix_p)
+	{
+	  tree literal = build_userdef_literal (suffix_id, value);
+	  tok->u.value = literal;
+	  return cp_parser_userdef_string_literal (tok);
+	}
     }
   else
     /* cpp_interpret_string has issued an error.  */
@@ -3195,7 +3284,221 @@
   return value;
 }
 
+/* Parse a user-defined char constant.  Returns a call to a user-defined
+   literal operator taking the character as an argument.  */
+static tree
+cp_parser_userdef_char_literal (cp_parser *parser)
+{
+  cp_token *token = NULL;
+  tree literal, suffix_id, value;
+  tree name, decl;
+  tree result;
+  VEC(tree,gc) *vec;
 
+  token = cp_lexer_consume_token (parser->lexer);
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  value = USERDEF_LITERAL_VALUE (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  vec = make_tree_vector ();
+  VEC_safe_push (tree, gc, vec, value);
+  decl = lookup_function_nonclass (name, vec, /*block_p=*/false);
+  if (decl == error_mark_node)
+    {
+      error ("unable to find user-defined literal operator declaration");
+      release_tree_vector (vec);
+      return error_mark_node;
+    }
+  result = finish_call_expr (decl, &vec, false, true, tf_warning_or_error);
+  release_tree_vector (vec);
+
+  return result;
+}
+
+/* A subroutine of cp_parser_userdef_numeric_literal to cast
+   a number as a string.  */
+static tree
+make_numeric_string(tree value)
+{
+  const int len = 1024;
+  char *str = XNEWVEC (char, len);
+  tree newval = error_mark_node;
+  /* Cast VALUE as a string.  */
+  if (TREE_CODE (value) == INTEGER_CST)
+    {
+      HOST_WIDEST_INT i = TREE_INT_CST_LOW (value);
+      snprintf (str, len, HOST_WIDEST_INT_PRINT_DEC, i);
+      newval = build_string (strlen (str), str);
+    }
+  else if (TREE_CODE (value) == REAL_CST)
+    {
+      unsigned int num_digs = 2 + __LDBL_MANT_DIG__ * 643L / 2136;
+      REAL_VALUE_TYPE d;
+      d = TREE_REAL_CST (value);
+      real_to_decimal (str, &d, len,
+		       /*digits=*/num_digs,
+		       /*crop_trailing_zeros=*/1);
+      newval = build_string (strlen (str), str);
+    }
+  else
+    gcc_unreachable ();
+
+  TREE_TYPE (newval) = char_array_type_node;
+  return newval;
+}
+
+/*A subroutine of cp_parser_userdef_numeric_literal to
+  create a char... template parameter pack.  */
+static tree
+make_char_string_pack (const char* str)
+{
+  tree parmvec;
+  tree parmtypevec;
+  tree argpack = make_node (NONTYPE_ARGUMENT_PACK);
+  tree argtypepack = cxx_make_type (TYPE_ARGUMENT_PACK);
+  int i, len = strlen (str);
+  /*  Do I need to stuff THIS into a tree? */
+  tree argvec = make_tree_vec (1);
+
+  /* Fill in PARMVEC and PARMTYPEVEC with all of the parameters.  */
+  parmvec = make_tree_vec (len);
+  parmtypevec = make_tree_vec (len);
+  for (i = 0; i < len; ++i)
+    {
+      TREE_VEC_ELT (parmvec, i) = build_int_cst (char_type_node, str[i]);
+      TREE_VEC_ELT (parmtypevec, i) = char_type_node;
+    }
+
+  /* Build the argument packs.  */
+  SET_ARGUMENT_PACK_ARGS (argpack, parmvec);
+  SET_ARGUMENT_PACK_ARGS (argtypepack, parmtypevec);
+  TREE_TYPE (argpack) = argtypepack;
+
+  /*  Do I need to stuff THIS into a tree? */
+  TREE_VEC_ELT (argvec, 0) = argpack;
+  return argvec;
+
+  /*return argpack;*/
+}
+
+/* Parse a user-defined numeric constant.  returns a call to a user-defined
+   literal operator.  */
+static tree
+cp_parser_userdef_numeric_literal (cp_parser *parser)
+{
+  cp_token *token = NULL;
+  tree literal, suffix_id, value;
+  tree name, decl;
+  tree result = error_mark_node;
+  VEC(tree,gc) *args;
+
+  token = cp_lexer_consume_token (parser->lexer);
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  value = USERDEF_LITERAL_VALUE (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  /* Try to find the literal operator by finishing the call expression
+     with the numeric argument.  */
+  args = make_tree_vector ();
+  VEC_safe_push (tree, gc, args, value);
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl != error_mark_node)
+    {
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  /* If the numeric argument didn't work, look for a raw literal
+     operator taking a const char* argument consisting of the number
+     in string format.  */
+  args = make_tree_vector ();
+  value = make_numeric_string (value);
+  VEC_safe_push (tree, gc, args, value);
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl != error_mark_node)
+    {
+      result = finish_call_expr (decl, &args, false, true, tf_none);
+      if (result != error_mark_node)
+	{
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  /* If the raw literal didn't work, look for a non-type template
+     function with parameter pack char....  Call the function with
+     template parameter characters representing the number.  */
+  args = make_tree_vector ();
+  decl = lookup_function_nonclass (name, args, /*block_p=*/false);
+  if (decl != error_mark_node)
+    {
+      decl = finish_call_expr (decl, &args, false, true, tf_none);
+      if (decl != error_mark_node)
+	{
+	  tree tmpl_args = make_char_string_pack (TREE_STRING_POINTER (value));
+	  /*result = build2 (TEMPLATE_ID_EXPR, unknown_type_node, decl, tmpl_args);*/
+	  result = lookup_template_function (decl, tmpl_args);
+	  release_tree_vector (args);
+	  return result;
+	}
+    }
+  release_tree_vector (args);
+
+  if (result == error_mark_node)
+    error ("unable to find appropriate call for user-defined literal");
+
+  return result;
+}
+
+/* Parse a user-defined string constant.  Returns a call to a user-defined
+   literal operator taking a character pointer and the length of the string
+   as arguments.  */
+static tree
+cp_parser_userdef_string_literal (cp_token *token)
+{
+  tree literal, suffix_id, value;
+  tree name, decl;
+  tree result;
+  VEC(tree,gc) *vec;
+  int len;
+
+  literal = token->u.value;
+  suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
+  name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
+  value = USERDEF_LITERAL_VALUE (literal);
+  len = TREE_STRING_LENGTH (value) - 1;
+
+  /* Build up a call to the user-defined operator  */
+  /* Lookup the name we got back from the id-expression.  */
+  vec = make_tree_vector ();
+  VEC_safe_push (tree, gc, vec, value);
+  VEC_safe_push (tree, gc, vec, build_int_cst (size_type_node, len));
+  decl = lookup_function_nonclass (name, vec, /*block_p=*/false);
+  if (decl == error_mark_node)
+    {
+      error ("unable to find user-defined literal operator declaration");
+      release_tree_vector (vec);
+      return error_mark_node;
+    }
+  result = finish_call_expr (decl, &vec, false, true, tf_warning_or_error);
+  release_tree_vector (vec);
+
+  return result;
+}
+
+
 /* Basic concepts [gram.basic]  */
 
 /* Parse a translation-unit.
@@ -3338,12 +3641,16 @@
 	   character-literal
 	   floating-literal
 	   string-literal
-	   boolean-literal  */
+	   boolean-literal
+	   pointer-literal
+	   user-defined-literal  */
     case CPP_CHAR:
     case CPP_CHAR16:
     case CPP_CHAR32:
     case CPP_WCHAR:
     case CPP_NUMBER:
+      if (TREE_CODE (token->u.value) == USERDEF_LITERAL)
+	return cp_parser_userdef_numeric_literal (parser);
       token = cp_lexer_consume_token (parser->lexer);
       if (TREE_CODE (token->u.value) == FIXED_CST)
 	{
@@ -3397,11 +3704,22 @@
 	}
       return token->u.value;
 
+    case CPP_CHAR_USERDEF:
+    case CPP_CHAR16_USERDEF:
+    case CPP_CHAR32_USERDEF:
+    case CPP_WCHAR_USERDEF:
+      return cp_parser_userdef_char_literal (parser);
+
     case CPP_STRING:
     case CPP_STRING16:
     case CPP_STRING32:
     case CPP_WSTRING:
     case CPP_UTF8STRING:
+    case CPP_STRING_USERDEF:
+    case CPP_STRING16_USERDEF:
+    case CPP_STRING32_USERDEF:
+    case CPP_WSTRING_USERDEF:
+    case CPP_UTF8STRING_USERDEF:
       /* ??? Should wide strings be allowed when parser->translate_strings_p
 	 is false (i.e. in attributes)?  If not, we can kill the third
 	 argument to cp_parser_string_literal.  */
@@ -4879,7 +5197,7 @@
 	/* Restore the saved message.  */
 	parser->type_definition_forbidden_message = saved_message;
 	/* `typeid' may not appear in an integral constant expression.  */
-	if (cp_parser_non_integral_constant_expression(parser, NIC_TYPEID))
+	if (cp_parser_non_integral_constant_expression (parser, NIC_TYPEID))
 	  return error_mark_node;
       }
       break;
@@ -9462,7 +9780,7 @@
   /* If the next token is `extern' and the following token is a string
      literal, then we have a linkage specification.  */
   if (token1.keyword == RID_EXTERN
-      && cp_parser_is_string_literal (&token2))
+      && cp_parser_is_pure_string_literal (&token2))
     cp_parser_linkage_specification (parser);
   /* If the next token is `template', then we have either a template
      declaration, an explicit instantiation, or an explicit
@@ -10893,6 +11211,22 @@
   return cp_parser_operator (parser);
 }
 
+/* Return an identifier node for a user-defined literal operator.
+   The suffix identifier is chained to the operator name identifier.  */
+
+static tree
+cp_literal_operator_id (const char* name)
+{
+  tree identifier;
+  char *buffer = XNEWVEC (char, strlen (UDLIT_OP_ANSI_PREFIX)
+			      + strlen (name) + 10);
+  sprintf (buffer, UDLIT_OP_ANSI_FORMAT, name);
+  identifier = get_identifier (buffer);
+  /*IDENTIFIER_UDLIT_OPNAME_P (identifier) = 1; If we get a flag someday. */
+
+  return identifier;
+}
+
 /* Parse an operator.
 
    operator:
@@ -11112,6 +11446,35 @@
       cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE);
       return ansi_opname (ARRAY_REF);
 
+    case CPP_STRING:
+      if (cxx_dialect == cxx98)
+	maybe_warn_cpp0x (CPP0X_USER_DEFINED_LITERALS);
+      if (TREE_STRING_LENGTH (token->u.value) > 2)
+	{
+	  error ("expected empty string after %<operator%> keyword");
+	  return error_mark_node;
+	}
+      /* Consume the string.  */
+      cp_lexer_consume_token (parser->lexer);
+      /* Look for an identifier.  */
+      id = cp_parser_identifier (parser);
+      if (id != error_mark_node)
+	{
+	  const char *name = IDENTIFIER_POINTER (id);
+
+	  /* 17.6.3.3.5  */
+	  if (name[0] != '_' && !in_system_header)
+	    warning (0, "suffixes not preceded by %<_%> "
+			"are reserved for future standardization");
+
+	  return cp_literal_operator_id(name);
+	}
+      else
+	{
+	  error ("expected suffix identifier");
+	  return error_mark_node;
+	}
+
     default:
       /* Anything else is an error.  */
       break;
@@ -22458,7 +22821,8 @@
   /* If the next token is `extern' and the following token is a string
      literal, then we have a linkage specification.  */
   if (token->keyword == RID_EXTERN
-      && cp_parser_is_string_literal (cp_lexer_peek_nth_token (parser->lexer, 2)))
+      && cp_parser_is_pure_string_literal
+	 (cp_lexer_peek_nth_token (parser->lexer, 2)))
     cp_parser_linkage_specification (parser);
   /* Handle #pragma, if any.  */
   else if (token->type == CPP_PRAGMA)
Index: gcc/cp/cp-objcp-common.c
===================================================================
--- gcc/cp/cp-objcp-common.c	(revision 178749)
+++ gcc/cp/cp-objcp-common.c	(working copy)
@@ -100,6 +100,8 @@
 
     case TEMPLATE_INFO:         return sizeof (struct tree_template_info);
 
+    case USERDEF_LITERAL:	return sizeof (struct tree_userdef_literal);
+
     default:
       gcc_unreachable ();
     }
Index: gcc/cp/mangle.c
===================================================================
--- gcc/cp/mangle.c	(revision 178749)
+++ gcc/cp/mangle.c	(working copy)
@@ -181,6 +181,7 @@
 static void write_unqualified_name (const tree);
 static void write_conversion_operator_name (const tree);
 static void write_source_name (tree);
+static void write_literal_operator_name (tree);
 static void write_unnamed_type_name (const tree);
 static void write_closure_type_name (const tree);
 static int hwint_to_ascii (unsigned HOST_WIDE_INT, const unsigned int, char *,
@@ -1174,6 +1175,8 @@
 	  }
       write_string (mangled_name);
     }
+  else if (UDLIT_OPER_P (identifier))
+    write_literal_operator_name (identifier);
   else
     write_source_name (identifier);
 }
@@ -1227,6 +1230,8 @@
 
 	  write_string (oni[DECL_OVERLOADED_OPERATOR_P (decl)].mangled_name);
 	}
+      else if (UDLIT_OPER_P (DECL_NAME (decl)))
+	write_literal_operator_name (DECL_NAME (decl));
       else
 	found = false;
 
@@ -1286,6 +1291,21 @@
   write_identifier (IDENTIFIER_POINTER (identifier));
 }
 
+/* Write a user-defined literal operator.
+   IDENTIFIER is an LITERAL_IDENTIFIER_NODE.  */
+
+static void
+write_literal_operator_name (tree identifier)
+{
+  const char* suffix = UDLIT_OP_SUFFIX (identifier);
+  char* buffer = XNEWVEC (char, strlen (UDLIT_OP_MANGLED_PREFIX)
+			      + strlen (suffix) + 10);
+  sprintf (buffer, UDLIT_OP_MANGLED_FORMAT, suffix);
+
+  write_unsigned_number (strlen (buffer));
+  write_identifier (buffer);
+}
+
 /* Encode 0 as _, and 1+ as n-1_.  */
 
 static void
Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h	(revision 178749)
+++ gcc/cp/cp-tree.h	(working copy)
@@ -394,7 +394,9 @@
   /* inline namespaces */
   CPP0X_INLINE_NAMESPACES,
   /* override controls, override/final */
-  CPP0X_OVERRIDE_CONTROLS
+  CPP0X_OVERRIDE_CONTROLS,
+  /* user defined literals */
+  CPP0X_USER_DEFINED_LITERALS
 } cpp0x_warn_str;
   
 /* The various kinds of operation used by composite_pointer_type. */
@@ -725,6 +727,7 @@
   TS_CP_TRAIT_EXPR,
   TS_CP_LAMBDA_EXPR,
   TS_CP_TEMPLATE_INFO,
+  TS_CP_USERDEF_LITERAL,
   LAST_TS_CP_ENUM
 };
 
@@ -750,6 +753,8 @@
     lambda_expression;
   struct tree_template_info GTY ((tag ("TS_CP_TEMPLATE_INFO")))
     template_info;
+  struct tree_userdef_literal GTY ((tag ("TS_CP_USERDEF_LITERAL")))
+    userdef_literal;
 };
 
 \f
@@ -4191,6 +4196,17 @@
              LAMBDANAME_PREFIX, \
 	     sizeof (LAMBDANAME_PREFIX) - 1))
 
+#define UDLIT_OP_ANSI_PREFIX "operator\"\" "
+#define UDLIT_OP_ANSI_FORMAT UDLIT_OP_ANSI_PREFIX "%s"
+#define UDLIT_OP_MANGLED_PREFIX "li"
+#define UDLIT_OP_MANGLED_FORMAT UDLIT_OP_MANGLED_PREFIX "%s"
+#define UDLIT_OPER_P(ID_NODE) \
+  (!strncmp (IDENTIFIER_POINTER (ID_NODE), \
+             UDLIT_OP_ANSI_PREFIX, \
+	     sizeof (UDLIT_OP_ANSI_PREFIX) - 1))
+#define UDLIT_OP_SUFFIX(ID_NODE) \
+  (IDENTIFIER_POINTER (ID_NODE) + sizeof (UDLIT_OP_ANSI_PREFIX) - 1)
+
 #if !defined(NO_DOLLAR_IN_LABEL) || !defined(NO_DOT_IN_LABEL)
 
 #define VTABLE_NAME_P(ID_NODE) (IDENTIFIER_POINTER (ID_NODE)[1] == 'v' \
@@ -5709,6 +5725,7 @@
 extern int lvalue_or_else			(tree, enum lvalue_use,
                                                  tsubst_flags_t);
 extern void check_template_keyword		(tree);
+extern bool check_literal_operator_args		(const_tree, bool *, bool *);
 
 /* in typeck2.c */
 extern void require_complete_eh_spec_types	(tree, tree);
Index: libcpp/include/cpplib.h
===================================================================
--- libcpp/include/cpplib.h	(revision 178749)
+++ libcpp/include/cpplib.h	(working copy)
@@ -131,6 +131,16 @@
   TK(OBJC_STRING,	LITERAL) /* @"string" - Objective-C */		\
   TK(HEADER_NAME,	LITERAL) /* <stdio.h> in #include */		\
 									\
+  TK(CHAR_USERDEF,	LITERAL) /* 'char'_suffix - C++-0x */		\
+  TK(WCHAR_USERDEF,	LITERAL) /* L'char'_suffix - C++-0x */		\
+  TK(CHAR16_USERDEF,	LITERAL) /* u'char'_suffix - C++-0x */		\
+  TK(CHAR32_USERDEF,	LITERAL) /* U'char'_suffix - C++-0x */		\
+  TK(STRING_USERDEF,	LITERAL) /* "string"_suffix - C++-0x */		\
+  TK(WSTRING_USERDEF,	LITERAL) /* L"string"_suffix - C++-0x */	\
+  TK(STRING16_USERDEF,	LITERAL) /* u"string"_suffix - C++-0x */	\
+  TK(STRING32_USERDEF,	LITERAL) /* U"string"_suffix - C++-0x */	\
+  TK(UTF8STRING_USERDEF,LITERAL) /* u8"string"_suffix - C++-0x */	\
+									\
   TK(COMMENT,		LITERAL) /* Only if output comments.  */	\
 				 /* SPELL_LITERAL happens to DTRT.  */	\
   TK(MACRO_ARG,		NONE)	 /* Macro argument.  */			\
@@ -402,6 +412,9 @@
   /* True for traditional preprocessing.  */
   unsigned char traditional;
 
+  /* Nonzero for the 2011 C++ Standard.  */
+  unsigned char cxx11;
+
   /* Holds the name of the target (execution) character set.  */
   const char *narrow_charset;
 
@@ -817,10 +830,19 @@
 #define CPP_N_FRACT	0x100000 /* Fract types.  */
 #define CPP_N_ACCUM	0x200000 /* Accum types.  */
 
+#define CPP_N_USERDEF	0x1000000 /* C++0x user-defned literal.  */
+
 /* Classify a CPP_NUMBER token.  The return value is a combination of
    the flags from the above sets.  */
-extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *);
+extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *,
+				     char **ud_suffix);
 
+/* Return the classification flags for a float suffix.  */
+unsigned int cpp_interpret_float_suffix (const char *s, size_t len);
+
+/* Return the classification flags for an int suffix.  */
+unsigned int cpp_interpret_int_suffix (const char *s, size_t len);
+
 /* Evaluate a token classified as category CPP_N_INTEGER.  */
 extern cpp_num cpp_interpret_integer (cpp_reader *, const cpp_token *,
 				      unsigned int type);
@@ -993,4 +1015,20 @@
 extern void cpp_force_token_locations (cpp_reader *, source_location *);
 extern void cpp_stop_forcing_token_locations (cpp_reader *);
 
+/* In expr.c */
+extern enum cpp_ttype cpp_userdef_string_remove_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_string_add_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_char_remove_type
+  (enum cpp_ttype type);
+extern enum cpp_ttype cpp_userdef_char_add_type
+  (enum cpp_ttype type);
+extern bool cpp_userdef_string_p
+  (enum cpp_ttype type);
+extern bool cpp_userdef_char_p
+  (enum cpp_ttype type);
+extern void cpp_get_userdef_suffix
+  (cpp_string, char, char *);
+
 #endif /* ! LIBCPP_CPPLIB_H */
Index: libcpp/init.c
===================================================================
--- libcpp/init.c	(revision 178749)
+++ libcpp/init.c	(working copy)
@@ -80,22 +80,23 @@
   char digraphs;
   char uliterals;
   char rliterals;
+  char cxx11;
 };
 
 static const struct lang_flags lang_defaults[] =
-{ /*              c99 c++ xnum xid std  //   digr ulit rlit */
-  /* GNUC89   */  { 0,  0,  1,   0,  0,   1,   1,   0,   0 },
-  /* GNUC99   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1 },
-  /* GNUC1X   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1 },
-  /* STDC89   */  { 0,  0,  0,   0,  1,   0,   0,   0,   0 },
-  /* STDC94   */  { 0,  0,  0,   0,  1,   0,   1,   0,   0 },
-  /* STDC99   */  { 1,  0,  1,   0,  1,   1,   1,   0,   0 },
-  /* STDC1X   */  { 1,  0,  1,   0,  1,   1,   1,   1,   0 },
-  /* GNUCXX   */  { 0,  1,  1,   0,  0,   1,   1,   0,   0 },
-  /* CXX98    */  { 0,  1,  1,   0,  1,   1,   1,   0,   0 },
-  /* GNUCXX0X */  { 1,  1,  1,   0,  0,   1,   1,   1,   1 },
-  /* CXX0X    */  { 1,  1,  1,   0,  1,   1,   1,   1,   1 },
-  /* ASM      */  { 0,  0,  1,   0,  0,   1,   0,   0,   0 }
+{ /*              c99 c++ xnum xid std  //   digr ulit rlit cxx11 */
+  /* GNUC89   */  { 0,  0,  1,   0,  0,   1,   1,   0,   0,    0 },
+  /* GNUC99   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1,    0 },
+  /* GNUC1X   */  { 1,  0,  1,   0,  0,   1,   1,   1,   1,    0 },
+  /* STDC89   */  { 0,  0,  0,   0,  1,   0,   0,   0,   0,    0 },
+  /* STDC94   */  { 0,  0,  0,   0,  1,   0,   1,   0,   0,    0 },
+  /* STDC99   */  { 1,  0,  1,   0,  1,   1,   1,   0,   0,    0 },
+  /* STDC1X   */  { 1,  0,  1,   0,  1,   1,   1,   1,   0,    0 },
+  /* GNUCXX   */  { 0,  1,  1,   0,  0,   1,   1,   0,   0,    0 },
+  /* CXX98    */  { 0,  1,  1,   0,  1,   1,   1,   0,   0,    0 },
+  /* GNUCXX0X */  { 1,  1,  1,   0,  0,   1,   1,   1,   1,    1 },
+  /* CXX0X    */  { 1,  1,  1,   0,  1,   1,   1,   1,   1,    1 },
+  /* ASM      */  { 0,  0,  1,   0,  0,   1,   0,   0,   0,    0 }
   /* xid should be 1 for GNUC99, STDC99, GNUCXX, CXX98, GNUCXX0X, and
      CXX0X when no longer experimental (when all uses of identifiers
      in the compiler have been audited for correct handling of
@@ -120,6 +121,7 @@
   CPP_OPTION (pfile, digraphs)			 = l->digraphs;
   CPP_OPTION (pfile, uliterals)			 = l->uliterals;
   CPP_OPTION (pfile, rliterals)			 = l->rliterals;
+  CPP_OPTION (pfile, cxx11)			 = l->cxx11;
 }
 
 /* Initialize library global state.  */
Index: libcpp/expr.c
===================================================================
--- libcpp/expr.c	(revision 178749)
+++ libcpp/expr.c	(working copy)
@@ -1,6 +1,6 @@
 /* Parse C expressions for cpplib.
    Copyright (C) 1987, 1992, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
-   2002, 2004, 2008, 2009, 2010 Free Software Foundation.
+   2002, 2004, 2008, 2009, 2010, 2011 Free Software Foundation.
    Contributed by Per Bothner, 1994.
 
 This program is free software; you can redistribute it and/or modify it
@@ -185,6 +185,13 @@
 	     q ? CPP_N_MD_Q : CPP_N_DEFAULT));
 }
 
+/* Return the classification flags for a float suffix.  */
+unsigned int
+cpp_interpret_float_suffix (const char *s, size_t len)
+{
+  return interpret_float_suffix ((const unsigned char *)s, len);
+}
+
 /* Subroutine of cpp_classify_number.  S points to an integer suffix
    of length LEN, possibly zero. Returns 0 for an invalid suffix, or a
    flag vector describing the suffix.  */
@@ -219,11 +226,139 @@
 	     : (l == 1) ? CPP_N_MEDIUM : CPP_N_LARGE));
 }
 
+/* Return the classification flags for an int suffix.  */
+unsigned int
+cpp_interpret_int_suffix (const char *s, size_t len)
+{
+  return interpret_int_suffix ((const unsigned char *)s, len);
+}
+
+/* Return the string type corresponding to the the input user-defined string
+   literal type.  If the input type is not a user-defined string literal
+   type return the input type.  */
+enum cpp_ttype
+cpp_userdef_string_remove_type (enum cpp_ttype type)
+{
+  if (type == CPP_STRING_USERDEF)
+    return CPP_STRING;
+  else if (type == CPP_WSTRING_USERDEF)
+    return CPP_WSTRING;
+  else if (type == CPP_STRING16_USERDEF)
+    return CPP_STRING16;
+  else if (type == CPP_STRING32_USERDEF)
+    return CPP_STRING32;
+  else if (type == CPP_UTF8STRING_USERDEF)
+    return CPP_UTF8STRING;
+  else
+    return type;
+}
+
+/* Return the user-defined string literal type corresponding to the input
+   string type.  If the input type is not a string type return the input
+   type.  */
+enum cpp_ttype
+cpp_userdef_string_add_type (enum cpp_ttype type)
+{
+  if (type == CPP_STRING)
+    return CPP_STRING_USERDEF;
+  else if (type == CPP_WSTRING)
+    return CPP_WSTRING_USERDEF;
+  else if (type == CPP_STRING16)
+    return CPP_STRING16_USERDEF;
+  else if (type == CPP_STRING32)
+    return CPP_STRING32_USERDEF;
+  else if (type == CPP_UTF8STRING)
+    return CPP_UTF8STRING_USERDEF;
+  else
+    return type;
+}
+
+/* Return the char type corresponding to the the input user-defined char
+   literal type.  If the input type is not a user-defined char literal
+   type return the input type.  */
+enum cpp_ttype
+cpp_userdef_char_remove_type (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR_USERDEF)
+    return CPP_CHAR;
+  else if (type == CPP_WCHAR_USERDEF)
+    return CPP_WCHAR;
+  else if (type == CPP_CHAR16_USERDEF)
+    return CPP_STRING16;
+  else if (type == CPP_CHAR32_USERDEF)
+    return CPP_STRING32;
+  else
+    return type;
+}
+
+/* Return the user-defined char literal type corresponding to the input
+   char type.  If the input type is not a char type return the input
+   type.  */
+enum cpp_ttype
+cpp_userdef_char_add_type (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR)
+    return CPP_CHAR_USERDEF;
+  else if (type == CPP_WCHAR)
+    return CPP_WCHAR_USERDEF;
+  else if (type == CPP_CHAR16)
+    return CPP_CHAR16_USERDEF;
+  else if (type == CPP_CHAR32)
+    return CPP_CHAR32_USERDEF;
+  else
+    return type;
+}
+
+/* Return true if the token type is a user-defined string literal.  */
+bool
+cpp_userdef_string_p (enum cpp_ttype type)
+{
+  if (type == CPP_STRING_USERDEF
+   || type == CPP_WSTRING_USERDEF
+   || type == CPP_STRING16_USERDEF
+   || type == CPP_STRING32_USERDEF
+   || type == CPP_UTF8STRING_USERDEF)
+    return true;
+  else
+    return false;
+}
+
+/* Return true if the token type is a user-defined char literal.  */
+bool
+cpp_userdef_char_p (enum cpp_ttype type)
+{
+  if (type == CPP_CHAR_USERDEF
+   || type == CPP_WCHAR_USERDEF
+   || type == CPP_CHAR16_USERDEF
+   || type == CPP_CHAR32_USERDEF)
+    return true;
+  else
+    return false;
+}
+
+/* Extract the suffix from a user-defined literal string or char.  */
+void
+cpp_get_userdef_suffix (cpp_string string, char delim, char *suffix)
+{
+  unsigned int len = string.len;
+  const char *text = (const char *)string.text;
+  int i;
+  for (i = len; i > 0; --i)
+    {
+      if (text[i - 1] == delim)
+	break;
+    }
+  strncpy (suffix, text + i, len - i);
+  suffix[len - i] = '\0';
+}
+
 /* Categorize numeric constants according to their field (integer,
    floating point, or invalid), radix (decimal, octal, hexadecimal),
-   and type suffixes.  */
+   and type suffixes.  In C++0X if UD_SUFFIX is non null it will be
+   assigned any unrecognized suffix for a user-defined literal.  */
 unsigned int
-cpp_classify_number (cpp_reader *pfile, const cpp_token *token)
+cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
+		     char **ud_suffix)
 {
   const uchar *str = token->val.str.text;
   const uchar *limit;
@@ -231,6 +366,9 @@
   enum {NOT_FLOAT = 0, AFTER_POINT, AFTER_EXPON} float_flag;
   bool seen_digit;
 
+  if (ud_suffix)
+    *ud_suffix = NULL;
+
   /* If the lexer has done its job, length one can only be a single
      digit.  Fast-path this very common case.  */
   if (token->val.str.len == 1)
@@ -361,10 +499,19 @@
       result = interpret_float_suffix (str, limit - str);
       if (result == 0)
 	{
-	  cpp_error (pfile, CPP_DL_ERROR,
-		     "invalid suffix \"%.*s\" on floating constant",
-		     (int) (limit - str), str);
-	  return CPP_N_INVALID;
+	  if (CPP_OPTION (pfile, cxx11))
+	    {
+	      if (ud_suffix)
+		*ud_suffix = xstrdup ((const char *)str);
+	      result = CPP_N_LARGE | CPP_N_USERDEF;
+	    }
+	  else
+	    {
+	      cpp_error (pfile, CPP_DL_ERROR,
+			 "invalid suffix \"%.*s\" on floating constant",
+			 (int) (limit - str), str);
+	      return CPP_N_INVALID;
+	    }
 	}
 
       /* Traditional C didn't accept any floating suffixes.  */
@@ -406,10 +553,19 @@
       result = interpret_int_suffix (str, limit - str);
       if (result == 0)
 	{
-	  cpp_error (pfile, CPP_DL_ERROR,
-		     "invalid suffix \"%.*s\" on integer constant",
-		     (int) (limit - str), str);
-	  return CPP_N_INVALID;
+	  if (CPP_OPTION (pfile, cxx11))
+	    {
+	      if (ud_suffix)
+		*ud_suffix = xstrdup ((const char *)str);
+	      result = CPP_N_UNSIGNED | CPP_N_LARGE | CPP_N_USERDEF;
+	    }
+	  else
+	    {
+	      cpp_error (pfile, CPP_DL_ERROR,
+			 "invalid suffix \"%.*s\" on integer constant",
+			 (int) (limit - str), str);
+	      return CPP_N_INVALID;
+	    }
 	}
 
       /* Traditional C only accepted the 'L' suffix.
@@ -748,7 +904,7 @@
   switch (token->type)
     {
     case CPP_NUMBER:
-      temp = cpp_classify_number (pfile, token);
+      temp = cpp_classify_number (pfile, token, NULL);
       switch (temp & CPP_N_CATEGORY)
 	{
 	case CPP_N_FLOATING:
Index: libcpp/lex.c
===================================================================
--- libcpp/lex.c	(revision 178749)
+++ libcpp/lex.c	(working copy)
@@ -1227,6 +1227,7 @@
   token->type = type;
   token->val.str.len = len;
   token->val.str.text = dest;
+/*printf("\ntoken: %s", token->val.str.text);*/
 }
 
 /* Subroutine of lex_raw_string: Append LEN chars from BASE to the buffer
@@ -1478,6 +1479,21 @@
     }
  break_outer_loop:
 
+  if (CPP_OPTION (pfile, cxx11))
+    {
+      /* Grab user defined literal suffix.  */
+      if (ISIDST(*cur))
+	{
+	  type = cpp_userdef_char_add_type (type);
+	  type = cpp_userdef_string_add_type (type);
+	  ++cur;
+	}
+      while (ISIDNUM(*cur))
+	{
+	  ++cur;
+	}
+    }
+
   pfile->buffer->cur = cur;
   if (first_buff == NULL)
     create_literal (pfile, token, base, cur - base, type);
@@ -1581,6 +1597,21 @@
     cpp_error (pfile, CPP_DL_PEDWARN, "missing terminating %c character",
 	       (int) terminator);
 
+  if (CPP_OPTION (pfile, cxx11))
+    {
+      /* Grab user defined literal suffix.  */
+      if (ISIDST(*cur))
+	{
+	  type = cpp_userdef_char_add_type (type);
+	  type = cpp_userdef_string_add_type (type);
+          ++cur;
+	}
+      while (ISIDNUM(*cur))
+	{
+	  ++cur;
+	}
+    }
+
   pfile->buffer->cur = cur;
   create_literal (pfile, token, base, cur - base, type);
 }


^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2011-10-31 19:45 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-12 21:12 Re: [C++-11] User defined literals 3dw4rd
2011-10-15 23:13 ` Jason Merrill
2011-10-16  7:59 ` Jason Merrill
2011-10-21 14:56   ` Ed Smith-Rowland
2011-10-21 21:20     ` Tom Tromey
2011-10-21 23:38       ` Jason Merrill
2011-10-23 22:29         ` Ed Smith-Rowland
2011-10-24 15:41         ` Ed Smith-Rowland
2011-10-25 23:38           ` Jason Merrill
2011-10-26  9:16             ` Ed Smith-Rowland
2011-10-26 20:13               ` Jason Merrill
2011-10-27 19:15                 ` Ed Smith-Rowland
2011-10-27 19:55                 ` Ed Smith-Rowland
2011-10-27 20:37                   ` Jason Merrill
2011-10-30 19:10                     ` Ed Smith-Rowland
2011-10-31 17:52                       ` Jason Merrill
2011-10-25  7:07         ` Ed Smith-Rowland
  -- strict thread matches above, loose matches on Subject: below --
2011-10-31 17:58 3dw4rd
2011-10-31 20:20 ` Jason Merrill
2011-10-26 20:33 3dw4rd
2011-10-26 20:46 ` Jason Merrill
2011-10-21 17:04 3dw4rd
2011-09-13 15:36 Ed Smith-Rowland
2011-09-13 16:43 ` Jason Merrill
2011-09-14  8:00 ` Jason Merrill
2011-09-19  8:33   ` Ed Smith-Rowland
2011-09-19 22:43     ` Jason Merrill
2011-09-20  7:23       ` Ed Smith-Rowland
2011-09-20 21:48         ` Jason Merrill
2011-10-05 15:57           ` Ed Smith-Rowland
2011-10-05 21:24             ` Jason Merrill
2011-10-08 21:38               ` Ed Smith-Rowland
2011-10-09  1:18                 ` Jason Merrill
2011-10-09 23:46                   ` Ed Smith-Rowland
2011-10-11 19:20                     ` Jason Merrill
2011-10-11 17:39                       ` Jason Merrill
2011-10-12  6:51                         ` Ed Smith-Rowland
2011-10-12 18:49                           ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).