SlickEdit Product Discussion > Features and/or Improvements

Improve Context Tagging handling std::shared_ptr

(1/1)

kniped1:
Context Tagging doesn't seem to support de-referencing a shared_ptr, but it works with a unique_ptr:

--- Code: ---#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   
}

--- End code ---

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

--- End quote ---

edit: Added SlickEdit info, and fixed compile issues in test code.

Dennis:
What version of GCC is this using?

kniped1:
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.

Navigation

[0] Message Index

Go to full version