-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong type of "this" pointer detected in a non-const method #2303
Comments
I believe this is "by design" and repros in VS 2017. The type "MyClass *const" is correct for "this" and it means "this" cannot be assigned to (it's const) and it points to an object of type "MyClass *", which is not const. If getPointer() was defined as "MyClass *getPointer() const" then the type of "this" would be "const MyClass *const". |
@sean-mcmanus But it violates the C++11 standard :( so there is currently no plan in the VS team to be more aligned with the standard on this issue? And, does VSCode's cpptool use VS as its internal engine? |
Okay, it looks like you're right, it's a bug: https://stackoverflow.com/questions/6067244/type-of-this-pointer . It got reported to VS: https://developercommunity.visualstudio.com/content/problem/293655/class-foo-const-this-reported-while-in-not-const-c.html . If they fix it, we'll take the fix as well. |
VS "Won't Fixed" the bug saying it didn't have enough "votes", but when I tried to upvote it, it wouldn't let me, so I created a new issue at https://developercommunity.visualstudio.com/content/problem/416906/c-intellisense-wrong-type-of-this-pointer-detected.html -- that issue will probably need to get enough upvotes in order to get fixed though. |
Fixed with 0.25.0. |
Type: LanguageService
Describe the bug
MyClass
, thethis
pointer should be of typeMyClass *
in the hovering message (per C++11 standard 9.3.2 paragraph 1, C++17 standard 12.2.2.1 paragraph 1), notMyClass *const
.To Reproduce
Steps to reproduce the behavior:
test.cc
.this
pointer, examine the message.MyClass *const this
.Expected behavior
The type message should be
MyClass *this
.Screenshots

Additional text: this StackOverflow post said in the days of C++98 and C++03 old GCC and MSVC compilers internally used a trick that labels the
this
pointer as a const pointer. That trick was benign at that time but became problematic in C++11 and later standards. GCC has since abandoned that trick. I'm wondering if this is the problem. That post also said as of 2017 MSVC didn't fix the problem.The text was updated successfully, but these errors were encountered: