SlickEdit Community

SlickEdit Product Discussion => SlickEdit® => Topic started by: rowbearto on January 18, 2022, 04:44:07 pm

Title: type with auto and dynamic_cast<> not determined - C++
Post by: rowbearto 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());
}

Title: Re: type with auto and dynamic_cast<> not determined - C++
Post by: Dennis 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.
Title: Re: type with auto and dynamic_cast<> not determined - C++
Post by: rowbearto 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.
Title: Re: type with auto and dynamic_cast<> not determined - C++
Post by: rowbearto 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*".
Title: Re: type with auto and dynamic_cast<> not determined - C++
Post by: Dennis 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\
Title: Re: type with auto and dynamic_cast<> not determined - C++
Post by: rowbearto 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.
Title: Re: type with auto and dynamic_cast<> not determined - C++
Post by: rowbearto on January 18, 2022, 10:09:41 pm
Yep, char*, see attached screenshot.
Title: Re: type with auto and dynamic_cast<> not determined - C++
Post by: Dennis on January 18, 2022, 10:11:05 pm
Document > C/C++ Options... > Context Tagging > Preview and Highlighting > |x| Evaluate and show return type
Title: Re: type with auto and dynamic_cast<> not determined - C++
Post by: rowbearto 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.



Title: Re: type with auto and dynamic_cast<> not determined - C++
Post by: rowbearto 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.

Title: Re: type with auto and dynamic_cast<> not determined - C++
Post by: rowbearto 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?
Title: Re: type with auto and dynamic_cast<> not determined - C++
Post by: rowbearto 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.
Title: Re: type with auto and dynamic_cast<> not determined - C++
Post by: rowbearto 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?
Title: Re: type with auto and dynamic_cast<> not determined - C++
Post by: rowbearto 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*.
Title: Re: type with auto and dynamic_cast<> not determined - C++
Post by: rowbearto 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.
Title: Re: type with auto and dynamic_cast<> not determined - C++
Post by: rowbearto on January 18, 2022, 10:37:30 pm
Now it reproduces when I copy my entire original config dir to the new config dir INCLUDING all subdirectories.

I'll look into providing this to you. It may be very large.
Title: Re: type with auto and dynamic_cast<> not determined - C++
Post by: rowbearto on January 18, 2022, 10:50:09 pm
I tarballed my entire 26.0.1 dir, including subdirs, and removed a few things. It still reproduces with this.

I sent a mail with a link to sstamp so he can download it and provide it to you.

I was only able to repro this by copying the entire 26.0.1 with its subdirs. I did this on Linux x64, so you'll probably have to do that too.

Also there are many 'vunxs2X.0.0.Xt.e/.ex' files in my config dir. Can I remove those? Seems like something brought over from a previous version? What are these files?
Title: Re: type with auto and dynamic_cast<> not determined - C++
Post by: Dennis on January 18, 2022, 10:51:51 pm
An easier way would be to run the following from the command line (with the cursor on 'derivedClassObj')

codehelp-trace-symbol-info-help

You will get a slew of output to the debug window, hit Ctrl+X in the debug to cut it to the clipboard.

You could also to to each symbol in the sample file and do a Ctrl+Dot.  The only options should be what you see in the current file.  I suspect it is picking up code from one of your C/C++ tag files which is defining DerivedClass to something that ultimately typedefs down to "char".
Title: Re: type with auto and dynamic_cast<> not determined - C++
Post by: rowbearto on January 19, 2022, 01:03:23 pm
Look for codehelp.log on support.

I think whatever is in the tagfile should not impact this. 'auto' has the tightest scope and should override anything in tag files.
Title: Re: type with auto and dynamic_cast<> not determined - C++
Post by: rowbearto on January 19, 2022, 01:11:43 pm
That log mentions /usr/include/rpcsvc/mount.h which has on the final line I post below (but not the final line of the file):

typedef char *name;

Don't know why SE is picking this up?

Code: [Select]
/*
 * Please do not edit this file.
 * It was generated using rpcgen.
 */

#ifndef _MOUNT_H_RPCGEN
#define _MOUNT_H_RPCGEN

#include <rpc/rpc.h>


#ifdef __cplusplus
extern "C" {
#endif

#define MNTPATHLEN 1024
#define MNTNAMLEN 255
#define FHSIZE 32

typedef char fhandle[FHSIZE];

struct fhstatus {
u_int fhs_status;
union {
fhandle fhs_fhandle;
} fhstatus_u;
};
typedef struct fhstatus fhstatus;

typedef char *dirpath;

typedef char *name;
Title: Re: type with auto and dynamic_cast<> not determined - C++
Post by: Dennis on January 19, 2022, 01:15:26 pm
Things go haywire before that.  It picks up a #define for dynamic_cast from your Qt tag file.
Title: Re: type with auto and dynamic_cast<> not determined - C++
Post by: rowbearto on January 19, 2022, 01:40:56 pm
I found below code in /usr/include/QtCore/qglobal.h.

It comes from tagfile: GCC-4.8.2-x86_64-redhat-linux.vtg

I added an #undef of QT_NO_DYNAMIC_CAST into preprocessing and rebuilt the GCC-4.8.2-x86_64-redhat-linux.vtg

Now it does find the right type, DerivedClass*

Strange thing is that there were other auto var = dynamic_cast<> in my codebase where the SE was correctly figuring out the type. Don't know why it worked sometimes and not others.

I suppose it is working now for me but would be nice is somehow SE got around this issue, or at least gave some indication to the user so they could easily find this issue and know to do an #undef.

Here is the code in /usr/include/QtCore/qglobal.h:

Code: [Select]
#ifdef QT_NO_DYNAMIC_CAST
#  define dynamic_cast QT_PREPEND_NAMESPACE(qt_dynamic_cast_check)

  template<typename T, typename X>
  T qt_dynamic_cast_check(X, T* = 0)
  { return T::dynamic_cast_will_always_fail_because_rtti_is_disabled; }
#endif
Title: Re: type with auto and dynamic_cast<> not determined - C++
Post by: Dennis on January 19, 2022, 04:55:16 pm
I am adding the same #undef to the pre-configured preprocessing for the hot fix.

I am also going to double-fix it by specifically not allowing "dynamic_cast" to be expanded as a #define

I also found a separate tagging issue with anonymous enumerate types nested in classes which will be fixed in 26.0.2.

There will also be another issue with preprocessing addressed in 26.0.2.

The issue with the global typedef "name" is less fixable.  It is a legitimately defined global, SlickEdit cannot just ignore it, however, the code to avoid going down that path makes it a moot point anyway.
Title: Re: type with auto and dynamic_cast<> not determined - C++
Post by: rowbearto on January 19, 2022, 04:59:25 pm
Thanks Dennis!