+++ This bug was initially created as a clone of Bug #78693 +++ The following testcase should be rejected during instantiation, because the auto deduced type in the same simple declaration is deduced differently. But we don't preserve the information what decls appeared together until instantiation, so don't diagnose it right now. 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); }
In my testing today, gcc 4.7.2, gcc 6.2.1 and Debian experimental's gcc 7.0.0 20161230, among other versions, reject the one-argument foo and bar instantiations from the OP's testcase, as I think they should. They accept the two-argument foo, I think incorrectly, an accepts-invalid bug. (clang rejects all three.) But the Subject line's use of "nondependent" suggests the OP is reporting an accepts-invalid error on the one-argument instantiations. Could it be that's a regression between 20161230 and 2017-01-05? I don't feel the two-argument foo - the bug I can reproduce - is covered by the Subject line. That's OK, as: Bug #59960 - accepts ill-formed 'auto a1 = t1, a2 = t2;' where t1 and t2 have different template types ... looks to have reported much the same thing, some three years earlier. It's unloved by any cc:s and, unlike this PR, has no Depends-on.
I confirm that this still happens on my g++-7 (Ubuntu 7.2.0-1ubuntu1~16.04) 7.2.0. My test program (essentially the same as original): template<typename T> struct S {}; template<typename T> void f() { auto s = S<T>(), i = 1; } int main() { f<int>(); return 0; }
Confirmed. Clang rejects the original with: auto.cc:5:3: error: 'auto' deduced as 'long' in declaration of 'i' and deduced as 'int' in declaration of 'j' auto i = t, j = 1; ^ ~ ~ auto.cc:25:3: note: in instantiation of function template specialization 'foo<long>' requested here foo (0L); ^ auto.cc:12:3: error: 'auto' deduced as 'int' in declaration of 'i' and deduced as 'long' in declaration of 'j' auto i = 1, j = t, k = 2; ^ ~ ~ auto.cc:26:3: note: in instantiation of function template specialization 'bar<long>' requested here bar (0L); ^ auto.cc:19:3: error: 'auto' deduced as 'int' in declaration of 'i' and deduced as 'long' in declaration of 'j' auto i = t, j = u; ^ ~ ~ auto.cc:27:3: note: in instantiation of function template specialization 'foo<int, long>' requested here foo (1, 2L); ^ 3 errors generated. And similarly for comment 2: auto.cc:7:9: error: 'auto' deduced as 'S<int>' in declaration of 's' and deduced as 'int' in declaration of 'i' auto s = S<T>(), i = 1; ^ ~~~~~~ ~ auto.cc:11:9: note: in instantiation of function template specialization 'f<int>' requested here f<int>(); ^ 1 error generated.
*** Bug 59960 has been marked as a duplicate of this bug. ***
*** Bug 86185 has been marked as a duplicate of this bug. ***
*** Bug 92509 has been marked as a duplicate of this bug. ***
*** Bug 98919 has been marked as a duplicate of this bug. ***
*** Bug 116368 has been marked as a duplicate of this bug. ***
*** Bug 79624 has been marked as a duplicate of this bug. ***
*** Bug 116446 has been marked as a duplicate of this bug. ***