template<class T> void foo (T t) { auto i = t, j = 1; } prog.cc: In function 'void foo(T)': prog.cc:3:3: error: inconsistent deduction for 'auto': 'auto' and then 'int' auto i = t, j = 1; ^~~~ Accepted by GCC 5.3, Clang, MSVC (CL 19 on gcc.beta.godbolt.org, whatever that corresponds to) and ICC 17 (but with a bogus warning). Rejected by 6.1 and 7 (on Wandbox).
Confirmed, started with r231349.
GCC 6.3 is being released, adjusting target milestone.
Created attachment 40437 [details] gcc7-pr78693.patch Untested fix, if auto deduction can't be performed during the parsing, because the initializers have dependent types, it is premature to diagnose inconsistent deduction, the deduction might be inconsistent, but might be consistent as well. But this also reveals that without extra infrastructure, we don't and can't diagnose invalid cases, e.g. template <class T> void foo (T t) { auto i = t, j = 1; } template <class T> void bar (T t) { auto i = 1, j = t, k = 2; } template <class T, class U> void foo (T t, U u) { auto i = t, j = u; } void foo () { foo (0L); bar (0L); foo (1, 2L); } After parsing we loose the information which variables have been declared together and what auto deduction has been performed. So perhaps we'd need some extra tree that would hold a vector of variables (for those not deduced during parsing) and auto_result (for those deduced during parsing) and during instantiation check for the inconsistencies again. Jason? Another probably invalid testcase I found while googling around for this is: struct A { auto foo(), bar(); }; auto A::foo() { return 1; } auto A::bar() { return 2; } [dcl.spec.auto]/7 in N4618 says: "If the init-declarator-list contains more than one init-declarator, they shall all form declarations of variables." so the last testcase I think violates that. and "The type of each declared variable is determined by placeholder type deduction (7.1.7.4.1), and if the type that replaces the placeholder type is not the same in each deduction, the program is ill-formed." later in the same paragraph is why the first testcase above should be diagnosed.
*** Bug 77347 has been marked as a duplicate of this bug. ***
Author: jakub Date: Wed Jan 4 21:30:35 2017 New Revision: 244074 URL: https://gcc.gnu.org/viewcvs?rev=244074&root=gcc&view=rev Log: PR c++/78693 * parser.c (cp_parser_simple_declaration): Only complain about inconsistent auto deduction if auto_result doesn't use auto. * g++.dg/cpp0x/pr78693.C: New test. Added: trunk/gcc/testsuite/g++.dg/cpp0x/pr78693.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/parser.c trunk/gcc/testsuite/ChangeLog
Fixed on the trunk so far. Will file a new PR for the still present accepts-invalid in templates.
Author: jakub Date: Tue Jan 17 20:31:40 2017 New Revision: 244551 URL: https://gcc.gnu.org/viewcvs?rev=244551&root=gcc&view=rev Log: Backported from mainline 2017-01-04 Jakub Jelinek <jakub@redhat.com> PR c++/78693 * parser.c (cp_parser_simple_declaration): Only complain about inconsistent auto deduction if auto_result doesn't use auto. * g++.dg/cpp0x/pr78693.C: New test. Added: branches/gcc-6-branch/gcc/testsuite/g++.dg/cpp0x/pr78693.C Modified: branches/gcc-6-branch/gcc/cp/ChangeLog branches/gcc-6-branch/gcc/cp/parser.c branches/gcc-6-branch/gcc/testsuite/ChangeLog
Fixed for 6.4+.