aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2021-05-03 13:35:26 -0400
committerPatrick Palka <ppalka@redhat.com>2021-05-03 13:35:26 -0400
commiteef4fa6968ae0682679c27dae06409db3d113d5d (patch)
tree68238e6b43a1003fd2966826295cf68185047fb4
parent34b51ea7184ebc651b39037dfea14f08722314b1 (diff)
downloadgcc-eef4fa6968ae0682679c27dae06409db3d113d5d.zip
gcc-eef4fa6968ae0682679c27dae06409db3d113d5d.tar.gz
gcc-eef4fa6968ae0682679c27dae06409db3d113d5d.tar.bz2
c++: mark_used and ADL with template-id [PR100344]
My r11-295 patch for PR68942 didn't consider that the callee of an ADL-eligible function call can be a TEMPLATE_ID_EXPR, and we don't want to disable mark_used when substituting into the template arguments of this TEMPLATE_ID_EXPR because the arguments are clearly used regardless of the outcome of ADL. In the first testcase below, this oversight causes us to trip over the assert in build_call_a for the call to find_index<int> because the function no longer had its TREE_USED bit set from mark_used. So this patch restricts the original fix to disable mark_used only when the callee is a FUNCTION_DECL, which seems to be the only case that matters for PR68942. For instance, in the second testcase below we already don't mark_used the deleted function specialization even before r11-295. gcc/cp/ChangeLog: PR c++/68942 PR c++/100344 * pt.c (tsubst_copy_and_build) <case CALL_EXPR>: Set tf_conv only when the callee is a FUNCTION_DECL. gcc/testsuite/ChangeLog: PR c++/68942 PR c++/100344 * g++.dg/template/call8.C: New test. * g++.dg/template/koenig12a.C: New test.
-rw-r--r--gcc/cp/pt.c12
-rw-r--r--gcc/testsuite/g++.dg/template/call8.C14
-rw-r--r--gcc/testsuite/g++.dg/template/koenig12a.C16
3 files changed, 37 insertions, 5 deletions
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 116bdd2..36a8cb5 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -20227,11 +20227,13 @@ tsubst_copy_and_build (tree t,
/* Avoid error about taking the address of a constructor. */
function = TREE_OPERAND (function, 0);
- /* When KOENIG_P, we don't want to mark_used the callee before
- augmenting the overload set via ADL, so during this initial
- substitution we disable mark_used by setting tf_conv (68942). */
- function = tsubst_copy_and_build (function, args,
- complain | (koenig_p * tf_conv),
+ tsubst_flags_t subcomplain = complain;
+ if (koenig_p && TREE_CODE (function) == FUNCTION_DECL)
+ /* When KOENIG_P, we don't want to mark_used the callee before
+ augmenting the overload set via ADL, so during this initial
+ substitution we disable mark_used by setting tf_conv (68942). */
+ subcomplain |= tf_conv;
+ function = tsubst_copy_and_build (function, args, subcomplain,
in_decl,
!qualified_p,
integral_constant_expression_p);
diff --git a/gcc/testsuite/g++.dg/template/call8.C b/gcc/testsuite/g++.dg/template/call8.C
new file mode 100644
index 0000000..04609dd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/call8.C
@@ -0,0 +1,14 @@
+// PR c++/100344
+// { dg-do compile { target c++11 } }
+
+template <class> constexpr int find_index() { return 1; }
+
+template <int, class T> void foo(T);
+
+template <class T> void get(T v) {
+ foo<find_index<T>()>(v);
+}
+
+int main() {
+ get(0);
+}
diff --git a/gcc/testsuite/g++.dg/template/koenig12a.C b/gcc/testsuite/g++.dg/template/koenig12a.C
new file mode 100644
index 0000000..96b98b9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/koenig12a.C
@@ -0,0 +1,16 @@
+// PR c++/68942
+// { dg-do compile { target c++11 } }
+// A template-id analogue of koenig12.C.
+
+template <int> void foo(...) = delete;
+
+template <class T> void lookup(T t) { foo<0>(t); }
+
+namespace N {
+ struct A { };
+ template <int> int foo(A);
+}
+
+int main() {
+ lookup(N::A{});
+}