# Using Sonar for C++ naming conventions

**URL:** <https://community.sonarsource.com/t/using-sonar-for-c-naming-conventions/117049>\
**Category:** SonarQube Cloud\
**Tags:** cfamily\
**Created:** [June 11, 2024, 9:46am UTC](https://community.sonarsource.com/t/using-sonar-for-c-naming-conventions/117049 "2024-06-11T09:46:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dbeker](https://avatars.discourse-cdn.com/v4/letter/d/cc9497/32.png) [@dbeker](https://community.sonarsource.com/u/dbeker)\
**Post date:** [June 11, 2024, 9:46am UTC](https://community.sonarsource.com/t/using-sonar-for-c-naming-conventions/117049/1 "2024-06-11T09:46:15Z")

</div>

Template for a good new topic, formatted with [Markdown](https://commonmark.org/help/):

- ALM used (GitHub, Bitbucket Cloud, Azure DevOps)
- CI system used (Bitbucket Cloud, Azure DevOps, Travis CI, Circle CI
- Scanner command used when applicable (private details masked)
- Languages of the repository
- Only if the SonarCloud project is public, the URL
  - And if you need help with pull request decoration, then the URL to the PR too

- Error observed (wrap logs/code around with triple quotes ``` for proper formatting)
- Steps to reproduce
- Potential workaround

Hello,

We are using SonarCloud to analyse C++ code baseline. I’m looking for a solution if sonar ecosystem provides naming convention checking for C++. I’m particularly interested in how we can enable sonar for both CLI and for IDEs to verify correct naming conventions for variables, classes and structs are applied. Do you have any recommendation?

**Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!**

---

<div class="post-metadata">

**Author:** ![aalvarez](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/aalvarez/32/39649_2.png) [@aalvarez](https://community.sonarsource.com/u/aalvarez)\
**Post date:** [June 11, 2024, 1:12pm UTC](https://community.sonarsource.com/t/using-sonar-for-c-naming-conventions/117049/2 "2024-06-11T13:12:49Z")

</div>

Hello, @dbeker, and welcome to the community,

There are rules for naming conventions, although they are disabled by default.  
For instance, [S100](https://rules.sonarsource.com/cpp/tag/convention/RSPEC-100/) for functions, and [there are others](https://rules.sonarsource.com/cpp/tag/convention/?search=naming).

In SonarCloud, you must create a new Quality Profile for your organization (if you do not have one already).

1. Go to your organization page (`https://sonarcloud.io/organizations/...`)
2. Click on “Quality Profiles”
3. Search for C++; there should be two built-in. You can pick any of the two as a base profile (I would advise Sonar Way by default).
4. Click the three dots to the right and then “Extend.”
5. Give it a new name
6. Click on “Inactive rules.”
7. Search for, say, S100, click on “Activate,” and provide a regex used to verify the naming convention

Once this is done, you can either set this new profile as the organization’s default or go to the affected projects and apply the new profile.

SonarLint will pick these changes [if you use connected mode](https://docs.sonarsource.com/sonarlint/intellij/team-features/connected-mode/).

Please let me know if this helps.

Also, the changes take effect on new analyses, so you will not immediately see any issue raised in SC after activating the rules.

---

<div class="post-metadata">

**Author:** ![dbeker](https://avatars.discourse-cdn.com/v4/letter/d/cc9497/32.png) [@dbeker](https://community.sonarsource.com/u/dbeker)\
**Post date:** [June 12, 2024, 8:41am UTC](https://community.sonarsource.com/t/using-sonar-for-c-naming-conventions/117049/4 "2024-06-12T08:41:28Z")

</div>

Thank you Alejandro.

Following it up, would it be possible to extend those naming conventions? For example, would it be possible to separate private and public member variables? How can we define our own custom rule set for naming conventions if it doesn’t exist in the second link you shared?

---

<div class="post-metadata">

**Author:** ![aalvarez](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/aalvarez/32/39649_2.png) [@aalvarez](https://community.sonarsource.com/u/aalvarez)\
**Post date:** [June 12, 2024, 9:10am UTC](https://community.sonarsource.com/t/using-sonar-for-c-naming-conventions/117049/5 "2024-06-12T09:10:35Z")

</div>

Defining your own CFamily rules is not possible, [but you can import reports generated by other tools](https://docs.sonarsource.com/sonarcloud/enriching/generic-issue-data/), so you could conceivably roll out something based on clang’s json dump of the AST (which is not necessarily stable between releases, though).

What rules do you have in mind, apart of differentiating between public/protected/private member variables?

---

<div class="post-metadata">

**Author:** ![claudg2\_mdt](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/claudg2_mdt/32/60635_2.png) [@claudg2\_mdt](https://community.sonarsource.com/u/claudg2_mdt)\
**Post date:** [August 16, 2024, 3:13pm UTC](https://community.sonarsource.com/t/using-sonar-for-c-naming-conventions/117049/7 "2024-08-16T15:13:40Z")

</div>

Hi Alejandro,

Thank you for your response. We need the same rules that you can enforce with clang-tidy. You can find the rules at [https://clang.llvm.org/extra/clang-tidy/checks/readability/identifier-naming.html](https://clang.llvm.org/extra/clang-tidy/checks/readability/identifier-naming.html).

Is there any possibility that this will be included in your roadmap soon?

Thanks for your assistance!

---

<div class="post-metadata">

**Author:** ![claudg2\_mdt](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/claudg2_mdt/32/60635_2.png) [@claudg2\_mdt](https://community.sonarsource.com/u/claudg2_mdt)\
**Post date:** [September 18, 2024, 9:41am UTC](https://community.sonarsource.com/t/using-sonar-for-c-naming-conventions/117049/9 "2024-09-18T09:41:09Z")

</div>

Hi @aalvarez.

Do you have any updates regarding the naming conventions?

Many thanks!

---

<div class="post-metadata">

**Author:** ![aalvarez](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/aalvarez/32/39649_2.png) [@aalvarez](https://community.sonarsource.com/u/aalvarez)\
**Post date:** [September 24, 2024, 8:59am UTC](https://community.sonarsource.com/t/using-sonar-for-c-naming-conventions/117049/10 "2024-09-24T08:59:16Z")

</div>

Hello @claudg2_mdt ,

Unfortunately, there is nothing on the roadmap in this respect. I have forwarded this thread to our PM, though, so we note the interest in a feature like this.

---

<div class="post-metadata">

**Author:** ![Geoffray](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/geoffray/32/2966_2.png) [@Geoffray](https://community.sonarsource.com/u/Geoffray)\
**Post date:** [September 27, 2024, 9:36am UTC](https://community.sonarsource.com/t/using-sonar-for-c-naming-conventions/117049/11 "2024-09-27T09:36:52Z")

</div>

Hi @claudg2_mdt ,

Thanks for reaching out.  
I can see the clang-tidy check is indeed more refined and configurable than what we offer.  
Please, would you be able to elaborate on what you need specifically that is not covered by t[he rules that @aalvarez mentioned](https://community.sonarsource.com/t/using-sonar-for-c-naming-conventions/117049/2)?

Thank you very much
