JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C and C++


LANG.TYPE.IMPSC : Implicit Encoding in String Concatenation

Summary

Some, but not all, of the string literals in a concatenation operation have implicit encoding.

This can make the operation harder for human readers to understand.

See also Mixed Encodings in String Concatenation.

Properties

Class Name Implicit Encoding in String Concatenation
Significance style
Mnemonic LANG.TYPE.IMPSC
Categories
MisraC++2008 MisraC++2008:2-13-5 Narrow and wide string literals shall not be concatenated.
MisraC++2023 MisraC++2023:5.13.7 Strings with different encoding prefixes shall not be concatenated
CERT-C CERT-C:STR10-C Do not concatenate different type of string literals
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default. To enable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += allow class="Implicit Encoding in String Concatenation"

Example

#include <string>
using namespace std::string_literals;

const wchar_t * bad1 =   "Hello" L"World";  // 'Implicit Encoding in String Concatenation' warning issued here
const wchar_t * bad2 =  L"Hello"  "World";  // 'Implicit Encoding in String Concatenation' warning issued here

const char * good1 =  "Hello" "World";                   // ok: no explicit encoding
const wchar_t * good2 =  L"Hello" L"World";              // ok: same explicit encoding

// User-defined suffixes do not denote an encoding.
std::string     good3 =  "abc"  "def"s;                  // ok: no explicit encoding
std::wstring    good4 = L"abc" L"def"s;                  // ok: same explicit encoding
std::wstring bad3 = "Hello"s L"World"s;     // 'Implicit Encoding in String Concatenation' warning issued here

// The R prefix denotes a raw string, not an encoding.
const char *    good5 =  "abc" R"(def)";                // ok: no explicit encoding
const wchar_t * good6 = L"abc" LR"(def)";               // ok: same explicit encoding
const wchar_t * bad4 = "Hello" LR"(World)"; // 'Implicit Encoding in String Concatenation' warning issued here

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.

 

To report problems with this documentation, please visit https://support.codesecure.com/.