public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Martin Liska <marxin@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/users/marxin/heads/PR92440-use-note)] Fix "PR c++/92804 ICE trying to use concept as a nested-name-specifier"
Date: Mon, 27 Jan 2020 14:08:00 -0000	[thread overview]
Message-ID: <20200127140821.1442.qmail@sourceware.org> (raw)

https://gcc.gnu.org/g:c91072247eb066ec9c6cd0b0f949c7dae691e46c

commit c91072247eb066ec9c6cd0b0f949c7dae691e46c
Author: Paolo Carlini <paolo.carlini@oracle.com>
Date:   Thu Jan 23 19:28:23 2020 +0100

    Fix "PR c++/92804 ICE trying to use concept as a nested-name-specifier"
    
    A rather simple ICE where we failed to properly check for concept-ids
    uses in nested-name-specifiers.
    
    Tested x86_64-linux.
    
           /cp
           PR c++/92804
           * parser.c (cp_parser_nested_name_specifier_opt): Properly
           diagnose concept-ids.
    
           /testsuite
           PR c++/92804
           * g++.dg/concepts/pr92804-1.C: New.
           * g++.dg/concepts/pr92804-2.C: New.

Diff:
---
 gcc/cp/ChangeLog                          |  6 ++++++
 gcc/cp/parser.c                           | 23 +++++++++++++++++------
 gcc/testsuite/ChangeLog                   |  6 ++++++
 gcc/testsuite/g++.dg/concepts/pr92804-1.C | 19 +++++++++++++++++++
 gcc/testsuite/g++.dg/concepts/pr92804-2.C | 19 +++++++++++++++++++
 5 files changed, 67 insertions(+), 6 deletions(-)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index b13ee2b..c01bece 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2020-01-23  Paolo Carlini  <paolo.carlini@oracle.com>
+
+	PR c++/92804
+	* parser.c (cp_parser_nested_name_specifier_opt): Properly
+	diagnose concept-ids.
+
 2020-01-23  Jason Merrill  <jason@redhat.com>
 
 	PR c++/93331 - ICE with __builtin_strchr.
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index dc07dc5..72037ee 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -6467,16 +6467,27 @@ cp_parser_nested_name_specifier_opt (cp_parser *parser,
 		      tree fns = get_fns (tid);
 		      if (OVL_SINGLE_P (fns))
 			tmpl = OVL_FIRST (fns);
-		      error_at (token->location, "function template-id %qD "
-				"in nested-name-specifier", tid);
+		      if (function_concept_p (fns))
+			error_at (token->location, "concept-id %qD "
+				  "in nested-name-specifier", tid);
+		      else
+			error_at (token->location, "function template-id "
+				  "%qD in nested-name-specifier", tid);
 		    }
 		  else
 		    {
-		      /* Variable template.  */
 		      tmpl = TREE_OPERAND (tid, 0);
-		      gcc_assert (variable_template_p (tmpl));
-		      error_at (token->location, "variable template-id %qD "
-				"in nested-name-specifier", tid);
+		      if (variable_concept_p (tmpl)
+			  || standard_concept_p (tmpl))
+			error_at (token->location, "concept-id %qD "
+				  "in nested-name-specifier", tid);
+		      else
+			{
+			  /* Variable template.  */
+			  gcc_assert (variable_template_p (tmpl));
+			  error_at (token->location, "variable template-id "
+				    "%qD in nested-name-specifier", tid);
+			}
 		    }
 		  if (tmpl)
 		    inform (DECL_SOURCE_LOCATION (tmpl),
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index ef4c6fc..93fb3be 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2020-01-23  Paolo Carlini  <paolo.carlini@oracle.com>
+
+	PR c++/92804
+	* g++.dg/concepts/pr92804-1.C: New.
+	* g++.dg/concepts/pr92804-2.C: Likewise.
+
 2020-01-23  David Malcolm  <dmalcolm@redhat.com>
 
 	PR analyzer/93375
diff --git a/gcc/testsuite/g++.dg/concepts/pr92804-1.C b/gcc/testsuite/g++.dg/concepts/pr92804-1.C
new file mode 100644
index 0000000..cc21426
--- /dev/null
+++ b/gcc/testsuite/g++.dg/concepts/pr92804-1.C
@@ -0,0 +1,19 @@
+// { dg-do compile { target c++17 } }
+// { dg-options "-fconcepts" }
+
+template<typename T>
+concept foo = true;  // { dg-message "declared here" }
+
+template<typename T>
+void bar(T t)
+{
+  if constexpr (foo<T>::value)  // { dg-error "17:concept-id .foo<T>. in nested-name-specifier" }
+  // { dg-error "expected|value" "" { target c++17 } .-1 }
+  {
+  }
+}
+
+int main()
+{
+  bar(1);
+}
diff --git a/gcc/testsuite/g++.dg/concepts/pr92804-2.C b/gcc/testsuite/g++.dg/concepts/pr92804-2.C
new file mode 100644
index 0000000..32a1554
--- /dev/null
+++ b/gcc/testsuite/g++.dg/concepts/pr92804-2.C
@@ -0,0 +1,19 @@
+// { dg-do compile { target c++17 } }
+// { dg-options "-fconcepts-ts" }
+
+template<typename T>
+concept bool foo() { return true; };  // { dg-message "declared here" }
+
+template<typename T>
+void bar(T t)
+{
+  if constexpr (foo<T>::value)  // { dg-error "17:concept-id .foo<T>. in nested-name-specifier" }
+  // { dg-error "expected|value" "" { target *-*-* } .-1 }
+  {
+  }
+}
+
+int main()
+{
+  bar(1);
+}


                 reply	other threads:[~2020-01-27 14:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20200127140821.1442.qmail@sourceware.org \
    --to=marxin@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.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).