Skip to content

Improve C2135 error reference #5658

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Rageking8
Copy link
Contributor

// C2135.cpp

struct S
{
    int bit_field : 1;
};

int main()
{
    &S::bit_field;   // C2135
    +S::bit_field;   // C2135
    -S::bit_field;   // C2135
    !S::bit_field;   // C2135
    ~S::bit_field;   // C2135
    *S::bit_field;   // C2135
}
C:\Test>cl C2135.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.44.35214 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

C2135.cpp
C2135.cpp(10): error C2135: 'bit_field': you cannot apply '&' to a bit-field
C2135.cpp(11): error C2135: 'bit_field': you cannot apply '+' to a bit-field
C2135.cpp(12): error C2135: 'bit_field': you cannot apply '-' to a bit-field
C2135.cpp(13): error C2135: 'bit_field': you cannot apply '!' to a bit-field
C2135.cpp(14): error C2135: 'bit_field': you cannot apply '~' to a bit-field
C2135.cpp(15): error C2135: 'bit_field': you cannot apply '*' to a bit-field

Changes to "Remarks"

  • Add 5 more operators that could emit C2135 (from my testing, there doesn't seem to be any other, but I could have missed some)
  • Add important "in this context", since the compiler either emits some other error (e.g. C2104 for S s{}; &s.bit_field;) or said operator is valid in other contexts

Changes to "Example"

  • Merge T into S for a terser example
  • Remove "address of a bit field" comment as it's a bit more nuanced than that (trying to take the address of a bit-field data member on an instance emits C2104 instead of C2135)
  • Use slightly more descriptive identifiers for clarity

Other changes

  • Update the outdated error message
  • Add C2104 "See also" link and update ms.date metadata

Copy link
Contributor

@Rageking8 : Thanks for your contribution! The author(s) and reviewer(s) have been notified to review your proposed change.

Copy link
Contributor

Learn Build status updates of commit 797e67b:

✅ Validation status: passed

File Status Preview URL Details
docs/error-messages/compiler-errors-1/compiler-error-c2135.md ✅Succeeded

For more details, please refer to the build report.

Copy link
Contributor

PRMerger Results

Issue Description
File Change Percent This PR contains file(s) with more than 30% file change.

@v-regandowner
Copy link
Contributor

@TylerMSFT - Can you review the proposed changes?

IMPORTANT: When the changes are ready for publication, adding a #sign-off comment is the best way to signal that the PR is ready for the review team to merge.

#label:"aq-pr-triaged"
@MicrosoftDocs/public-repo-pr-review-team

@prmerger-automator prmerger-automator bot added the aq-pr-triaged Tracking label for the PR review team label Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants