This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/78693] [6/7 Regression] Bogus 'inconsistent deduction for ‘auto’' error when having a dependent initializer and a nondependent one in the same declaration


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78693

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 40437
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40437&action=edit
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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]