Main Content

AUTOSAR C++14 Rule A2-8-2

An implementation file name should reflect the logical entity for which it provides definitions.

Since R2021a

Description

Rule Definition

An implementation file name should reflect the logical entity for which it provides definitions.

Rationale

An implementation file name that matches the name of the entity that is defined in that file makes your project structure clearer and your code more readable.

Polyspace Implementation

Polyspace® checks the implementation file name against the name of relevant defined types such as class or struct, or namespace names. If the names do not match, Polyspace flags the first character on the first line of the implementation file.

  • The name comparison is case insensitive. For instance, myclass matches myClass.

  • The name comparison ignores:

    • The underscore character '_'. For instance, myclass matches my_Class.

    • Prefix characters 'C', 'M', 'T', or suffix character 'T'. The comparison ignores either the prefix or suffix characters, but not both. For instance, myclass matches CmyClass and myClass_T, but not CmyClass_T.

    • The hyphen character '-' in file names. For instance, a file named my-class.cpp matches a class named myClass_.

Polyspace does not check the file where you implement main().

Troubleshooting

If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.

Examples

expand all

username.h

#include <string>

class User
{
public:
	User();
    User(std::string s);
    std::string getUser();

private:
    std::string user;
};

username.cpp

#include "username.h" // Non-compliant

User::User() : user("") { }
User::User(std::string s): user(s) {}
std::string User::getUser()
{
	return user;
}

In the is example, the name of implementation file username.cpp is not compliant because it does not match the name of the class (User) defined in that file.

Check Information

Group: Lexical conventions
Category: Advisory, Non-automated

Version History

Introduced in R2021a