AutosarC++17_03-A13.1.1ΒΆ
User-defined literals shall not be used
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
Rationale
User-defined literals permits only following types for parameter lists:
- const char*
- unsigned long long int
- long double
- char
- wchar_t
- char16_t
- char32_t
- const char*, std::size_t
- const wchar_t*, std::size_t
- const char16_t*, std::size_t
- const char32_t*, std::size_t
A programmer has limited control on the types of parameters passed to user-definedconversion operators. Also, it is implementation-defined whether fixed-size types from<cstdint> header are compatible with the types allowed by user-defined literals.
Note that user-defined literals are not widespread in C++ Standard Library. They areused to convert literals to objects of type std::chrono::duration (i.e. h, min, s, ms, us,ns), std::complex and basic_string.
Example
// $Id: A13-1-1.cpp 271687 2017-03-23 08:57:35Z piotr.tanski $
#include <cstdint>
constexpr unsigned long long int
operator"" _ft(unsigned long long int feet) // Non-compliant
{
// Implementation
return feet;
}
constexpr std::uint64_t operator"" _m(std::uint64_t meters) // Non-compliant
{
// Implementation
return meters;
}
void fn() noexcept {
unsigned long long int feets = 200_ft;
// std::uint64_t meters = 300_m; // Compilation error - uint64_t has
// invalid
// type, not compatible with user-defined literals. On 64-bit machines,
// uint64_t is defined as unsigned long, and not unsigned long long
}
See Also
- none
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
user_defined_literal |
User-defined literals shall not be used. |
None |
False |
Options
This rule shares the following common options: confidence, exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
This rule has no individual options.