Skip to content

C++: out-of-line template method qualified_name keeps template params (Box<T>::get), can overflow NAME_MAX #1286

Description

@Dshuishui

stripCppTemplateArgs (added in #1043 to drop <…> from templated base-class references so extends resolves) is not applied to method qualifiers. An out-of-line template method definition therefore keeps the class template parameter list in qualified_name.

Reproduction

template <typename T>
class Box { public: T get() const; void set(T v); private: T value; };

template <typename T> T Box<T>::get() const { return value; }
template <typename T> void Box<T>::set(T v) { value = v; }

After codegraph init, the nodes table has:

name qualified_name expected
get Box<T>::get Box::get
set Box<T>::set Box::set

Notes:

  • name is already clean (get); only the qualifier leaks.
  • Inline method bodies inside the class are unaffected (they come out as Box::get); only the out-of-line definition syntax leaks the params — so the same method gets a different qualified_name depending on where it's defined.
  • The <T> here is the primary template's parameter name (always T), not a specialization, so it carries no disambiguating value.

Severe manifestation — qualified_name can exceed NAME_MAX (255)

With long, multi-line template parameter names (this is the shape of ICU's capi_helper.h), codegraph stores the entire Class<…params…>::method — newlines included — as qualified_name:

qualified_name (272 bytes):
  ApiHelper<IntegerConversionSourceCTypeParameterForTheHelperTemplateClassInstanceLong,
            IntegerConversionDestinationCPlusPlusTypeParameterForTheHelperTemplateClassLong,
            kMagicValidationSentinelConstantForTheHelperTemplateClassInstanceGuardLong>::validate

A consumer that derives a filename from qualified_name then fails with OSError: [Errno 63] File name too long (272 > 255).

Impact

Same failure mode #1043 fixed for extends: name-matcher compares the qualifier before the last ::, and Box<T> does not match the class node indexed as Box, so a method resolved via its out-of-line definition can fail to link to its class.

Root cause / fix

extractCppReceiverType in src/extraction/languages/c-cpp.ts builds the receiver by joining the ::-parts of the declarator's qualified-id but does not strip template arguments; the receiver then becomes qualifiedName = \${receiverType}::${name}`intree-sitter.ts. Applying the existing stripCppTemplateArgsto the receiver (it already turnsOuter::InnerOuter::Inner`) fixes both the normal and the long-name case. PR incoming.

Reproduced on 1.4.x.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions