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
commit e2fe821867bdc55a300f400fe8340a8d7168fb46
Author: Jason Merrill <ja...@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;
commit 9c14fb264df67fdc3a28b47c67991345af634d85
Author: Jason Merrill <ja...@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
commit d083a0d7f94fb0fe3605d499366b1b637e169c17
Author: Jason Merrill <ja...@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)

Reply via email to