Intellisense (?) assumes that class members starting with underscore are private

Apologies in advance about possible use of incorrect terms. Is it autocomplete, intellisense, language server, suggestions or ... ?

Windows11, IDE 2.3.6.

I'm trying to adjust the naming convention that I use in classes. In the past I used to start private variables with an underscore. I'm now trying to adopt a naming convention where any class variable starts with an underscore (less typing than m_); I do not care if they are private or public or protected.

The below code as example

class ClassB
{
public:
  ClassB()
  {
  }

  int _x;
  int _y;
  int z;
};

ClassB b1;

void setup()
{
  Serial.begin(115200);
}

void loop()
{
  // put your main code here, to run repeatedly:
}

After typing b1. in setup() I only see the member that does not start with an underscore (z).

I would expect whatever it is to look at the access modifiers and not at variable names.

At least I now understand why I get inconsistent results in the 'suggestions'; I often change the names afterwards (from e.g. x to _x).

Did the forum software mangle your variable name ?

Not quite sure what you mean? One of the suggestions to name member variables is to use e.g. m_x. As said, I want to use _x which is less typing.

So _ is less typing than m_.

I wondered whether your example had been mangled in some way by the forum software interpreting what you had typed as HTLM/Markdown/etc

OK, I see now what you mean now
To be explicit you want to precede member variables with an underscore rather than an m followed by an underscore. That was not immediately obvious to me in your first post

However, I am sure that I remember reading somewhere that use of a leading underscore was deprecated due to the possibility of conflict with system variable names or some such. The suggest was, therefore, that trailing underscores should be used, but I cannot find where I read it

What I figured out is that that applies to names with all capitals as used in #define. But reading again I might have misinterpreted that. Guess I will starting using m_.

Reference was, https://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier and linked pages.

Anyway, I still think that treating a name starting with an underscore as a private variable is a bug.

So do I

They’re all the same; it’s the language server. Under the hood, it is clangd. If z is there, and both _x and _y are absent, I assume they are not indexed. It’s not exactly the same, but it could be related: findReferences not work with struct which name starts with "_" · Issue #1091 · clangd/clangd · GitHub. Note that the Arduino IDE 2.x uses a quite old clangd version.

I just read something that said system vars and anything else that should be hidden are to be preceded by TWO underscores. I think it was a CPP standard but don't quote me on that part.

I am not CPP trained and have only coded one or two classes so I remember them well. I used the format _myVar in the public section and it worked well. It was simply a local copy of one of the parameters.

These are reserved identifiers:

https://timsong-cpp.github.io/cppwp/n3337/reserved.names#global.names-1.1

Each name that contains a double underscore __ or begins with an underscore followed by an uppercase letter ([lex.key]) is reserved to the implementation for any use.

FYI, IntelliSense is Microsoft's name for its "features for programmers in editors", including code completion. Back when Borland made money selling IDEs, their name was Code Insight. A related feature is syntax highlighting. These were "hand-crafted" for languages like C++ and HTML to be included with their IDEs.

Microsoft later developed Language Server Protocol (for Visual Studio Code) to make such support pluggable for any language; it has since become an open standard, used by other editors. That protocol is implemented by (you guessed it) language servers.

An issue like this is in the language server (the back end). It's not the editor itself (the front end) deciding to hide certain things.