lundi 1 avril 2019

QtCreator 4.4.1 Clang Code Model crashes when trying to resolve namespace name hidden behind macros

Background

I want to make a library that has some Qt interop, and wanted to develop a set of tools to expedite my library development. I reason that using macro definitions for my library structure is the right way to go, as it would allow both myself and library consumer's to express the greatest amount of control over the code. Unfortunately, ClangCodeModel appears to crash when parsing, although I have removed every possible flag.

Problem

I've defined a series of macros as the following:

#ifndef NAMESPACE_NAME
    #define NAMESPACE_NAME test
#endif
#ifndef BEGIN_NAMESPACE 
    #define BEGIN_NAMESPACE namespace NAMESPACE_NAME {
#endif
#ifndef END_NAMESPACE 
    #define END_NAMESPACE }
#endif
#ifndef NAMESPACE_ALIAS
    #define NAMESPACE_ALIAS te
#endif
#ifndef USE_NAMESPACE_ALIAS
    BEGIN_NAMESPACE END_NAMESPACE /* Namespace must be declared first */
    namespace NAMESPACE_ALIAS = NAMESPACE_NAME;
#endif

I find this approach preferable for a number of reasons, mainly for the level of control it allows me to express, as well as the ability to inject unique identifiers. This approach allows me to perform useful maintenance features, such as nesting namespaces without having to perform massive search and replace (example: moving test namespace to test::math or something like that can be a pain even on modern IDEs), which I find myself doing quite often, though admittedly earlier on in library development. However, using these common definition even from a project only standpoint caused ClangCodeModel to crash with every keystroke.

Example

Typing the following:

BEGIN_NAMESPACE

struct test{};

END_NAMESPACE

Will cause ClangCodeModel to crash everytime with the following message: Clang Code Model Error: The clangbackend process has finished unexpectedly and was restarted. I added the recommended environment variables from this link, and libclang jsut says crash detected during reparsing with a stack trace from libc.so.6 clone + 109(hex: 0x6d).

Question (tl;dr)

Why does adding a BEGIN_NAMESPACE and END_NAMESPACE macro cause Clang Code Model to segfault? When the code is rewritten to have namespace NAMESPACE_NAME {} Clang Code Model no longer segfaults. Is there anything I can do to fix this? It wouldn't be terribly inconvenient to refactor my design, but I see no reason as to why the Clang Code Model shouldn't be able to parse namespace definitions hidden behind macros.

Aucun commentaire:

Enregistrer un commentaire