public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106893] New: auto deduces wrong type for function pointer
@ 2022-09-08 21:53 dan at stahlke dot org
  2022-09-08 22:07 ` [Bug c++/106893] [12/13 Regression] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: dan at stahlke dot org @ 2022-09-08 21:53 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106893
           Summary: auto deduces wrong type for function pointer
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dan at stahlke dot org
  Target Milestone: ---

This works in 11.3.0 but not in 12.2.0.

struct IntegerCoordinate {
    int x() const;
    int y() const;
};

template <typename T>
struct CoordTraits
{
    static auto GetX(T const &p) { return p.x(); }
    static auto GetY(T const &p) { return p.y(); }
    using Ordinate = decltype(GetX(T{}));
};

template <typename Traits>
struct Node {
    static constexpr auto GetX = Traits::GetX; // works because of the `using
Ordinate = ...`
    static constexpr auto GetY = Traits::GetY; // compilation error
    // This compiles
    //static constexpr auto GetX = &Traits::GetX;
    //static constexpr auto GetY = &Traits::GetY;
    // This compiles
    //using fptr = int(*)(IntegerCoordinate const &);
    //static constexpr fptr GetX = Traits::GetX;
    //static constexpr fptr GetY = Traits::GetY;

    // Not needed for minimal test case
    auto x(auto const &p) const { return GetX(p); }
    auto y(auto const &p) const { return GetY(p); }
};

int main() {
    Node<CoordTraits<IntegerCoordinate>> node;
    // Not needed for minimal test case
    node.x(IntegerCoordinate{});
    node.y(IntegerCoordinate{});
}


$ g++ -std=c++20 gcc-function-ptr-bug.cpp -c -o gcc-function-ptr-bug.o

gcc-function-ptr-bug.cpp: In instantiation of ‘constexpr auto (* const
Node<CoordTraits<IntegerCoordinate> >::GetY)(const IntegerCoordinate&)’:
gcc-function-ptr-bug.cpp:17:27:   required from ‘struct
Node<CoordTraits<IntegerCoordinate> >’
gcc-function-ptr-bug.cpp:32:42:   required from here
gcc-function-ptr-bug.cpp:17:27: error: invalid conversion from ‘int (*)(const
IntegerCoordinate&)’ to ‘auto (*)(const IntegerCoordinate&)’ [-fpermissive]
   17 |     static constexpr auto GetY = Traits::GetY; // compilation error
      |                           ^~~~
      |                           |
      |                           int (*)(const IntegerCoordinate&)
gcc-function-ptr-bug.cpp: In instantiation of ‘auto Node<Traits>::y(const
auto:2&) const [with auto:2 = IntegerCoordinate; Traits =
CoordTraits<IntegerCoordinate>]’:
gcc-function-ptr-bug.cpp:35:11:   required from here
gcc-function-ptr-bug.cpp:28:46: error: use of
‘Node<CoordTraits<IntegerCoordinate> >::GetY’ before deduction of ‘auto’
   28 |     auto y(auto const &p) const { return GetY(p); }
      |                                          ~~~~^~~

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-04-21 20:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-08 21:53 [Bug c++/106893] New: auto deduces wrong type for function pointer dan at stahlke dot org
2022-09-08 22:07 ` [Bug c++/106893] [12/13 Regression] " pinskia at gcc dot gnu.org
2022-09-09 10:36 ` redi at gcc dot gnu.org
2022-09-12 17:28 ` jason at gcc dot gnu.org
2022-09-12 19:47 ` cvs-commit at gcc dot gnu.org
2022-09-12 20:30 ` [Bug c++/106893] [12 " cvs-commit at gcc dot gnu.org
2023-04-21 20:13 ` jason at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).