c++: Further tweak for P1937R2 - const{expr,eval} inconsistencies
authorJakub Jelinek <jakub@redhat.com>
Fri, 28 Feb 2020 16:35:32 +0000 (17:35 +0100)
committerJakub Jelinek <jakub@redhat.com>
Fri, 28 Feb 2020 16:35:32 +0000 (17:35 +0100)
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.

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp2a/consteval16.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/consteval3.C

index 22fe803..4dc30e0 100644 (file)
@@ -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
index 2a3243f..8e3188a 100644 (file)
@@ -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)))
        {
index cde33ee..3727ae2 100644 (file)
@@ -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 (file)
index 0000000..9b43de8
--- /dev/null
@@ -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" }
index edd3a73..9fb1f1a 100644 (file)
@@ -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" }