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

            Bug ID: 111484
           Summary: bogus "error: inconsistent deduction for auto return
                    type" in if-constexpr branches
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

Given:

template<typename T>
auto foo()
{
  using ref = T&;
  if constexpr (__is_same(ref, ref))
    return 1;
  else
    return 1L;
}

int main()
{
  foo<void>();
}


The invalid type in the condition prevents both branches from being discarded,
and so we get two different types deduced for the return type:

ded.cc: In instantiation of 'auto foo() [with T = void]':
ded.cc:13:12:   required from here
ded.cc:4:9: error: forming reference to void
    4 |   using ref = T&;
      |         ^~~
ded.cc:8:12: error: inconsistent deduction for auto return type: 'int' and then
'long int'
    8 |     return 1L;
      |            ^~


I don't know how easy (or worthwhile) it would be to suppress that second
error.

Reply via email to