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