[gcc(refs/vendors/ibm/heads/perf)] c++: Further tweak for P1937R2 - const{expr, eval} inconsistencies
Jiu Fu Guo
guojiufu@gcc.gnu.org
Thu Mar 19 05:58:09 GMT 2020
https://gcc.gnu.org/g:18396541e4793382a989a23f41f5deb347610234
commit 18396541e4793382a989a23f41f5deb347610234
Author: Jakub Jelinek <jakub@redhat.com>
Date: Fri Feb 28 17:35:32 2020 +0100
c++: Further tweak for P1937R2 - const{expr,eval} inconsistencies
Seems I've missed one thing, as the first hunk in
https://github.com/cplusplus/draft/commit/c8e68ed202b4a9260616bcee8a9768b5dca4bbca
changes the wording so that only potentially-evaluated id-expressions that
denote immediate functions must appear only in the specified contexts.
That IMO means that in unevaluated contexts there aren't such restrictions
anymore, so I think in unevaluated contexts one should be able to take the
address of an immediate function.
2020-02-28 Jakub Jelinek <jakub@redhat.com>
P1937R2 - Fixing inconsistencies between const{expr,eval} functions
* typeck.c (cp_build_addr_expr_1): Allow taking address of immediate
functions in unevaluated contexts.
* g++.dg/cpp2a/consteval3.C: Change dg-error about taking address of
immediate function in unevaluated contexts into dg-bogus.
* g++.dg/cpp2a/consteval16.C: New test.
Diff:
---
gcc/cp/ChangeLog | 6 ++++++
gcc/cp/typeck.c | 1 +
gcc/testsuite/ChangeLog | 5 +++++
gcc/testsuite/g++.dg/cpp2a/consteval16.C | 7 +++++++
gcc/testsuite/g++.dg/cpp2a/consteval3.C | 4 ++--
5 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 22fe8036f18..4dc30e0a321 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2020-02-28 Jakub Jelinek <jakub@redhat.com>
+
+ P1937R2 - Fixing inconsistencies between const{expr,eval} functions
+ * typeck.c (cp_build_addr_expr_1): Allow taking address of immediate
+ functions in unevaluated contexts.
+
2020-02-27 Nathan Sidwell <nathan@acm.org>
PR c++/93933
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 2a3243f3e81..8e3188a415d 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -6332,6 +6332,7 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue, tsubst_flags_t complain)
tree stripped_arg = tree_strip_any_location_wrapper (arg);
if (TREE_CODE (stripped_arg) == FUNCTION_DECL
&& DECL_IMMEDIATE_FUNCTION_P (stripped_arg)
+ && cp_unevaluated_operand == 0
&& (current_function_decl == NULL_TREE
|| !DECL_IMMEDIATE_FUNCTION_P (current_function_decl)))
{
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index cde33ee5015..3727ae255fe 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,10 @@
2020-02-28 Jakub Jelinek <jakub@redhat.com>
+ P1937R2 - Fixing inconsistencies between const{expr,eval} functions
+ * g++.dg/cpp2a/consteval3.C: Change dg-error about taking address of
+ immediate function in unevaluated contexts into dg-bogus.
+ * g++.dg/cpp2a/consteval16.C: New test.
+
PR middle-end/92152
* g++.dg/torture/pr92152.C (size_t): Use decltype (sizeof (0)) instead
of hardcoding unsigned long.
diff --git a/gcc/testsuite/g++.dg/cpp2a/consteval16.C b/gcc/testsuite/g++.dg/cpp2a/consteval16.C
new file mode 100644
index 00000000000..9b43de8b5fa
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/consteval16.C
@@ -0,0 +1,7 @@
+// { dg-do compile }
+// { dg-options "-std=c++2a" }
+
+consteval int foo () { return 0; }
+int bar (int (*) ());
+auto sz = sizeof (bar (foo)); // { dg-bogus "taking address of an immediate function" }
+decltype (bar (foo)) baz; // { dg-bogus "taking address of an immediate function" }
diff --git a/gcc/testsuite/g++.dg/cpp2a/consteval3.C b/gcc/testsuite/g++.dg/cpp2a/consteval3.C
index edd3a7310b2..9fb1f1a0b12 100644
--- a/gcc/testsuite/g++.dg/cpp2a/consteval3.C
+++ b/gcc/testsuite/g++.dg/cpp2a/consteval3.C
@@ -31,8 +31,8 @@ consteval consteval int f11 () { return 0; } // { dg-error "duplicate 'consteval
struct U { consteval ~U () {} }; // { dg-error "a destructor cannot be 'consteval'" }
struct V { consteval int v = 5; }; // { dg-error "non-static data member 'v' declared 'consteval'" }
struct W { consteval static int w; }; // { dg-error "static data member 'w' declared 'consteval'" }
-int i = sizeof (&f6); // { dg-error "taking address of an immediate function 'consteval int f6\\(int\\)'" }
-using j = decltype (&f6); // { dg-error "taking address of an immediate function 'consteval int f6\\(int\\)'" }
+int i = sizeof (&f6); // { dg-bogus "taking address of an immediate function 'consteval int f6\\(int\\)'" }
+using j = decltype (&f6); // { dg-bogus "taking address of an immediate function 'consteval int f6\\(int\\)'" }
int k = sizeof (f6 (d)); // { dg-bogus "the value of 'd' is not usable in a constant expression" }
using l = decltype (f6 (d)); // { dg-bogus "the value of 'd' is not usable in a constant expression" }
bool m = noexcept (f6 (d)); // { dg-bogus "the value of 'd' is not usable in a constant expression" }
More information about the Gcc-cvs
mailing list