aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-02-28 17:35:32 +0100
committerJakub Jelinek <jakub@redhat.com>2020-02-28 17:35:32 +0100
commit18396541e4793382a989a23f41f5deb347610234 (patch)
tree70142f3f7cdb056c4037fd52065fa4e1a99f6033 /gcc
parentf3ce088645e5305d932380c7520809181b2d2eb9 (diff)
downloadgcc-18396541e4793382a989a23f41f5deb347610234.zip
gcc-18396541e4793382a989a23f41f5deb347610234.tar.gz
gcc-18396541e4793382a989a23f41f5deb347610234.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/typeck.c1
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/consteval16.C7
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/consteval3.C4
5 files changed, 21 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 22fe803..4dc30e0 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 2a3243f..8e3188a 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 cde33ee..3727ae2 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 0000000..9b43de8
--- /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 edd3a73..9fb1f1a 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" }