Menu

#937 Inline Nested Namespaces - Code Refactoring/Completion not Working (and error symbol not found under cursor)

Undefined
open
nobody
Undefined
2021-05-03
2020-04-02
No

Hi all,

I hope I'm not reporting anything already reported, I didn't find it on the forums and here.

The problem is that, when using "inline" nested namespaces, like this: fn::kh::subnetting::function(), the code completion stops working, the code refactoring fails, and this is terrible for those like me who like to use inline nested namespaces.

Below you'll see the code with 3 nested namespaces, like this:

namespace fn{
    namespace kh{
        namespace subnetting{
        }
    }
}

But now try to replace it by:

namespace fn::namespace kh::namespace subnetting{
}

Then you'll notice that your function:
fn::kh::subnetting::sayHello("Gonzalo");

Although it continues to work, as obvious, if you try to change the "sayHello" function name, it doesn't change, it gives the error "symbol not found under cursor", as it doesn't recognize the nested functions.

Also, the autocompletion fails there, you'll be only able to write fn:: with auto completion of fn::sayHello, as if it was only inside the first namespace, and then you have to add the "kd::subnetting:: in the middle for it to be complete.

The same way, if you change it in the .h or .cpp file of the namespace, it changes them but not in the main.cpp because the inline nested namespace isn't parsed.

I know it may be more difficult than it seems, and I didn't find a ticket with it.

If you have one already, I'm terribly sorry to duplicate it, hope it's the first time.

You can easily replicate this behaviour, with simple code (sorry for the big chars it's the first time I use this):

main.cpp

int main(int argc,char argv){
    fn::kh::subnetting::sayHello("Gonzalo");
    return 0;
}

fn_kh_subnetting.h

#ifndef FN_KH_SUBNETTING_H_INCLUDED
#define FN_KH_SUBNETTING_H_INCLUDED
#import <iostream>
namespace fn{
    namespace kh{
        namespace subnetting{
            void sayHello(std::string name);
        }
    }
}

#endif // FN_KH_SUBNETTING_H_INCLUDED

Now the file fn_kh_subnetting_cpp:

include "fn_kh_subnetting.h"

namespace fn{
    namespace kh{
        namespace subnetting{
            void sayHello(std::string name){
                std::cout<<"Hello "<<name<<std::endl;
            }
        }
    }
}

Thanks!

3 Attachments

Discussion

  • Dimitry Sibiryakov

    Not only namespaces but nested classes are affected as well:

    struct A
    {
        struct B
        {
        };
    
        struct C
        {
            B* foo; // <-- Symbol B not found
            A::B* bar; // <-- ok, symbol B found
        };
    };
    
     
  • ollydbg

    ollydbg - 2021-05-03
    • labels: namespaces, nested, refactoring, symbol not found --> namespaces, nested, refactoring, symbol not found, CodeCompletion
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -6,20 +6,24 @@
    
     Below you&#39;ll see the code with 3 nested namespaces, like this:
    
    +~~~
     namespace fn{
        namespace kh{
            namespace subnetting{
             }
         }
     }
    +~~~
    
     But now try to replace it by:
    
    +~~~
     namespace fn::namespace kh::namespace subnetting{
     }
    +~~~
    
     Then you&#39;ll notice that your function:
    -fn::kh::subnetting::sayHello(&#34;Gonzalo&#34;);
    +`fn::kh::subnetting::sayHello(&#34;Gonzalo&#34;);`
    
     Although it continues to work, as obvious, if you try to change the &#34;sayHello&#34; function name, it doesn&#39;t change, it gives the error &#34;symbol not found under cursor&#34;, as it doesn&#39;t recognize the nested functions.
    
    @@ -34,13 +38,16 @@
     You can easily replicate this behaviour, with simple code (sorry for the big chars it&#39;s the first time I use this):
    
     #main.cpp
    +~~~
     int main(int argc,char argv){
         fn::kh::subnetting::sayHello(&#34;Gonzalo&#34;);
         return 0;
     }
    +~~~
    
     #fn_kh_subnetting.h
    
    +~~~
     #ifndef FN_KH_SUBNETTING_H_INCLUDED
     #define FN_KH_SUBNETTING_H_INCLUDED
     #import &lt;iostream&gt;
    @@ -53,10 +60,12 @@
     }
    
     #endif // FN_KH_SUBNETTING_H_INCLUDED
    +~~~
    
     Now the file fn_kh_subnetting_cpp:
    
     #include &#34;fn_kh_subnetting.h&#34;
    +~~~
     namespace fn{
        namespace kh{
            namespace subnetting{
    @@ -66,5 +75,6 @@
            }
        }
     }
    +~~~
    
     Thanks!
    
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.