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

            Bug ID: 110785
           Summary: Incorrect return type deduction for const auto with no
                    return statement
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bbi5291 at gmail dot com
  Target Milestone: ---

With `g++ -std=c++2b` the following is rejected:
---
const auto f() { }
const void (*fp)() = &f;
---
with error message:
---
<source>:2:22: error: invalid conversion from 'void (*)()' to 'const void
(*)()' [-fpermissive]
    2 | const void (*fp)() = &f;
      |                      ^~
      |                      |
      |                      void (*)()
---

However, the type of `&f` should be `const void (*)()`.

Clang does the right thing here, as does MSVC. GCC also does the right thing if
the body of `f` contains the statement `return;`, instead of no return
statement.

Reply via email to