メインコンテンツ

MISRA C++:2008 Rule 3-9-1

The types used for an object, a function return type, or a function parameter shall be token-for-token identical in all declarations and re-declarations.

説明

ルール定義

The types used for an object, a function return type, or a function parameter shall be token-for-token identical in all declarations and re-declarations. 1

根拠

再宣言が前の宣言とトークン単位で同一でない場合、再宣言されているオブジェクトまたは関数が目視検査では不明確になります。

Polyspace 実装

ルール チェッカーは、現在の宣言とその前に確認された宣言を比較します。

レポート内の追加のメッセージ

The types used for an object, a function return type, or a function parameter shall be token-for-token identical in all declarations and re-declarations.

変数 varName には前の宣言との互換性がありません。

トラブルシューティング

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

すべて展開する

typedef int* intptr;

int* map;
extern intptr map; //Noncompliant

intptr table;
extern intptr table; //Compliant

この例では、変数 map が 2 回宣言されています。2 番目の宣言では、最初の宣言の型に解決される typedef が使用されています。typedef が原因で、2 番目の宣言は最初の宣言とトークン単位で同一ではありません。

チェック情報

グループ: Basic Concepts
カテゴリ: 必要

バージョン履歴

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.