メインコンテンツ

MISRA C++:2008 Rule 2-13-5

Narrow and wide string literals shall not be concatenated.

説明

ルール定義

Narrow and wide string literals shall not be concatenated. 1

根拠

ナロー文字列リテラルは接頭辞を付けずに二重引用符で囲みます。ワイド文字列リテラルは二重引用符で囲んで、その引用符の外側に接頭辞 L を付けます。文字列リテラルを参照してください。

ナロー文字列リテラルとワイド文字列リテラルの連結は未定義の動作を引き起こす可能性があります。

Polyspace 実装

ルール チェッカーはワイド文字列リテラルとナロー文字列リテラルの連結に対して違反を報告します。

トラブルシューティング

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

すべて展開する

char array[] = "Hello" "World";
wchar_t w_array[] = L"Hello" L"World";
wchar_t mixed[] = "Hello" L"World"; //Noncompliant

この例では、配列 mixed の初期化で、ナロー文字列リテラル "Hello" とワイド文字列リテラル L"World" を連結しています。

チェック情報

グループ: 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.