Skip to content

Bug: Global using types can conflict with downstream users #6323

Closed

Description

@luca-della-vedova

Describe the bug
#6266 introduced three global using directives, specifically

using MeshArray = std::vector<aiMesh *>;
using NodeArray = std::vector<aiNode *>;
using MaterialArray = std::vector<aiMaterial*>;
.

These are not in the Assimp namespace and the names are generic enough that they will cause issues to downstream users that import the library and have structs with the same name.

An example of a downstream library that uses assimp and will be broken by this change is the Bullet physics library, that uses its own NodeArray type here. Exporting a global NodeArray will force the library to either rename their type or fail compilation going forward.

Proposed Solution

The new types should be namespaced to Assimp instead

Activity

  1. added
    Bug
    on Aug 13, 2025
  2. tellypresence commented on Aug 13, 2025

    @tellypresence
    Collaborator

    @luca-della-vedova Thank you for the report; those using directives shouldn't be in that .h file.

    General C++ advice is that using directives shouldn't be in header files, some references:

    A using directive can be placed at the top of a .cpp file (at file scope), or inside a class or function definition.
    
    In general, avoid putting using directives in header files (*.h) because any file that includes that header will 
    bring everything in the namespace into scope, which can cause name hiding and name collision problems 
    that are very difficult to debug. Always use fully qualified names in a header file.
    
    A good rule of thumb is that using-statements should not be placed anywhere where they might have an impact on 
    code in a different file. Nor should they be placed anywhere where another file’s code might be able to impact them.
    
    More specifically, this means using-statements should not be used in header files, nor before an #include directive.
    
  3. luca-della-vedova commented on Aug 13, 2025

    @luca-della-vedova
    ContributorAuthor

    Hi and thanks for the quick reply!

    I fully agree with you and actually my first recommendation would be to just revert the change itself. Given how the types are used just a few times but in a lot of different files, moving the using directive from the header to the source file would cause a lot of duplication, pretty much defeating the original scope of the PR that was meant to be a cleanup, hence my second in order of preference of a "compromise" to encapsulate it in the namespace.
    I'll open a PR to revert it then!

  4. luca-della-vedova commented on Aug 14, 2025

    @luca-della-vedova
    ContributorAuthor

    Opened reverting PR #6324

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions