Commit fb6a8b23 by Jakub Jelinek

c++: P1937R2 - Fixing inconsistencies between const{expr,eval} functions

The following patch implements my understanding of P1937R2, though I wonder
if https://eel.is/c++draft/expr.const#14.example-1 shouldn't have been
also either removed or adjusted by the P1937R2 paper.

2020-02-24  Jakub Jelinek  <jakub@redhat.com>

	P1937R2 - Fixing inconsistencies between const{expr,eval} functions
	* call.c (build_over_call): Don't evaluate immediate functions in
	unevaluated operands.

	* g++.dg/ext/consteval1.C: Change dg-{message,error} into dg-bogus.
	* g++.dg/cpp2a/consteval6.C: Likewise.
	* g++.dg/cpp2a/consteval3.C: Change dg-error for unevaluated operands
	into dg-bogus.
parent 8566286e
2020-02-24 Jakub Jelinek <jakub@redhat.com>
P1937R2 - Fixing inconsistencies between const{expr,eval} functions
* call.c (build_over_call): Don't evaluate immediate functions in
unevaluated operands.
2020-02-24 Jason Merrill <jason@redhat.com> 2020-02-24 Jason Merrill <jason@redhat.com>
P0780R2: Resolve lambda init-capture pack grammar. P0780R2: Resolve lambda init-capture pack grammar.
......
...@@ -8425,6 +8425,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) ...@@ -8425,6 +8425,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
current_function_returns_abnormally = 1; current_function_returns_abnormally = 1;
if (TREE_CODE (fn) == FUNCTION_DECL if (TREE_CODE (fn) == FUNCTION_DECL
&& DECL_IMMEDIATE_FUNCTION_P (fn) && DECL_IMMEDIATE_FUNCTION_P (fn)
&& cp_unevaluated_operand == 0
&& (current_function_decl == NULL_TREE && (current_function_decl == NULL_TREE
|| !DECL_IMMEDIATE_FUNCTION_P (current_function_decl)) || !DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
&& (current_binding_level->kind != sk_function_parms && (current_binding_level->kind != sk_function_parms
...@@ -9061,6 +9062,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) ...@@ -9061,6 +9062,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
tree fndecl = STRIP_TEMPLATE (TREE_OPERAND (fn, 0)); tree fndecl = STRIP_TEMPLATE (TREE_OPERAND (fn, 0));
if (TREE_CODE (fndecl) == FUNCTION_DECL if (TREE_CODE (fndecl) == FUNCTION_DECL
&& DECL_IMMEDIATE_FUNCTION_P (fndecl) && DECL_IMMEDIATE_FUNCTION_P (fndecl)
&& cp_unevaluated_operand == 0
&& (current_function_decl == NULL_TREE && (current_function_decl == NULL_TREE
|| !DECL_IMMEDIATE_FUNCTION_P (current_function_decl)) || !DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
&& (current_binding_level->kind != sk_function_parms && (current_binding_level->kind != sk_function_parms
......
2020-02-24 Jakub Jelinek <jakub@redhat.com>
P1937R2 - Fixing inconsistencies between const{expr,eval} functions
* g++.dg/ext/consteval1.C: Change dg-{message,error} into dg-bogus.
* g++.dg/cpp2a/consteval6.C: Likewise.
* g++.dg/cpp2a/consteval3.C: Change dg-error for unevaluated operands
into dg-bogus.
2020-02-24 Christophe Lyon <christophe.lyon@linaro.org> 2020-02-24 Christophe Lyon <christophe.lyon@linaro.org>
PR lto/78353 PR lto/78353
......
...@@ -33,9 +33,9 @@ struct V { consteval int v = 5; }; // { dg-error "non-static data member 'v' dec ...@@ -33,9 +33,9 @@ struct V { consteval int v = 5; }; // { dg-error "non-static data member 'v' dec
struct W { consteval static int w; }; // { dg-error "static data member 'w' 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\\)'" } 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\\)'" } using j = decltype (&f6); // { dg-error "taking address of an immediate function 'consteval int f6\\(int\\)'" }
int k = sizeof (f6 (d)); // { dg-error "the value of 'd' is not usable in a constant expression" } int k = sizeof (f6 (d)); // { dg-bogus "the value of 'd' is not usable in a constant expression" }
using l = decltype (f6 (d)); // { dg-error "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-error "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" }
namespace std { namespace std {
using size_t = decltype (sizeof (0)); using size_t = decltype (sizeof (0));
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
struct A { struct A {
constexpr A () {} constexpr A () {}
A (A const&) = delete; // { dg-message "declared here" } A (A const&) = delete; // { dg-bogus "declared here" }
}; };
template<typename T> template<typename T>
...@@ -19,8 +19,8 @@ consteval void ...@@ -19,8 +19,8 @@ consteval void
bar () bar ()
{ {
T t; T t;
T u = t; // { dg-error "use of deleted function" } T u = t; // { dg-bogus "use of deleted function" }
} }
using B = decltype (foo<A> ()); using B = decltype (foo<A> ());
using C = decltype (bar<A> ()); // { dg-message "required from here" } using C = decltype (bar<A> ()); // { dg-bogus "required from here" }
...@@ -2,5 +2,5 @@ ...@@ -2,5 +2,5 @@
// { dg-options "-std=c++2a" } // { dg-options "-std=c++2a" }
consteval int foo (int x) { return x; } consteval int foo (int x) { return x; }
int d = 6; // { dg-message "'int d' is not const" } int d = 6; // { dg-bogus "'int d' is not const" }
bool e = __builtin_has_attribute (foo (d), packed); // { dg-error "the value of 'd' is not usable in a constant expression" } bool e = __builtin_has_attribute (foo (d), packed); // { dg-bogus "the value of 'd' is not usable in a constant expression" }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment