We started rejecting this test with r268321, whereby we process the
compound_literal in finish_compound_literal normally even in a template
if it's not instantiation-dependent.  This broke with __PRETTY_FUNCTION__
in a template function, because instantiation_dependent_expression_p didn't
consider it dependent, which resulted in a bogus error later.

cp_make_fname_decl has TYPE_DEP indicating that the fname is dependent, so
I think value_dependent_expression_p needs to be fixed as below, and actually
treat such a fname as dependent.

Bootstrapped/regtested on x86_64-linux, ok for trunk and 9?

2019-08-01  Marek Polacek  <pola...@redhat.com>

        PR c++/91230 - wrong error with __PRETTY_FUNCTION__ and generic lambda.
        * pt.c (value_dependent_expression_p): Consider __PRETTY_FUNCTION__
        inside a template function value-dependent.

        * g++.dg/cpp1y/lambda-generic-pretty1.C: New test.

diff --git gcc/cp/pt.c gcc/cp/pt.c
index 91a46745447..94706bc5ad1 100644
--- gcc/cp/pt.c
+++ gcc/cp/pt.c
@@ -25553,7 +25553,11 @@ value_dependent_expression_p (tree expression)
       if (DECL_HAS_VALUE_EXPR_P (expression))
        {
          tree value_expr = DECL_VALUE_EXPR (expression);
-         if (value_dependent_expression_p (value_expr))
+         if (value_dependent_expression_p (value_expr)
+             /* __PRETTY_FUNCTION__ inside a template function is dependent
+                on the name of the function.  */
+             || (DECL_PRETTY_FUNCTION_P (expression)
+                 && value_expr == error_mark_node))
            return true;
        }
       return false;
diff --git gcc/testsuite/g++.dg/cpp1y/lambda-generic-pretty1.C 
gcc/testsuite/g++.dg/cpp1y/lambda-generic-pretty1.C
new file mode 100644
index 00000000000..4d3246b909b
--- /dev/null
+++ gcc/testsuite/g++.dg/cpp1y/lambda-generic-pretty1.C
@@ -0,0 +1,17 @@
+// PR c++/91230
+// { dg-do compile { target c++14 } }
+
+struct StringWrapper {
+    const char* Value;
+};
+
+template <typename T>
+void f() {
+    [](auto) {
+        StringWrapper{__PRETTY_FUNCTION__};
+    };
+}
+
+int main() {
+    f<int>();
+}

Reply via email to