]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/44193 (function types, cv-quals and typename)
authorJason Merrill <jason@redhat.com>
Wed, 19 May 2010 15:44:08 +0000 (11:44 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 19 May 2010 15:44:08 +0000 (11:44 -0400)
PR c++/44193
* pt.c (tsubst) [TYPENAME_TYPE]: Discard cv-quals on
function/reference type.

From-SVN: r159575

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/fntype1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/qualttp20.C

index 5b891c00a8837ba60786db44587c6a4c9ff65679..df69a8ec077e633675a3064ce760073ba1e6a95d 100644 (file)
@@ -1,3 +1,9 @@
+2010-05-19  Jason Merrill  <jason@redhat.com>
+
+       PR c++/44193
+       * pt.c (tsubst) [TYPENAME_TYPE]: Discard cv-quals on
+       function/reference type.
+
 2010-04-20  Richard Guenther  <rguenther@suse.de>
 
        Backport from mainline
index 46866c030485f20091eda0948066b06e0ae3aaa8..434e0cf8bfffc8305b2b68dd03af79ddf06b5f69 100644 (file)
@@ -9411,6 +9411,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
                                     in_decl, /*entering_scope=*/1);
        tree f = tsubst_copy (TYPENAME_TYPE_FULLNAME (t), args,
                              complain, in_decl);
+       int quals;
 
        if (ctx == error_mark_node || f == error_mark_node)
          return error_mark_node;
@@ -9460,8 +9461,15 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
                     t, f);
          }
 
-       return cp_build_qualified_type_real
-         (f, cp_type_quals (f) | cp_type_quals (t), complain);
+       /* cv-quals from the template are discarded when
+          substituting in a function or reference type.  */
+       if (TREE_CODE (f) == FUNCTION_TYPE
+           || TREE_CODE (f) == METHOD_TYPE
+           || TREE_CODE (f) == REFERENCE_TYPE)
+         quals = cp_type_quals (f);
+       else
+         quals = cp_type_quals (f) | cp_type_quals (t);
+       return cp_build_qualified_type_real (f, quals, complain);
       }
 
     case UNBOUND_CLASS_TEMPLATE:
index 93a89110b605a22ee5b2c8ed61b87d2592dde64c..d5955128b94ab095c8c8b27aeac5e3358f3507fe 100644 (file)
@@ -1,3 +1,8 @@
+2010-05-19  Jason Merrill  <jason@redhat.com>
+
+       PR c++/44193
+       * g++.dg/template/fntype1.C: New.
+
 2010-04-30  DJ Delorie  <dj@redhat.com>
 
        * gcc.c-torture/execute/20100430-1.c: New test.
diff --git a/gcc/testsuite/g++.dg/template/fntype1.C b/gcc/testsuite/g++.dg/template/fntype1.C
new file mode 100644 (file)
index 0000000..d7be273
--- /dev/null
@@ -0,0 +1,26 @@
+bool f(int i) { return i != 5; }
+
+template <class X, class P = bool(X)>
+struct Traits
+{
+ typedef P type;
+};
+
+template <class X, class P = typename Traits<X>::type>
+struct S
+{
+ const P& p_;
+ S( const P& p ) : p_(p) {} // const reference
+};
+
+template <class X>
+S<X> make_s(const typename Traits<X>::type & p) // const reference
+{
+ return S<X>(p); // << HERE
+}
+
+
+int main()
+{
+ make_s<int>(f);
+}
index ae20d7629020fe28badceebb28669c7b1e14247f..ea581db54465ed84f952ca01031ad25233b2dc71 100644 (file)
@@ -17,7 +17,7 @@ struct AS
 template <typename T> struct B1 : T
 {
   typedef typename T::L __restrict__ r;// { dg-error "'__restrict__' qualifiers cannot" "" }
-  typedef typename T::myT __restrict__ p;// { dg-error "ignoring '__restrict__'" }
+  typedef typename T::myT __restrict__ p;
 
   // The following are DR 295 dependent
   typedef typename T::myT volatile *myvolatile;