isocpp / isocpp/CppCoreGuidelines
SF.2 allow inline variables and static inline class member variables
Nobody has claimed this yet.
- Dominant language
- CSS
- Stars
- 45.3k
- Forks
- 5.6k
- PR merge metrics
- No merged PRs in 30d
Description
SF.2 has a list under "A header file must contain only" that does not include:
static inlineclass member variables (not just functions)inlinevariables not in a class declaration (again, not just functions)
Both are supported since C++17, resulting in all translation units linking the entity to the same memory location, The first point above results in code simplification and allows implementation of header-only classes that would otherwise not be possible. In [https://en.cppreference.com/w/cpp/language/inline](inline specifier - cppreference.com):
An inline function or variable(since C++17) ... has the same address in every translation unit.
For example, if a header includes:
class MyClass
{
public:
static inline int staticInlineMember = 5;
};
inline int inlineVariable = 5;
The memory location of staticInlineMember is always the same, when that header is included in multiple source files. So is the location of inlineVariable.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the SF.2 guideline and reviewing the section listing what a header file may contain, then compare its wording with the C++17 inline-variable rules referenced in the issue. Done means the guideline explicitly addresses both static inline class member variables and non-member inline variables without narrowing the existing guidance.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100