Commit Graph

5 Commits

Author SHA1 Message Date
William S Fulton 638742fbcc Detect inheriting constructors by base class match in the parser
The parser flagged an inheriting constructor (using Base::Base) only when the
terminal name of the nested-name-specifier equalled the unqualified-id, which
missed the form 'using Alias::Base' where Alias is a typedef for the direct base
Base.  The parser now also flags a candidate when the unqualified-id matches a
base class of the enclosing class, resolved through typedefs.  The type pass
verifies the candidate and clears it when the nested-name-specifier does not
resolve to an immediate base whose own name the unqualified-id is, so an ordinary
member using declaration is imported instead.

Extend cpp11_template_using_base and cpp11_inheriting_constructors_typedef with
the typedef-qualifier forms, including the base's own member typedef as the
qualifier, the base named by its own name through a typedef, and a member typedef
and protected method import.

Assisted-by: Claude Opus 4.8
2026-06-17 01:47:06 +01:00
William S Fulton b78dba177a Inherit constructors named through a typedef base
C++11 inheriting constructors (using Base::Base;) now work when the immediate
base class is named through a typedef, a chain of typedefs, a typedef whose
template argument is itself a typedef, a scope-qualified or namespaced name, or
a type-template parameter used directly as the base class (the mixin idiom).

The inheriting constructor's using-declaration qualifier is normalized in the
typepass stage; the inheriting base is then found by identity in the resolved base
class list and the base class' constructors are used to implement the inherited
constructors.

An inheriting-constructor using declaration whose qualifier is not an immediate
base class is reported with Warning 329 (uses base '...' which is not an
immediate base of '...') rather than the generic Warning 315.

Closes #2951)

Assisted-by: Claude Opus 4.8
2026-06-17 01:47:06 +01:00
William S Fulton 35e7cb8871 cpp11_template_using_base: build under D and Lua 2026-05-28 20:15:58 +01:00
William S Fulton 5d01d06e1d Test the inheriting-constructor form of the mixin pattern (#2951)
Extend cpp11_template_using_base to also cover

    template <typename I>
    struct Derived : I {
      using I::I;        // inheriting constructors through the parameter base
      using I::call;
    };

and exercise it from the python and java runmes by constructing
DerivedInt(10) and checking the seeded call() result.

Reference #2951 in CHANGES.current.
2026-05-28 00:19:45 +01:00
William S Fulton e88a88815e Substitute template parameters in using-declaration through a template parameter base
A using-declaration whose qualifier is a type-template parameter used
directly as the base class - the mixin idiom -

    template <typename I>
    struct Derived : I {
      using I::call;
    };

now has its template parameter substituted during instantiation, so a
wrapper for the inherited member is emitted on the instantiated derived
class. Previously the parameter was only substituted when the qualifier
was itself a template-id (e.g. BaseTemplate<T>::method), so the bare
parameter form emitted "Warning 315: Nothing known about 'I::call'" and
no wrapper was generated.

The change in templ.c removes the strchr(uname, '<') guard so the using
node's uname is always added to the template parameter substitution
patchlist.

Assisted-by: Claude Code (Opus 4.7)
2026-05-28 00:10:47 +01:00