public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Ed Smith-Rowland <3dw4rd@verizon.net>
Cc: Tom Tromey <tromey@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [C++-11] User defined literals
Date: Wed, 26 Oct 2011 20:13:00 -0000	[thread overview]
Message-ID: <4EA861C1.8080703@redhat.com> (raw)
In-Reply-To: <4EA7A1ED.6030206@verizon.net>

[-- 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)

  reply	other threads:[~2011-10-26 19:39 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-12 21:12 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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4EA861C1.8080703@redhat.com \
    --to=jason@redhat.com \
    --cc=3dw4rd@verizon.net \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=tromey@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).