public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Paolo Carlini <paolo.carlini@oracle.com>
To: Jason Merrill <jason@redhat.com>
Cc: gcc-patches List <gcc-patches@gcc.gnu.org>,
	       Nathan Sidwell <nathan@acm.org>
Subject: Re: [C++ Patch] PR 84423 ("[6/7/8/9 Regression] [concepts] ICE with invalid using declaration")
Date: Tue, 09 Oct 2018 19:27:00 -0000	[thread overview]
Message-ID: <ca085f60-eeb5-6a6d-4233-1a74f65aa22c@oracle.com> (raw)
In-Reply-To: <CADzB+2mmvOW+HABBK6LMEi2W2x8yYzn6yX_N45DQbMA7=kgYiQ@mail.gmail.com>

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

Hi,

On 09/10/18 17:17, Jason Merrill wrote:
> On Sat, Sep 29, 2018 at 3:27 PM Paolo Carlini <paolo.carlini@oracle.com> wrote:
>> Hi again,
>>
>> On 9/28/18 9:15 PM, Paolo Carlini wrote:
>>> Thanks. About the location, you are certainly right, but doesn't seem
>>> trivial. Something we can do *now* is using
>>> declspecs->locations[ds_typedef] and declspecs->locations[ds_alias],
>>> but that gives us the location of the keyword 'typedef' and 'using',
>>> respectively, whereas I think that we would like to have the location
>>> of 'auto' itself. I could look into that as a follow-up piece work
>> In fact, completing the work turned out to be easy: ensure that
>> cp_parser_alias_declaration saves the location of the defining-type-id
>> too and then consistently use locations[ds_type_spec] in the error
>> messages. Tested x86_64-linux. Still Ok? ;)
> Hmm, I think you need to look past any cv-qualifiers at the beginning
> of the type-id.

Ah, good point. The information is readily available in 
cp_parser_type_id thus we can simply return it to 
cp_parser_alias_declaration. I guess an alternate approach would be 
adding a pointer to the whole cp_decl_specifier_seq parameter to 
cp_parser_type_id (and cp_parser_type_id_1, etc), but that seems over 
killing to me.

Thanks! Paolo.

/////////////////////


[-- Attachment #2: patch_84423_3 --]
[-- Type: text/plain, Size: 8075 bytes --]

Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 264985)
+++ cp/decl.c	(working copy)
@@ -11879,6 +11879,7 @@ grokdeclarator (const cp_declarator *declarator,
   /* If this is declaring a typedef name, return a TYPE_DECL.  */
   if (typedef_p && decl_context != TYPENAME)
     {
+      bool alias_p = decl_spec_seq_has_spec_p (declspecs, ds_alias);
       tree decl;
 
       /* This declaration:
@@ -11901,7 +11902,12 @@ grokdeclarator (const cp_declarator *declarator,
 
       if (type_uses_auto (type))
 	{
-	  error ("typedef declared %<auto%>");
+	  if (alias_p)
+	    error_at (declspecs->locations[ds_type_spec],
+		      "%<auto%> not allowed in alias declaration");
+	  else
+	    error_at (declspecs->locations[ds_type_spec],
+		      "typedef declared %<auto%>");
 	  type = error_mark_node;
 	}
 
@@ -11961,7 +11967,7 @@ grokdeclarator (const cp_declarator *declarator,
 		      inlinep, friendp, raises != NULL_TREE,
 		      declspecs->locations);
 
-      if (decl_spec_seq_has_spec_p (declspecs, ds_alias))
+      if (alias_p)
 	/* Acknowledge that this was written:
 	     `using analias = atype;'.  */
 	TYPE_DECL_ALIAS_P (decl) = 1;
Index: cp/parser.c
===================================================================
--- cp/parser.c	(revision 264985)
+++ cp/parser.c	(working copy)
@@ -2216,12 +2216,12 @@ static tree cp_parser_late_return_type_opt
 static tree cp_parser_declarator_id
   (cp_parser *, bool);
 static tree cp_parser_type_id
-  (cp_parser *);
+  (cp_parser *, location_t * = NULL);
 static tree cp_parser_template_type_arg
   (cp_parser *);
 static tree cp_parser_trailing_type_id (cp_parser *);
 static tree cp_parser_type_id_1
-  (cp_parser *, bool, bool);
+  (cp_parser *, bool, bool, location_t *);
 static void cp_parser_type_specifier_seq
   (cp_parser *, bool, bool, cp_decl_specifier_seq *);
 static tree cp_parser_parameter_declaration_clause
@@ -19034,7 +19034,7 @@ static tree
 cp_parser_alias_declaration (cp_parser* parser)
 {
   tree id, type, decl, pushed_scope = NULL_TREE, attributes;
-  location_t id_location;
+  location_t id_location, type_location;
   cp_declarator *declarator;
   cp_decl_specifier_seq decl_specs;
   bool member_p;
@@ -19086,7 +19086,7 @@ cp_parser_alias_declaration (cp_parser* parser)
 	G_("types may not be defined in alias template declarations");
     }
 
-  type = cp_parser_type_id (parser);
+  type = cp_parser_type_id (parser, &type_location);
 
   /* Restore the error message if need be.  */
   if (parser->num_template_parameter_lists)
@@ -19120,6 +19120,7 @@ cp_parser_alias_declaration (cp_parser* parser)
   set_and_check_decl_spec_loc (&decl_specs,
 			       ds_alias,
 			       using_token);
+  decl_specs.locations[ds_type_spec] = type_location;
 
   if (parser->num_template_parameter_lists
       && !cp_parser_check_template_parameters (parser,
@@ -21110,7 +21111,7 @@ cp_parser_declarator_id (cp_parser* parser, bool o
 
 static tree
 cp_parser_type_id_1 (cp_parser* parser, bool is_template_arg,
-		     bool is_trailing_return)
+		     bool is_trailing_return, location_t * type_location)
 {
   cp_decl_specifier_seq type_specifier_seq;
   cp_declarator *abstract_declarator;
@@ -21119,6 +21120,9 @@ cp_parser_type_id_1 (cp_parser* parser, bool is_te
   cp_parser_type_specifier_seq (parser, /*is_declaration=*/false,
 				is_trailing_return,
 				&type_specifier_seq);
+  if (type_location)
+    *type_location = type_specifier_seq.locations[ds_type_spec];
+
   if (is_template_arg && type_specifier_seq.type
       && TREE_CODE (type_specifier_seq.type) == TEMPLATE_TYPE_PARM
       && CLASS_PLACEHOLDER_TEMPLATE (type_specifier_seq.type))
@@ -21184,9 +21188,9 @@ cp_parser_type_id_1 (cp_parser* parser, bool is_te
 }
 
 static tree
-cp_parser_type_id (cp_parser *parser)
+cp_parser_type_id (cp_parser *parser, location_t * type_location)
 {
-  return cp_parser_type_id_1 (parser, false, false);
+  return cp_parser_type_id_1 (parser, false, false, type_location);
 }
 
 static tree
@@ -21196,7 +21200,7 @@ cp_parser_template_type_arg (cp_parser *parser)
   const char *saved_message = parser->type_definition_forbidden_message;
   parser->type_definition_forbidden_message
     = G_("types may not be defined in template arguments");
-  r = cp_parser_type_id_1 (parser, true, false);
+  r = cp_parser_type_id_1 (parser, true, false, NULL);
   parser->type_definition_forbidden_message = saved_message;
   if (cxx_dialect >= cxx14 && !flag_concepts && type_uses_auto (r))
     {
@@ -21209,7 +21213,7 @@ cp_parser_template_type_arg (cp_parser *parser)
 static tree
 cp_parser_trailing_type_id (cp_parser *parser)
 {
-  return cp_parser_type_id_1 (parser, false, true);
+  return cp_parser_type_id_1 (parser, false, true, NULL);
 }
 
 /* Parse a type-specifier-seq.
Index: cp/pt.c
===================================================================
--- cp/pt.c	(revision 264985)
+++ cp/pt.c	(working copy)
@@ -7776,7 +7776,7 @@ convert_template_argument (tree parm,
   tree val;
   int is_type, requires_type, is_tmpl_type, requires_tmpl_type;
 
-  if (parm == error_mark_node)
+  if (parm == error_mark_node || error_operand_p (arg))
     return error_mark_node;
 
   /* Trivially convert placeholders. */
Index: testsuite/g++.dg/concepts/pr84423-1.C
===================================================================
--- testsuite/g++.dg/concepts/pr84423-1.C	(nonexistent)
+++ testsuite/g++.dg/concepts/pr84423-1.C	(working copy)
@@ -0,0 +1,8 @@
+// { dg-do compile { target c++11 } }
+// { dg-additional-options "-fconcepts" }
+
+template<typename> using A = auto;  // { dg-error "30:.auto. not allowed in alias declaration" }
+
+template<template<typename> class> struct B {};
+
+B<A> b;
Index: testsuite/g++.dg/concepts/pr84423-2.C
===================================================================
--- testsuite/g++.dg/concepts/pr84423-2.C	(nonexistent)
+++ testsuite/g++.dg/concepts/pr84423-2.C	(working copy)
@@ -0,0 +1,18 @@
+// { dg-do compile { target c++11 } }
+// { dg-additional-options "-fconcepts" }
+
+using A = auto;  // { dg-error "11:.auto. not allowed in alias declaration" }
+
+using A1 = const auto;  // { dg-error "18:.auto. not allowed in alias declaration" }
+
+using A2 = volatile auto;  // { dg-error "21:.auto. not allowed in alias declaration" }
+
+using A3 = const volatile auto;  // { dg-error "27:.auto. not allowed in alias declaration" }
+
+typedef auto B;  // { dg-error "9:typedef declared .auto." }
+
+typedef const auto B1;  // { dg-error "15:typedef declared .auto." }
+
+typedef volatile auto B2;  // { dg-error "18:typedef declared .auto." }
+
+typedef const volatile auto B3;  // { dg-error "24:typedef declared .auto." }
Index: testsuite/g++.dg/cpp0x/auto39.C
===================================================================
--- testsuite/g++.dg/cpp0x/auto39.C	(revision 264985)
+++ testsuite/g++.dg/cpp0x/auto39.C	(working copy)
@@ -1,6 +1,6 @@
 // PR c++/58560
 // { dg-do compile { target c++11 } }
 
-typedef auto T;     // { dg-error "typedef declared 'auto'" }
+typedef auto T;     // { dg-error "9:typedef declared 'auto'" }
 
 void foo() { T(); }
Index: testsuite/g++.dg/cpp0x/auto9.C
===================================================================
--- testsuite/g++.dg/cpp0x/auto9.C	(revision 264985)
+++ testsuite/g++.dg/cpp0x/auto9.C	(working copy)
@@ -120,4 +120,4 @@ void qq (auto);		       // { dg-error "auto" "" {
 void qr (auto*);	       // { dg-error "auto" "" { target { ! concepts } } }
 
 // PR c++/46145
-typedef auto autot;		// { dg-error "auto" }
+typedef auto autot;		// { dg-error "9:typedef declared .auto." }
Index: testsuite/g++.dg/cpp1y/pr60384.C
===================================================================
--- testsuite/g++.dg/cpp1y/pr60384.C	(revision 264985)
+++ testsuite/g++.dg/cpp1y/pr60384.C	(working copy)
@@ -5,5 +5,5 @@ template<typename> int foo();
 
 struct A
 {
-  typedef auto foo<>();  // { dg-error "typedef declared 'auto'" }
+  typedef auto foo<>();  // { dg-error "11:typedef declared 'auto'" }
 };

  reply	other threads:[~2018-10-09 17:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-28 16:43 Paolo Carlini
2018-09-28 17:53 ` Jason Merrill
2018-09-28 20:26   ` Paolo Carlini
2018-09-29 20:14     ` Paolo Carlini
2018-10-09 11:37       ` [C++ Patch PING] " Paolo Carlini
2018-10-09 16:51       ` Jason Merrill
2018-10-09 19:27         ` Paolo Carlini [this message]
2018-10-09 20:34           ` 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=ca085f60-eeb5-6a6d-4233-1a74f65aa22c@oracle.com \
    --to=paolo.carlini@oracle.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=nathan@acm.org \
    /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).