Hi,

in this simple issue we either wrongly talked about variable template-id in c++17 mode or ICEd in c++2a. I think we simply want to handle concept-ids first, both as represented in c++17 mode and as represented in c++2a mode. Tested x86_64-linux.

Thanks, Paolo.

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

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.C: New.
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index caafbefda8e..fe490d4a69f 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -6472,11 +6472,18 @@ cp_parser_nested_name_specifier_opt (cp_parser *parser,
                    }
                  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/g++.dg/concepts/pr92804.C 
b/gcc/testsuite/g++.dg/concepts/pr92804.C
new file mode 100644
index 00000000000..cc21426bb9e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/concepts/pr92804.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);
+}

Reply via email to