From 05f14938111e34edd272628a9268444256735e10 Mon Sep 17 00:00:00 2001 From: Patrick Palka Date: Tue, 21 Apr 2020 22:18:50 -0400 Subject: [PATCH] c++: Diagnose invalid use of member function in requires This updates diagnose_valid_expression to mirror the convert_to_void check added to tsubst_valid_expression_requirement by r10-7554. gcc/cp/ChangeLog: PR c++/67825 * constraint.cc (diagnose_valid_expression): Check convert_to_void here as well as in tsubst_valid_expression_requirement. gcc/testsuite/ChangeLog: PR c++/67825 * g++.dg/concepts/diagnostic10.C: New test. * g++.dg/cpp2a/concepts-pr67178.C: Adjust dg-message. --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/constraint.cc | 8 ++++++-- gcc/testsuite/ChangeLog | 8 +++++++- gcc/testsuite/g++.dg/concepts/diagnostic10.C | 18 ++++++++++++++++++ gcc/testsuite/g++.dg/cpp2a/concepts-pr67178.C | 2 +- 5 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/concepts/diagnostic10.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 67b571c4408..e7733d0517e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2020-04-22 Patrick Palka + + PR c++/67825 + * constraint.cc (diagnose_valid_expression): Check convert_to_void here + as well as in tsubst_valid_expression_requirement. + 2020-04-21 Patrick Palka PR c++/94549 diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index d56ec101cd9..c05fafe5da1 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3242,7 +3242,8 @@ static tree diagnose_valid_expression (tree expr, tree args, tree in_decl) { tree result = tsubst_expr (expr, args, tf_none, in_decl, false); - if (result != error_mark_node) + if (result != error_mark_node + && convert_to_void (result, ICV_STATEMENT, tf_none) != error_mark_node) return result; location_t loc = cp_expr_loc_or_input_loc (expr); @@ -3250,7 +3251,10 @@ diagnose_valid_expression (tree expr, tree args, tree in_decl) { /* Replay the substitution error. */ inform (loc, "the required expression %qE is invalid, because", expr); - tsubst_expr (expr, args, tf_error, in_decl, false); + if (result == error_mark_node) + tsubst_expr (expr, args, tf_error, in_decl, false); + else + convert_to_void (result, ICV_STATEMENT, tf_error); } else inform (loc, "the required expression %qE is invalid", expr); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 87d99b1e22b..be374fba120 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,8 +1,14 @@ +2020-04-22 Patrick Palka + + PR c++/67825 + * g++.dg/concepts/diagnostic10.C: New test. + * g++.dg/cpp2a/concepts-pr67178.C: Adjust dg-message. + 2020-04-21 Patrick Palka PR c++/94549 * g++.dg/concepts/inherit-ctor3.C: Adjust expected diagnostics. - * g++.dg/cpp2a/concepts-inherit-ctor4.C: New test. + * g++.dg/cpp2a/concepts-inherit-ctor4.C: Likewise. * g++.dg/cpp2a/concepts-inherit-ctor8.C: New test. 2020-04-21 Jonathan Wakely diff --git a/gcc/testsuite/g++.dg/concepts/diagnostic10.C b/gcc/testsuite/g++.dg/concepts/diagnostic10.C new file mode 100644 index 00000000000..fcc6043ca93 --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/diagnostic10.C @@ -0,0 +1,18 @@ +// PR c++/67825 +// { dg-do compile { target concepts } } +// { dg-additional-options "-fconcepts-diagnostics-depth=2" } + +template + requires requires (T t) { t.f; } // { dg-error "invalid use of non-static member function" } +void foo() { } + +struct S +{ + int f(); +}; + +void +bar() +{ + foo(); // { dg-error "unsatisfied constraints" } +} diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-pr67178.C b/gcc/testsuite/g++.dg/cpp2a/concepts-pr67178.C index ff84711a7af..7154fc2b7fe 100644 --- a/gcc/testsuite/g++.dg/cpp2a/concepts-pr67178.C +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-pr67178.C @@ -12,7 +12,7 @@ concept C0 = requires (auto x) { // { dg-error "placeholder type" } template concept C1 = requires (C1 auto x) { // { dg-error "not been declared|placeholder|two or more|in requirements" } x; // { dg-error "not declared" } - { x } -> c; // { dg-message "not declared|does not satisfy" } + { x } -> c; // { dg-message "is invalid" } }; template -- 2.30.2