メインコンテンツ

MISRA C++:2008 Rule 2-10-6

If an identifier refers to a type, it shall not also refer to an object or a function in the same scope.

説明

ルール定義

If an identifier refers to a type, it shall not also refer to an object or a function in the same scope. 1

根拠

C コードとの互換性を維持するために、C++ 標準では、型とオブジェクトまたは関数に同じ名前を使用することができます。しかし、名前を再利用すると開発中やコード レビュー中に混乱を招く可能性があります。

Polyspace 実装

Polyspace® は、識別子が型名と関数名またはオブジェクト名の両方として使用された場合に、このルールの違反を報告します。識別子が関数名で、その関数の宣言と定義の両方が行われている場合は、一度だけ違反が報告されます。

トラブルシューティング

ルール違反が想定されるものの、Polyspace から報告されない場合は、コーディング規約違反が想定どおりに表示されない理由の診断を参照してください。

すべて展開する

struct vector{
    int x;
    int y;
    int z;
}vector; //Noncompliant

この例では、名前 vector を構造体データ型とその型のオブジェクトの両方に使用しています。

チェック情報

グループ: Lexical Conventions
カテゴリ: 必要

バージョン履歴

R2013b で導入


1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.

The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:

  • MISRA C:2004

  • MISRA C:2012

  • MISRA C:2023

  • MISRA C++:2008

  • MISRA C++:2023

MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.