From b34fd35b83f8e93d87de4f865d86495a44c93498 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Fri, 2 Aug 2019 13:26:06 +0000 Subject: [PATCH] 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. From-SVN: r274009 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/pt.c | 9 ++++++++- gcc/testsuite/ChangeLog | 5 +++++ .../g++.dg/cpp1y/lambda-generic-pretty1.C | 17 +++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/lambda-generic-pretty1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 48435375aa0..2715966e6f4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-08-02 Marek Polacek + + 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 * tree.c (handle_nodiscard_attribute): Do not warn about nodiscard diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 91a46745447..87d177c6824 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 36dbcc86812..00d664f961e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-08-02 Marek Polacek + + 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 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 index 00000000000..4d3246b909b --- /dev/null +++ b/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 +void f() { + [](auto) { + StringWrapper{__PRETTY_FUNCTION__}; + }; +} + +int main() { + f(); +} -- 2.30.2