Skip to content

Fix 'using namespace tracy' at global scope in a header file#1692

Closed
Vic-Min wants to merge 1 commit intovsg-dev:masterfrom
Vic-Min:master
Closed

Fix 'using namespace tracy' at global scope in a header file#1692
Vic-Min wants to merge 1 commit intovsg-dev:masterfrom
Vic-Min:master

Conversation

@Vic-Min
Copy link
Copy Markdown
Contributor

@Vic-Min Vic-Min commented Apr 13, 2026

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

#include <vsg/all.h>
#ifdef TRACY_ENABLE
#    include <vsg/utils/TracyInstrumentation.h>
#endif

struct Color{};

Color color;

error C2872: Color: ambiguous symbol can be "Color" or "tracy::Color"

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code

@robertosfield
Copy link
Copy Markdown
Collaborator

By putting the using namespace tracy inside the vsg scope, the namespace becomes vsg::tracy, which is not what is intended.

What platform are you working on? What version of tracy? Does the vsgtracyinstrumentation example compile for you?

@Vic-Min
Copy link
Copy Markdown
Contributor Author

Vic-Min commented Apr 14, 2026

By putting the using namespace tracy inside the vsg scope, the namespace becomes vsg::tracy, which is not what is intended.

This is not true, the namespace does not become vsg::tracy:

namespace tracy
{
    struct Color{};
};

namespace vsg 
{
    using namespace tracy;
};

tracy::Color color; // Ok
vsg::tracy::Color color; // error: 'tracy' in namespace 'vsg' does not name a type

What platform are you working on?

Win10, VS2022

What version of tracy?

Last release 0.13.1

Does the vsgtracyinstrumentation example compile for you?

The vsgtracyinstrumentation example compiles.
My code, which defines the Color class, doesn't compile.
MRE - in the first post.

I proposed this solution as a minimal one that solves the problem.
In my opinion, a better solution would be to add using namespace tracy to the beginning of the enter/leave methods and replace VkCtx with tracy::VkCtx.
I'm ready to submit a PR for this.

@robertosfield
Copy link
Copy Markdown
Collaborator

I have just updated my old tracy checkout to 0.13.1 and the library compiles fine but the profiler is broken due to a new Wayland dependency. I'd guess my Kubuntu 24.04 systems Wayland libs are older than the latest Tracy is built against. Arrgg what a pain.

In generally I prefer not using using namespace in headers, when I originally wrote the VSG tracy support I followed 3rd party examples and Tracy itself for inspiration. That was a while back and haven't touched it much since.

@robertosfield
Copy link
Copy Markdown
Collaborator

To test I added:

struct Color{};

Color color;

to vsgtracyinstrumentation and then commented out the using namespace tracy and fixed build issues by putting in explict tracy:: in the TracyInstrumentation.h header. With these changes the above compiles in vsgtracyinstrumentation: 24f21da

I will close this PR as VSG master should now work fine for you.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants