This fixes class template argument deduction so that cv-qualifiers are not ignored.
Bootstrapped and tested powerpc64le-linux. OK for trunk? PR c++/80990 * pt.c (do_class_deduction): Build qualified type.
commit 1a81d74fa9cf32cb33580cc4a5e9a7c5868ce32b Author: Jonathan Wakely <jwak...@redhat.com> Date: Tue Jun 6 18:38:30 2017 +0100 PR c++/80990 use cv-qualifiers in class template argument deduction gcc/cp: PR c++/80990 * pt.c (do_class_deduction): Build qualified type. gcc/testsuite: PR c++/80990 * g++.dg/cpp1z/class-deduction39.C: New. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index a04f2e0..ada94bd 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -25367,7 +25367,7 @@ do_class_deduction (tree ptype, tree tmpl, tree init, int flags, --cp_unevaluated_operand; release_tree_vector (args); - return TREE_TYPE (t); + return cp_build_qualified_type (TREE_TYPE (t), cp_type_quals (ptype)); } /* Replace occurrences of 'auto' in TYPE with the appropriate type deduced diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction39.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction39.C new file mode 100644 index 0000000..98a3664 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction39.C @@ -0,0 +1,15 @@ +// { dg-options -std=c++1z } + +template <class T> struct A { }; + +A<int> a; +const A c = a; +volatile A v = a; +const volatile A cv = a; + +template <class,class> struct same; +template <class T> struct same<T,T> {}; + +same<decltype(c), const A<int>> s1; +same<decltype(v), volatile A<int>> s2; +same<decltype(cv), const volatile A<int>> s3;