testdino-hq/google-styleguides-skills · Archived

cpp

Google's official C++ style guide. Covers headers, naming conventions, formatting, classes, memory management, RAII, smart pointers, and modern C++ features.

First seen Apr 7, 2026

Installation

$ npx skills add testdino-hq/google-styleguides-skills --skill cpp

Stronger alternatives

This repository is archived — consider an actively maintained alternative.

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from testdino-hq/google-styleguides-skills · top by installs.

npx skills add testdino-hq/google-styleguides-skills

Browse all from testdino-hq/google-styleguides-skills

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Repository health

Stars 9
License LICENSE
Default branch main
Open issues 0
Status Archived

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 3,919 B
  • docs SUMMARY.md 168 B

History

  1. First seen on skills.sh
  2. First recorded snapshot · 10 installs

SKILL.md

Google C++ Style Guide

Official Google C++ coding standards for consistent, maintainable code.

Golden Rules

  1. Target C++20 — avoid non-standard extensions
  2. 80-character line limit — for readability
  3. 2-space indentation — no tabs
  4. Use const liberally — for correctness and thread safety
  5. Avoid exceptions — Google code doesn't use C++ exceptions
  6. Smart pointers for ownership — std::uniqueptr and std::sharedptr
  7. Header guards — use PROJECTPATHFILEH format

Quick Reference

Naming Conventions

Element Convention Example
Files snake_case urltable.cc, urltable.h
Classes/Structs UpperCamelCase UserService
Functions UpperCamelCase GetUserById
Variables snake_case user_count
Constants kUpperCamelCase kMaxRetries
Class members snakecase username (trailing _)
Macros UPPERSNAKECASE MAXBUFFERSIZE

Headers

// ✓ CORRECT - self-contained header with guard
#ifndef FOO_BAR_BAZ_H_
#define FOO_BAR_BAZ_H_

#include <string>
#include "base/basictypes.h"

class Baz {
 public:
  void DoSomething();
};

#endif  // FOO_BAR_BAZ_H_

Include order: related header → C system → C++ stdlib → other libs → your headers.

Classes

// ✓ CORRECT
class MyClass {
 public:
  explicit MyClass(int value);  // explicit for single-arg ctors
  ~MyClass();

  void DoSomething();
  int GetValue() const { return value_; }

 private:
  int value_;
  std::string name_;
};

Smart Pointers

// ✓ CORRECT - unique_ptr for exclusive ownership
std::unique_ptr<Foo> FooFactory();
void FooConsumer(std::unique_ptr<Foo> ptr);

// ✓ CORRECT - shared_ptr for shared ownership
std::shared_ptr<const Foo> immutable_foo;

// ✗ INCORRECT - avoid raw new/delete
Foo* foo = new Foo();  // avoid
delete foo;            // avoid

Modern C++ Features

// ✓ CORRECT - use auto for complex types
auto it = my_map.find(key);
auto widget = std::make_unique<Widget>(arg1, arg2);

// ✓ CORRECT - range-based for loops
for (const auto& item : container) {
  Process(item);
}

// ✓ CORRECT - nullptr, not NULL
Foo* ptr = nullptr;

// ✓ CORRECT - constexpr for compile-time constants
constexpr int kArraySize = 100;

Functions

// ✓ CORRECT - return type on same line
ReturnType ClassName::FunctionName(Type par_name1, Type par_name2) {
  DoSomething();
  return result;
}

// ✓ CORRECT - wrap long parameter lists (4-space indent)
ReturnType LongClassName::ReallyLongFunctionName(
    Type par_name1,
    Type par_name2,
    Type par_name3) {
  DoSomething();
}

Formatting

// ✓ CORRECT - braces and spacing
if (condition) {
  DoSomething();
} else {
  DoSomethingElse();
}

// ✓ CORRECT - pointer/reference alignment (attached to type)
char* c;
const std::string& str;

Common Mistakes

Mistake Correct Approach
Using exceptions Use error codes or absl::Status
Bare new/delete Use smart pointers (unique_ptr)
NULL or 0 for null Use nullptr
C-style casts Use C++ casts (static_cast, etc.)
using namespace std Never in headers; avoid in .cc
Mutable global variables Use singletons or dependency injection
Missing explicit Mark single-arg constructors explicit

When to Use This Guide

  • Writing new C++ code
  • Refactoring existing C++
  • Code reviews
  • Setting up clang-format rules
  • Onboarding new team members

Install

npx skills add testdino-hq/google-styleguides-skills/cpp

Full Guide

See [cpp.md](cpp.md) for complete details, examples, and edge cases.