Bug 78693 - [6 Regression] Bogus 'inconsistent deduction for ‘auto’' error when having a dependent initializer and a nondependent one in the same declaration
Summary: [6 Regression] Bogus 'inconsistent deduction for ‘auto’' error when having a ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: 6.4
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
: 77347 (view as bug list)
Depends on:
Blocks: 79009 79013
  Show dependency treegraph
 
Reported: 2016-12-06 08:52 UTC by TC
Modified: 2017-01-18 16:26 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-12-06 00:00:00


Attachments
gcc7-pr78693.patch (633 bytes, patch)
2017-01-02 13:16 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description TC 2016-12-06 08:52:17 UTC
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).
Comment 1 Martin Liška 2016-12-06 18:02:56 UTC
Confirmed, started with r231349.
Comment 2 Jakub Jelinek 2016-12-21 10:59:00 UTC
GCC 6.3 is being released, adjusting target milestone.
Comment 3 Jakub Jelinek 2017-01-02 13:16:59 UTC
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.
Comment 4 Jakub Jelinek 2017-01-03 07:50:44 UTC
*** Bug 77347 has been marked as a duplicate of this bug. ***
Comment 5 Jakub Jelinek 2017-01-04 21:31:06 UTC
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
Comment 6 Jakub Jelinek 2017-01-04 21:36:10 UTC
Fixed on the trunk so far.  Will file a new PR for the still present accepts-invalid in templates.
Comment 7 Jakub Jelinek 2017-01-17 20:32:11 UTC
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
Comment 8 Jakub Jelinek 2017-01-18 16:26:16 UTC
Fixed for 6.4+.