Fix "PR c++/92804 ICE trying to use concept as a nested-name-specifier"
authorPaolo Carlini <paolo.carlini@oracle.com>
Thu, 23 Jan 2020 18:28:23 +0000 (19:28 +0100)
committerPaolo Carlini <paolo.carlini@oracle.com>
Thu, 23 Jan 2020 18:28:23 +0000 (19:28 +0100)
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.

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/concepts/pr92804-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/concepts/pr92804-2.C [new file with mode: 0644]

index b13ee2b38207e3452752f85068a33596810deb7e..c01becefe879b1fd208f5534f71b1fa254a6a904 100644 (file)
@@ -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.
index dc07dc55d9c52e678cc49fc11c29179eb793242d..72037ee7b46ab6c31d62d54e3c3f805149acb6cf 100644 (file)
@@ -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),
index ef4c6fc79181091c2c2a4a2fc06d1b8a34b739a9..93fb3be2bb012655a3ecabdf2999ad4dd7470987 100644 (file)
@@ -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 (file)
index 0000000..cc21426
--- /dev/null
@@ -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 (file)
index 0000000..32a1554
--- /dev/null
@@ -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);
+}