C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Specify the mangled name

From: Thiago Macieira <thiago_at_[hidden]>
Date: Tue, 04 Feb 2025 08:02:14 -0800
On Tuesday 4 February 2025 04:23:45 Pacific Standard Time Tiago Freire via Std-
Proposals wrote:
> This isn't exactly crazy.
>
> I'm currently working on this in order to be able to forward declare, not
> just any class, but any type.
>
> you would just do something like:
>
> typename MyType;

The only way this would work is if the compiler translates this to an #include
or import of something provided by said library so the type gets forward-
declared. Going back to Frederick's example, the compiler has no way of
knowing whether the snippet he gave was correct or if it needed to be:

namespace std {
    inline namespace __1 {
        template<class T> class less;
        template<class T> class allocator;
        template< class Key, class Compare = less<Key>, class
Allocator = allocator<Key> > class set;
    }
}

Since the compiler can't know this at all, it needs to come from the library
itself. That in turn allows us to extend the mechanism for other libraries
besides the Standard one. We turn the problem from "what is the nature of this
type" to "how do I find a small header that will declare it for me". And the
Standard can simply do a jedi mind trick here and say it is implementation-
defined how such a file is found.

The easiest of which would be that it includes <fwd/NS/NS/.../name> or <NS/NS/
name> (whichever exists first) and we just rely on the include system to
resolve it. For me, the great thing about this is that it would "just work"
right now for practically all Qt classes, from Qt 4 (2005) onwards.

We'd ask the compilers to provide tooling to auto-generate those files for us,
as they're compiling sources. This would simplify everyone's lives. Moreover,
a smart compiler here could also perform an ODR verification that the types
were declared the same way everywhere.


Finally, one extra feature I'd like to see is the ability to forward-declare
nested classes, such as:

class Outer;
struct Outer:: public Inner;
-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel DCAI Platform & System Engineering

Received on 2025-02-04 16:02:20