Skip to content

C++ Scope Management Assertion Failure #4344

@gaborbernat

Description

@gaborbernat

Universal Ctags crashes with assertion failure in cxxScopePushTop at parsers/cxx/cxx_scope.c:238 when parsing complex C++ template specializations. The assertion false indicates an unexpected state in the scope stack management when handling member function pointer template specializations. Note, for this to crash the binary you need to run in debug mode.

Reproduced by:

// C++ template specialization that triggers scope management bug
template <class T>
struct TestUtil {
    static bool isNull(const T&) { return false; }
};

template <class T>
struct TestUtil<T*> {
    static bool isNull(T* f) { return 0 == f; }
};

template <class CLASS, class MEMTYPE>
inline
bool
TestUtil<MEMTYPE CLASS::*>::isNull(MEMTYPE CLASS::* f)
{
    return 0 == f;
}
# Save the above as scope_crash.h and run:
# This crashes with: cxxScopePushTop: Assertion `false' failed
./ctags -o /tmp/test scope_crash.h

Suggested fix: Improve the C++ scope stack management to properly handle complex template specializations, especially member function pointer specializations. The scope parser needs better logic to track nested template contexts and their specializations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions