aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2006-08-16 20:51:37 -0400
committerJason Merrill <jason@gcc.gnu.org>2006-08-16 20:51:37 -0400
commit9180c238de746a8883e81552d446c3359284b7dd (patch)
tree329d90ea87976a7bc7e05d9b522879373892aaaf /gcc
parent4cb55a5ae0cfd1d9be20e2c6a994a74fb6ad4668 (diff)
downloadgcc-9180c238de746a8883e81552d446c3359284b7dd.zip
gcc-9180c238de746a8883e81552d446c3359284b7dd.tar.gz
gcc-9180c238de746a8883e81552d446c3359284b7dd.tar.bz2
re PR c++/28385 (templated function call goes awry)
PR c++/28385 * pt.c (tsubst) [TEMPLATE_TYPE_PARM]: Ignore quals from template if arg is a function. From-SVN: r116203
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/pt.c14
-rw-r--r--gcc/testsuite/g++.dg/template/const1.C30
3 files changed, 48 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 7b08dd7..f69c4ff 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2006-08-16 Jason Merrill <jason@redhat.com>
+
+ PR c++/28385
+ * pt.c (tsubst) [TEMPLATE_TYPE_PARM]: Ignore quals from template
+ if arg is a function.
+
2006-08-16 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/28593
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 4c2b45a..27b6d11 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -7238,10 +7238,20 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
{
if (TREE_CODE (t) == TEMPLATE_TYPE_PARM)
{
+ int quals;
gcc_assert (TYPE_P (arg));
+
+ /* cv-quals from the template are discarded when
+ substituting in a function or reference type. */
+ if (TREE_CODE (arg) == FUNCTION_TYPE
+ || TREE_CODE (arg) == METHOD_TYPE
+ || TREE_CODE (arg) == REFERENCE_TYPE)
+ quals = cp_type_quals (arg);
+ else
+ quals = cp_type_quals (arg) | cp_type_quals (t);
+
return cp_build_qualified_type_real
- (arg, cp_type_quals (arg) | cp_type_quals (t),
- complain | tf_ignore_bad_quals);
+ (arg, quals, complain | tf_ignore_bad_quals);
}
else if (TREE_CODE (t) == BOUND_TEMPLATE_TEMPLATE_PARM)
{
diff --git a/gcc/testsuite/g++.dg/template/const1.C b/gcc/testsuite/g++.dg/template/const1.C
new file mode 100644
index 0000000..629c4d4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/const1.C
@@ -0,0 +1,30 @@
+// PR c++/28385
+// instantiating op() with void()() was making the compiler think that 'fcn'
+// was const, so it could eliminate the call.
+
+// { dg-do run }
+
+extern "C" void abort (void);
+
+int barcnt = 0;
+
+class Foo {
+ public:
+ template<typename T>
+ void operator()(const T& fcn) {
+ fcn();
+ }
+};
+
+void bar() {
+ barcnt++;
+}
+
+int main() {
+ Foo myFoo;
+ myFoo(bar);
+ myFoo(&bar);
+ if (barcnt != 2)
+ abort ();
+ return 0;
+}