This valid C++17 program fails to compile: template<typename T> struct container { }; void must_be_const(const container<int>&) { } void must_be_const(container<int>&) = delete; int main() { container<int> c; const container d = c; must_be_const(d); } $ g++ -std=c++17 const.cc const.cc: In function ‘int main()’: const.cc:10:18: error: use of deleted function ‘void must_be_const(container<int>&)’ must_be_const(d); ^ const.cc:4:6: note: declared here void must_be_const(container<int>&) = delete; ^~~~~~~~~~~~~ The variable 'd' should be const, so should not call the deleted overload.
FWIW using -fconcepts and const container<auto> doesn't lose the qualifiers.
Testing this patch: --- 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
Patch posted to https://gcc.gnu.org/ml/gcc-patches/2017-06/msg00372.html
Author: redi Date: Wed Jun 7 11:34:36 2017 New Revision: 248966 URL: https://gcc.gnu.org/viewcvs?rev=248966&root=gcc&view=rev Log: 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. Added: trunk/gcc/testsuite/g++.dg/cpp1z/class-deduction39.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/pt.c trunk/gcc/testsuite/ChangeLog
Fixed on trunk so far, I'd like to backport this to gcc-7-branch.
Jonathan: Can you please update Known to work?
I no longer plan to backport this.
*** Bug 83818 has been marked as a duplicate of this bug. ***