Author Topic: problem with C++ tag references and namespaces  (Read 2842 times)

IkerAriz

  • Senior Community Member
  • Posts: 143
  • Hero Points: 6
problem with C++ tag references and namespaces
« on: September 30, 2014, 07:29:30 pm »
Having trouble finding symbol references in a cpp file that looks something like so:

Code: [Select]
// test.cpp
// function xxx() is defined in thing.cpp and declared in "thing.h" like this:
//    namespace x { void xxx(); }

include "thing.h"

using namespace std;
using namespace z;

namespace x {
    void test() {
        xxx();
    }
}

When I clicked "Go to reference" for the call to "xxx()" in the test file only the declaration and definition were returned (ie, in thing.h and thing.cpp). The usage site was not returned. However, when I did so it seemed like the correct set of 3 references  briefly showed up in the References window before the list settled down to just two hits.

Also, in my small test setup I noticed that if I removed the "using namespace z" line "Go to reference" returned all 3 hits. This "trick" didn't work on the larger project where I first hit this problem.

Regards,
Iker


IkerAriz

  • Senior Community Member
  • Posts: 143
  • Hero Points: 6
Re: problem with C++ tag references and namespaces
« Reply #1 on: October 01, 2014, 02:14:42 pm »
Some more info... when doing a "Go to reference" on the call to "xxx()" SE only shows the declaration and definition (which are in other files), not the symbol I clicked on. However, SE behaves as expected if the call is namespace-qualified to this "x::xxx()".

Regards,
Iker

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1092
  • Hero Points: 100
Re: problem with C++ tag references and namespaces
« Reply #2 on: October 01, 2014, 03:14:25 pm »
I could only reproduce this so far when I copied your example verbatim... but there was an error in test.cpp that was making the tagging parser veer off into the bushes.  When I put in the missing '#' in front of the 'include', it works as expected, giving all of the references.  Removing/adding the "using namespace z" statement would change the behavior because it has an indirect effect on where the parser lands when it tries to recover from the parse error.

It's possible something similar could be happening in your real source though, something causing a mis-parse in the file where your function call reference is not being picked up.  The most common problem we run into is with source code that uses the preprocessor macros heavily, especially if the preprocessor defines are used to spruce up or hide syntax.  They're a pain, but can usually be fixed by adding preprocessor definitions to your C++ configuration so the tagging parser knows what sort of replacements to do.

So take a look at one of the source files where the calls aren't being tagged as references.  I'd start right above the namespace declaration first, and look for anything suspicious there;  and if there's nothing there, then start looking before the function declaration that your call that isn't being picked up.   (and by suspicious, I mean anything that's loaded up with preprocessor macros, or  doesn't look like vanilla C++).

Let us know if you don't find anything you can distill into a test case for us.  There may be a way to try to figure out the location of a parse error using the debug output from the beautifier... but it's a bit of a long shot. 

IkerAriz

  • Senior Community Member
  • Posts: 143
  • Hero Points: 6
Re: problem with C++ tag references and namespaces
« Reply #3 on: October 01, 2014, 06:11:42 pm »
Attached is a tarball with a sample project and source files that demonstrate the problem. To reproduce, open the file "module1.cpp" and look for references to the "utilfunc1()" function. I was expecting 3 references, including the call site, but get only 2 (the declaration and definition).

The tarball also includes a screenshot showing  the results of "Go to reference".

Regards,
Iker

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1092
  • Hero Points: 100
Re: problem with C++ tag references and namespaces
« Reply #4 on: October 02, 2014, 01:39:01 pm »
I can reproduce it with that, looking in to it.

IkerAriz

  • Senior Community Member
  • Posts: 143
  • Hero Points: 6
Re: problem with C++ tag references and namespaces
« Reply #5 on: October 29, 2014, 02:46:40 pm »
Hello all,

Under RC1 the results are still short one reference - will a fix make it into the final release?

Thanks,
Iker

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1092
  • Hero Points: 100
Re: problem with C++ tag references and namespaces
« Reply #6 on: October 30, 2014, 01:01:01 pm »
Odd, I thought this was fixed, but I can reproduce it again in RC1.  I'll look at this next.

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2738
  • Hero Points: 419
Re: problem with C++ tag references and namespaces
« Reply #7 on: October 30, 2014, 04:47:23 pm »
Fixed.  Thanks for the thorough example.  The problem traced down to the reference coming from a static function, which we did not recognize was a static function in a namespace rather than a static function in a class scope.

IkerAriz

  • Senior Community Member
  • Posts: 143
  • Hero Points: 6
Re: problem with C++ tag references and namespaces
« Reply #8 on: October 31, 2014, 06:23:30 pm »
Fix confirmed in RC2. Thanks!

Iker