メインコンテンツ

MISRA C++:2023 Rule 5.7.3

Line-splicing shall not be used in // comments.

R2024b 以降

説明

ルール定義

Line-splicing shall not be used in // comments. 1

根拠

コードの単一行コメントの最後が文字 \ の場合は、次の行にコメントが続いていると解釈されます。文字 \ で終わる単一行コメントは、コードのセクションを誤ってコメントアウトする可能性があります。

Polyspace 実装

Polyspace は、C++ スタイルのコメントの最後が文字 \ でないかどうかをチェックします。

トラブルシューティング

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

すべて展開する

#include <cstdint>

void foo()
{
  int32_t idx = 0;
  int32_t limit = 20;
  int32_t count = 20;
  ++idx; // Incrementing index before the loop starts// Requirement X\\
  for(;idx<limit;++idx)
  {
     --count;
  }
}

for ループ定義は、単一行コメントが文字 \ で終わっているため、コメントアウトされます。その結果、count は一度しかデクリメントされませんが、これは誤りの可能性があります。チェッカーは、単一行コメント内の文字 \ を強調表示することによって、この問題にフラグを設定します。

チェック情報

グループ: Lexical Conventions
カテゴリ: Required

バージョン履歴

R2024b で導入


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.