Author Topic: Improve Context Tagging handling std::shared_ptr  (Read 1796 times)

kniped1

  • Community Member
  • Posts: 19
  • Hero Points: 1
Improve Context Tagging handling std::shared_ptr
« on: September 09, 2021, 03:17:40 PM »
Context Tagging doesn't seem to support de-referencing a shared_ptr, but it works with a unique_ptr:
Code: [Select]
#include  <memory>

struct ParamData {
    double val;
    int val2;
};

class Param : public std::shared_ptr<ParamData> {
    public:
        /// Construct a shared pointer with a raw pointer to a parameter data struct
        /// \param d the parameter data structure
        explicit Param(ParamData *d) : std::shared_ptr<ParamData>(d) {}
        /// Default construct a parameter (blank)
        Param() : std::shared_ptr<ParamData>(new ParamData) {}

        double ext_val;
        ParamData* ptr_obj = new ParamData();
        std::shared_ptr<ParamData> shared_obj = std::shared_ptr<ParamData>(new ParamData);
        std::unique_ptr<ParamData> unique_obj = std::unique_ptr<ParamData>(new ParamData);
};

void test_function() {
    Param paramA;
   
    paramA->val = 0.5;                  //!< Error: Context Tagging doesn't contain any info
    paramA->val2 = 1;                   //!< Error: Context Tagging doesn't contain any info
    paramA.get()->val = 0.5;            //!< Error: Context Tagging doesn't contain any info
    paramA.get()->val2 = 1;             //!< Error: Context Tagging doesn't contain any info
    paramA.ext_val = 1.0;               //!< OK: Context Tagging shows this as a double
    paramA.ptr_obj->val = 0.5;          //!< OK: Context Tagging shows this as a double
    paramA.ptr_obj->val2 = 1;           //!< OK: Context Tagging shows this as a int
    paramA.shared_obj->val = 0.5;       //!< Error: Context Tagging doesn't contain any info
    paramA.shared_obj->val2 = 1;        //!< Error: Context Tagging doesn't contain any info
    (*paramA.shared_obj).val = 0.5;     //!< Error: Context Tagging doesn't contain any info 
    (*paramA.shared_obj).val2 = 1;      //!< Error: Context Tagging doesn't contain any info 
    paramA.shared_obj.get()->val = 0.5; //!< OK: Context Tagging shows this as a double
    paramA.shared_obj.get()->val2 = 1;  //!< OK: Context Tagging shows this as a int   
    paramA.unique_obj->val = 0.5;       //!< OK: Context Tagging shows this as a double
    paramA.unique_obj->val2 = 1;        //!< OK: Context Tagging shows this as a int
    (*paramA.unique_obj).val = 0.5;     //!< OK: Context Tagging shows this as a double                                   
    (*paramA.unique_obj).val2 = 1;      //!< OK: Context Tagging shows this as a int   
    paramA.unique_obj.get()->val = 0.5; //!< OK: Context Tagging shows this as a double
    paramA.unique_obj.get()->val2 = 1;  //!< OK: Context Tagging shows this as a int   
}

In the example above, the dereference of the shared_ptr doesn't work, but dereferencing the pointer returned by the get() method does. The unique_ptr worked in all cases.

Quote
SlickEdit Pro 2021 (v26.0.0.2 64-bit Qt4)

Serial number: FE81038_BETA
License type: Beta License
License expiration: 2021-10-09 19:00:00
License file: /home/dknipe/slickedit-pro2021beta2/bin/slickedit.lic

Build Date: August 10, 2021
Emulation: CUA

OS: Linux
OS Version: S
Kernel Level: 5.0.16-100.fc28.x86_64
Build Version: #1 SMP Tue May 14 18:22:28 UTC 2019
Processor Architecture: x86_64

X Server Vendor: Fedora Project
Window Manager: Xfwm4
Display manager: /usr/sbin/gdm

Memory: 49% Load, 3258MB/6633MB Virtual
Shell Information: /home/dknipe/slickedit-pro2021beta2/bin/secsh -i
Screen Size: 1920 x 1095

Project Type: Gnuc
Language: .cpp (C/C++)
Encoding: UTF-8, no signature

Installation Directory: /home/dknipe/slickedit-pro2021beta2/
Configuration Directory: /home/dknipe/.slickedit/26.0.0/
Migrated from: /home/dknipe/.slickedit/25.0.2/
Spill File: /tmp/$slk.dknipe.7637

edit: Added SlickEdit info, and fixed compile issues in test code.
« Last Edit: September 09, 2021, 04:00:16 PM by kniped1 »

Dennis

  • Senior Community Member
  • Posts: 3960
  • Hero Points: 517
Re: Improve Context Tagging handling std::shared_ptr
« Reply #1 on: September 10, 2021, 02:25:53 PM »
What version of GCC is this using?

kniped1

  • Community Member
  • Posts: 19
  • Hero Points: 1
Re: Improve Context Tagging handling std::shared_ptr
« Reply #2 on: September 10, 2021, 10:26:34 PM »
gcc (GCC) 8.3.1 20190223 (Red Hat 8.3.1-2)

A screenshot of the SlickEdit compiler properties for C++ are attached.

Now that you ask though, I forgot that I had to actually specify this myself in SlickEdit as there was not option for version 8. It was populating as version 7 originally and wasn't working as I don't have version 7 installed.
« Last Edit: September 10, 2021, 10:30:04 PM by kniped1 »

Dennis

  • Senior Community Member
  • Posts: 3960
  • Hero Points: 517
Re: Improve Context Tagging handling std::shared_ptr
« Reply #3 on: January 11, 2022, 08:03:46 PM »
Just an FYI.  Finally was able to try this one out and it appears to work well with SlickEdit 26.0.1 and g++ 8.3.x.  I think the problem was fixed as part of another issue which was taken care of in 26.0.1.