#What the #### is clang doing with inline namespaces???

33 messages · Page 1 of 1 (latest)

rare notch
#

namespace n1
{
    inline namespace n2
    {
        class S1
        {
            public:
            int x = 0;
        };
    }
}




int main()
{
    n1::S1 instance;
    instance.y;
}

GCC result:

<source>: In function 'int main()':
<source>:20:14: error: 'class n1::n2::S1' has no member named 'y'
   20 |     instance.y;
      |              ^
Compiler returned: 1

Clang:

<source>:20:14: error: no member named 'y' in 'n1::S1'
   20 |     instance.y;
      |     ~~~~~~~~ ^
1 error generated.
Compiler returned: 1

How do I force clang to reveal the inline namespace in the types???

zinc hawkBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

stable lake
#

try -fno-elide-type

rare notch
#

n2 is not shown

stable lake
#

then idk if you can show it

rare notch
#

even __PRETTY_FUNCTION__ with a type T doesn't reveal it

#

@civic wadi
Hey, you were bug reporting in clang,
got any ideas?

warm steeple
#

Clang drops the inline namespace in diagnostics only if the name is unambiguous without it.

#

;compile clang_trunk

namespace n1
{
    inline namespace n2
    {
        class S1
        {
            public:
            int x = 0;
        };
    }

    inline namespace n3
    {
        class S1
        {
            public:
            int x = 0;
        };
    }
}




int main()
{
    n1::n2::S1 instance;
    instance.y;
}
rare pawnBOT
#
Compiler Output
<source>:28:14: error: no member named 'y' in 'n1::n2::S1'
   28 |     instance.y;
      |     ~~~~~~~~ ^
1 error generated.
Build failed
rare notch
warm steeple
#

btw. I looked at the source and I think there is currently no option to change that behavior for the user

#

if you want that then you'd have to file an issue for feature request I guess

rare notch
warm steeple
rare notch
warm steeple
#

But that doesn't matter here anyway, this is about the printing of compiler diagnostic messages.

#

What are you trying to do with the diagnostic message anyway that you care? It is meant to be read by a human, not machine processed. (There are other output options for that.)

rare notch
#

so you gotta carefully do

namespace A
{
  class B
  {
    class C
    {

    };
  };
}

for example to trigger the duplicate and the compile error that spits out where the original is

warm steeple
#

Use clangd...

rare notch
#

I use clang++

warm steeple
#

clangd is a LSP implementation for your IDE/editor based on clang

#

it has functionality to just tell you where e.g. a variable is declared/defined and other code browsing

rare notch
warm steeple
#

you don't need to set up anything, you let your build system generate a compile_commands.json file, tell clangd/intellisense where that file is located and from there it just works

rare notch
#

if only you knew how insane our build tooling is...

warm steeple
rare notch
#

!solved