simplecpp icon indicating copy to clipboard operation
simplecpp copied to clipboard

added `constness_ptr` as pointer wrapper to ensure actual method constness

Open firewave opened this issue 3 months ago • 3 comments

firewave avatar Sep 24 '25 17:09 firewave

Taken from https://github.com/danmar/cppcheck/pull/4785.

firewave avatar Sep 24 '25 17:09 firewave

I might spin out the class into a separate repo (as public domain) as this seems like something useful in general.

firewave avatar Sep 24 '25 18:09 firewave

This fails to compile with GCC before 15:

simplecpp.cpp:1742:37: error: operands to ‘?:’ have different types ‘const simplecpp::constness_ptr<simplecpp::Token>’ and ‘std::nullptr_t’
 1742 |                 valueToken = argtok ? argtok->next : nullptr;
      |                              ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

And with Visual Studio:

     6>C:\a\simplecpp\simplecpp\simplecpp.cpp(1742,54): error C2446: ':': no conversion from 'nullptr' to 'const simplecpp::constness_ptr<simplecpp::Token>' [C:\a\simplecpp\simplecpp\simplecpp_obj.vcxproj]
             C:\a\simplecpp\simplecpp\simplecpp.cpp(1742,54):
             Constructor for class 'simplecpp::constness_ptr<simplecpp::Token>' is declared 'explicit'

firewave avatar Sep 25 '25 06:09 firewave