Author Topic: type with auto and dynamic_cast<> not determined - C++  (Read 2695 times)

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
type with auto and dynamic_cast<> not determined - C++
« on: January 18, 2022, 04:44:07 PM »
In the below code SE should determine that the type of derivedClassObj should be DerivedClass*, but it says 'name' instead.

See "PROBLEM" in the code below.

This is with 26.0.1 on Linux x64.

Code: [Select]
class BaseClass
{
    BaseClass() {};
    virtual void someVirtualFunc() {};
};

class DerivedClass : public BaseClass
{
};

BaseClass *funcThatReturnsBaseClassPtr()
{
    return nullptr;
}

void func()
{
    // PROBLEM: Do "Preview" on derivedClassObj, its type should be inferred
    // to DerivedClass*, but it says 'name'
    auto derivedClassObj = dynamic_cast<DerivedClass*>(funcThatReturnsBaseClassPtr());
}


Dennis

  • Senior Community Member
  • Posts: 3955
  • Hero Points: 515
Re: type with auto and dynamic_cast<> not determined - C++
« Reply #1 on: January 18, 2022, 09:44:17 PM »
I can not reproduce this with 26.0.1 with the given sample.  There must be something missing -- otherwise, I do not know where 'name' came from.

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: type with auto and dynamic_cast<> not determined - C++
« Reply #2 on: January 18, 2022, 10:01:35 PM »
Look on support for case number: "rowbearto_user_cfg_xml". Maybe my user.cfg.xml is the missing piece?

When I retried it just now with this user.cfg.xml I'm getting the following preview window for the type:

Code: [Select]
auto=dynamic_cast<DerivedClass*>( funcThatReturnsBaseClassPtr( ) )
I changed my user.cfg.xml since I submitted this post, don't know why the result would change.

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: type with auto and dynamic_cast<> not determined - C++
« Reply #3 on: January 18, 2022, 10:03:04 PM »
After closing my SE workspace and trying again with no SE workspace, now it is saying the type is "char*".

Dennis

  • Senior Community Member
  • Posts: 3955
  • Hero Points: 515
Re: type with auto and dynamic_cast<> not determined - C++
« Reply #4 on: January 18, 2022, 10:05:10 PM »
char* ??

Could you try in a clean default config?  You will need to enable the option to evaluate the type in Preview.

vs +new -sc C:\Temp\defcon1\

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: type with auto and dynamic_cast<> not determined - C++
« Reply #5 on: January 18, 2022, 10:08:35 PM »
Can you remind me how to enable that in Preview? I set it a while ago and don't remember how I did that.

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: type with auto and dynamic_cast<> not determined - C++
« Reply #6 on: January 18, 2022, 10:09:41 PM »
Yep, char*, see attached screenshot.

Dennis

  • Senior Community Member
  • Posts: 3955
  • Hero Points: 515
Re: type with auto and dynamic_cast<> not determined - C++
« Reply #7 on: January 18, 2022, 10:11:05 PM »
Document > C/C++ Options... > Context Tagging > Preview and Highlighting > |x| Evaluate and show return type

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: type with auto and dynamic_cast<> not determined - C++
« Reply #8 on: January 18, 2022, 10:19:04 PM »
It is also incorrect with a clean config, not char* or name, see attached screenshot.

When I previously did this I was using one of Clark's debug installers for another issue.

But this is with both a clean config and the release version of 26.0.1 on Linux x64.




rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: type with auto and dynamic_cast<> not determined - C++
« Reply #9 on: January 18, 2022, 10:23:07 PM »
Wait, I don't see "Evaluated Type" in the screenshot I provided you.

Yet I did set the option you specified according to attached screenshot.


rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: type with auto and dynamic_cast<> not determined - C++
« Reply #10 on: January 18, 2022, 10:24:31 PM »
I found the right option, had to highlight the other one.

Now it is correct with a clean config, see attached.

Did you try my user.cfg.xml?

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: type with auto and dynamic_cast<> not determined - C++
« Reply #11 on: January 18, 2022, 10:26:19 PM »
hmm, when I put my user.cfg.xml into a clean config, I don't see this error.

Maybe I try with Clark's debug version.

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: type with auto and dynamic_cast<> not determined - C++
« Reply #12 on: January 18, 2022, 10:27:43 PM »
With Clark's debug version and a clean config + my user.cfg.xml, it also evaluates correctly.

Hmm, what else can I try to make it repro?

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: type with auto and dynamic_cast<> not determined - C++
« Reply #13 on: January 18, 2022, 10:29:02 PM »
I restarted the release version of 26.0.1 on my original config directory and it is showing char*.

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: type with auto and dynamic_cast<> not determined - C++
« Reply #14 on: January 18, 2022, 10:34:42 PM »
I copied my old config dir to the new clean config dir (and not the subdirs) and it has the correct output, hmmm. Don't know what to try next.