aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarald van Dijk <harald@gigawatt.nl>2019-06-04 16:48:38 +0200
committerJason Merrill <jason@gcc.gnu.org>2019-06-04 10:48:38 -0400
commit7b9202ea9ee9b9147a2c2e3f478f1f3eb0b5c174 (patch)
tree09a05fcf0d7ab47821b96c882f7a163f5b69a85b
parentecdcd56094cadc7bd3c18a0edd19f00d670e0d9b (diff)
downloadgcc-7b9202ea9ee9b9147a2c2e3f478f1f3eb0b5c174.zip
gcc-7b9202ea9ee9b9147a2c2e3f478f1f3eb0b5c174.tar.gz
gcc-7b9202ea9ee9b9147a2c2e3f478f1f3eb0b5c174.tar.bz2
PR c++/60531 - Wrong error about unresolved overloaded function
For PR60531, GCC wrongly rejects function templates with explicitly specified template arguments as overloaded. They are resolved by resolve_nondeduced_context, which is normally called by cp_default_conversion through decay_conversion, but the latter have extra effects making them unusable here. Calling the former directly does work. * typeck.c (cp_build_binary_op): See if overload can be resolved. (cp_build_unary_op): Ditto. * g++.dg/template/operator15.C: New test. From-SVN: r271910
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/typeck.c12
-rw-r--r--gcc/testsuite/g++.dg/template/operator15.C6
3 files changed, 19 insertions, 5 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index efa79f3..21b82df 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2019-06-04 Harald van Dijk <harald@gigawatt.nl>
+
+ PR c++/60531 - Wrong error about unresolved overloaded function
+ * typeck.c (cp_build_binary_op): See if overload can be resolved.
+ (cp_build_unary_op): Ditto.
+
2019-06-04 Jason Merrill <jason@redhat.com>
Reduce accumulated garbage in constexpr evaluation.
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 7289f2c..b9fa6f1 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -4396,10 +4396,6 @@ cp_build_binary_op (const op_location_t &location,
/* True if both operands have arithmetic type. */
bool arithmetic_types_p;
- /* Apply default conversions. */
- op0 = orig_op0;
- op1 = orig_op1;
-
/* Remember whether we're doing / or %. */
bool doing_div_or_mod = false;
@@ -4409,6 +4405,10 @@ cp_build_binary_op (const op_location_t &location,
/* Tree holding instrumentation expression. */
tree instrument_expr = NULL_TREE;
+ /* Apply default conversions. */
+ op0 = resolve_nondeduced_context (orig_op0, complain);
+ op1 = resolve_nondeduced_context (orig_op1, complain);
+
if (code == TRUTH_AND_EXPR || code == TRUTH_ANDIF_EXPR
|| code == TRUTH_OR_EXPR || code == TRUTH_ORIF_EXPR
|| code == TRUTH_XOR_EXPR)
@@ -6216,11 +6216,13 @@ cp_build_unary_op (enum tree_code code, tree xarg, bool noconvert,
if (!arg || error_operand_p (arg))
return error_mark_node;
+ arg = resolve_nondeduced_context (arg, complain);
+
if ((invalid_op_diag
= targetm.invalid_unary_op ((code == UNARY_PLUS_EXPR
? CONVERT_EXPR
: code),
- TREE_TYPE (xarg))))
+ TREE_TYPE (arg))))
{
if (complain & tf_error)
error (invalid_op_diag);
diff --git a/gcc/testsuite/g++.dg/template/operator15.C b/gcc/testsuite/g++.dg/template/operator15.C
new file mode 100644
index 0000000..7554422
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/operator15.C
@@ -0,0 +1,6 @@
+// PR c++/60531
+
+template < class T > T foo ();
+
+bool b1 = foo<int> == foo<int>;
+int (*fp1)() = +foo<int>;