Bug 79009 - Missing 'inconsistent deduction for ‘auto’' error when having a dependent initializer and a nondependent one in the same declaration
Summary: Missing 'inconsistent deduction for ‘auto’' error when having a dependent ini...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
: 59960 79624 86185 92509 98919 116368 (view as bug list)
Depends on: 79013 78693
Blocks: 79624
  Show dependency treegraph
 
Reported: 2017-01-05 22:56 UTC by Jakub Jelinek
Modified: 2024-08-21 14:59 UTC (History)
11 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-04-16 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2017-01-05 22:56:22 UTC
+++ 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);
}
Comment 1 Martin Dorey 2017-01-20 00:52:50 UTC
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.
Comment 2 Sasha Unknown 2018-04-16 19:42:33 UTC
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;
}
Comment 3 Jonathan Wakely 2018-04-16 20:00:00 UTC
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.
Comment 4 Jonathan Wakely 2018-04-16 20:02:41 UTC
*** Bug 59960 has been marked as a duplicate of this bug. ***
Comment 5 Jonathan Wakely 2018-06-18 12:23:19 UTC
*** Bug 86185 has been marked as a duplicate of this bug. ***
Comment 6 Jonathan Wakely 2019-11-14 16:01:44 UTC
*** Bug 92509 has been marked as a duplicate of this bug. ***
Comment 7 Jonathan Wakely 2021-02-01 18:10:39 UTC
*** Bug 98919 has been marked as a duplicate of this bug. ***
Comment 8 Andrew Pinski 2024-08-14 07:13:28 UTC
*** Bug 116368 has been marked as a duplicate of this bug. ***
Comment 9 Andrew Pinski 2024-08-14 07:14:47 UTC
*** Bug 79624 has been marked as a duplicate of this bug. ***
Comment 10 Andrew Pinski 2024-08-21 14:59:08 UTC
*** Bug 116446 has been marked as a duplicate of this bug. ***