simplecpp
simplecpp copied to clipboard
added `constness_ptr` as pointer wrapper to ensure actual method constness
Taken from https://github.com/danmar/cppcheck/pull/4785.
I might spin out the class into a separate repo (as public domain) as this seems like something useful in general.
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'