PR c++/91230 - wrong error with __PRETTY_FUNCTION__ and generic lambda.
authorMarek Polacek <polacek@redhat.com>
Fri, 2 Aug 2019 13:26:06 +0000 (13:26 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 2 Aug 2019 13:26:06 +0000 (13:26 +0000)
* pt.c (value_dependent_expression_p): Consider __PRETTY_FUNCTION__
inside a template function value-dependent.

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

From-SVN: r274009

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1y/lambda-generic-pretty1.C [new file with mode: 0644]

index 48435375aa0445815d334585682e04e593a31cbb..2715966e6f41ce0cc2cb32c05093fe27b71dc687 100644 (file)
@@ -1,3 +1,9 @@
+2019-08-02  Marek Polacek  <polacek@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.
+
 2019-08-02  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * tree.c (handle_nodiscard_attribute): Do not warn about nodiscard
index 91a46745447609aebca91f1ca6d4b058038ab112..87d177c6824a77bd75d4d43ac4ebe8bda3a2fa31 100644 (file)
@@ -25553,7 +25553,14 @@ 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)
+                 /* It might be used in a template, but not a template
+                    function, in which case its DECL_VALUE_EXPR will be
+                    "top level".  */
+                 && value_expr == error_mark_node))
            return true;
        }
       return false;
index 36dbcc86812b87d697acbcfee14c6b320dca1ffa..00d664f961e39f309364d73b828e8223d6f60c74 100644 (file)
@@ -1,3 +1,8 @@
+2019-08-02  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/91230 - wrong error with __PRETTY_FUNCTION__ and generic lambda.
+       * g++.dg/cpp1y/lambda-generic-pretty1.C: New test.
+
 2019-08-02  Uroš Bizjak  <ubizjak@gmail.com>
 
        PR target/91323
diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-pretty1.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-pretty1.C
new file mode 100644 (file)
index 0000000..4d3246b
--- /dev/null
@@ -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>();
+}