public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106619] New: Inconsistent __PRETTY_FUNCTION__ output
@ 2022-08-15  8:05 kentsangkm at gmail dot com
  0 siblings, 0 replies; only message in thread
From: kentsangkm at gmail dot com @ 2022-08-15  8:05 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106619
           Summary: Inconsistent __PRETTY_FUNCTION__ output
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kentsangkm at gmail dot com
  Target Milestone: ---

Created attachment 53456
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53456&action=edit
example code

The __PRETTY_FUNCTION__ macro does print the function name as well as the
template arguments (if any), but the output is inconsistent and depends on the
declaration sequence.

// any templated typed with optional parameter(s)
template<typename T, typename U = std::conditional_t<std::is_void_v<T>, void,
T>>
struct Foo
{
};

template<typename T>
struct Container
{
    void get() const{
        std::cout << typeid(T).name() << "  "<< __PRETTY_FUNCTION__ <<
std::endl;
    }
};

int main()
{
    Container<Foo<int, int>> b;
    b.get();

    Container<Foo<int>> a;
    a.get();
}


Output:
3FooIiiE  void Container<T>::get() const [with T = Foo<int, int>]
3FooIiiE  void Container<T>::get() const [with T = Foo<int, int>]



If we swap the declaration of a and b, the output becomes:
3FooIiiE  void Container<T>::get() const [with T = Foo<int>]
3FooIiiE  void Container<T>::get() const [with T = Foo<int>]


in contrast, the typeid is very consistent on both cases, but it is not an
constexpr function



Clang does not have such issue, as it always expends the optional arguments and
output Foo<int, int> always


Here is a short link for godbolt
https://godbolt.org/z/vfTnz5bEb

the same code piece is also be enclosed

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-08-15  8:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-15  8:05 [Bug c++/106619] New: Inconsistent __PRETTY_FUNCTION__ output kentsangkm at gmail dot com

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).