mirror of
https://github.com/QuantumLeaps/qpcpp.git
synced 2025-02-04 06:13:00 +08:00
636 lines
25 KiB
Plaintext
636 lines
25 KiB
Plaintext
// ---------------------------------------------------------------------------
|
|
// Copyright Gimpel Software LLC 2019. All rights reserved.
|
|
//
|
|
// This file is provided by Gimpel Software LLC (https://www.gimpel.com) for
|
|
// use with PC-lint Plus. Redistribution is permitted but any redistribution
|
|
// must preserve this notice and, if the redistributed file has been modified,
|
|
// provide notice that the file has been modified from the original.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// au-ql-cpp11.lnt -- Author options - QL-C++11:2022
|
|
//
|
|
// This options file contains options to help enforce the checks advocated
|
|
// by the Quantum Leaps Embedded C/C++ Coding Style (QL-C/C++:2022):
|
|
// https://github.com/QuantumLeaps/embedded-coding-style
|
|
|
|
// ========== GENERAL RULES ==========
|
|
|
|
// 1.1 Which C++?
|
|
|
|
/* Enable C++11 mode */
|
|
-std=c++11
|
|
|
|
/* 975 - unknown pragma will be ignored */
|
|
+e975
|
|
-append(975,[BARR-C:2018 Rule 1.1c])
|
|
|
|
/* 9051 - macro defined with the same name as a C keyword */
|
|
+e9051
|
|
-append(9051,[BARR-C:2018 Rule 1.1d])
|
|
|
|
// 1.2 Line Widths
|
|
|
|
/* not currently supported */
|
|
|
|
// 1.3 Braces
|
|
|
|
/* 9012 - body should be a compound statement */
|
|
+e9012
|
|
-append(9012,[BARR-C:2018 Rule 1.3a])
|
|
|
|
// 1.4 Parentheses
|
|
|
|
/* 9050 - dependence placed on precedence */
|
|
+e9050
|
|
-append(9050,[BARR-C:2018 Rule 1.4a])
|
|
|
|
/* 9097 - unparenthesized argument to sizeof */
|
|
+e9097
|
|
-append(9097,[BARR-C:2018 Rule 1.4a])
|
|
|
|
/* 821 - right hand side of assignment not parenthesized */
|
|
+e821
|
|
-append(821,[BARR-C:2018 Rule 1.4a])
|
|
|
|
/* 834 - operator op1 followed by operator op2 could be confusing */
|
|
+e834
|
|
-append(834,[BARR-C:2018 Rule 1.4a])
|
|
|
|
/* 9240 - left/right side of logical operator is not a primary expression */
|
|
+e9240
|
|
-append(9240,[BARR-C:2018 Rule 1.4b])
|
|
|
|
// 1.5 Common Abbreviations
|
|
|
|
/* not currently supported */
|
|
|
|
// 1.6 Casts
|
|
|
|
/* not currently supported */
|
|
|
|
// 1.7 Keywords to Avoid
|
|
|
|
/* 586 - keyword is deprecated */
|
|
-deprecate(keyword, auto,[BARR-C:2018 Rule 1.7a])
|
|
-deprecate(keyword, register,[BARR-C:2018 Rule 1.7b])
|
|
-deprecate(keyword, continue,[BARR-C:2018 Rule 1.7d])
|
|
|
|
/* 801 - goto statement used */
|
|
+e801
|
|
-append(801,[BARR-C:2018 Rule 1.7c])
|
|
|
|
/* 9041 - goto appears in block which is not nested in block containing label */
|
|
+e9041
|
|
-append(9041,[BARR-C:2018 Rule 1.7c])
|
|
|
|
/* 9064 - goto references earlier label */
|
|
+e9064
|
|
-append(9064,[BARR-C:2018 Rule 1.7c])
|
|
|
|
// 1.8 Keywords to Frequent
|
|
|
|
/* 765 - external symbol could be made static */
|
|
+e765
|
|
-append(765,[BARR-C:2018 Rule 1.8a])
|
|
|
|
/* 818 - parameter of function could be pointer to const */
|
|
//QL +e818
|
|
//QL -append(818,[BARR-C:2018 Rule 1.8b])
|
|
|
|
/* 843 - static storage duration variable could be made const */
|
|
+e843
|
|
-append(843,[BARR-C:2018 Rule 1.8b])
|
|
|
|
/* 844 - static storage duration variable could be made pointer to const */
|
|
+e844
|
|
-append(844,[BARR-C:2018 Rule 1.8b])
|
|
|
|
/* 952 - parameter of function could be const */
|
|
//QL +e952
|
|
//QL -append(952,[BARR-C:2018 Rule 1.8b])
|
|
|
|
/* 953 - local variable could be const */
|
|
+e953
|
|
-append(953,[BARR-C:2018 Rule 1.8b])
|
|
|
|
/* 954 - local variable could be pointer to const */
|
|
+e954
|
|
-append(954,[BARR-C:2018 Rule 1.8b])
|
|
|
|
/* 2765 - reference to variable which is neither atomic nor volatile sig_atomic_t within signal handler */
|
|
+e2765
|
|
-append(2765,[BARR-C:2018 Rule 1.8c])
|
|
|
|
// ========== COMMENTS ==========
|
|
|
|
// 2.1 Acceptable Formats
|
|
|
|
/* 427 - C++ comment continued via back-slash */
|
|
+e427
|
|
-append(427,[BARR-C:2018 Rule 2.1b])
|
|
|
|
/* 602 - nested block comment */
|
|
+e602
|
|
-append(602,[BARR-C:2018 Rule 2.1b])
|
|
|
|
/* 9059 - C comment contains C++ comment */
|
|
+e9059
|
|
-append(9059,[BARR-C:2018 Rule 2.1b])
|
|
|
|
// 9259 - C comment contains '://' sequence
|
|
+e9259
|
|
-append(9259,[BARR-C:2018 Rule 2.1b])
|
|
|
|
/* 9066 - C++ comment contains C comment */
|
|
+e9066
|
|
-append(9066,[BARR-C:2018 Rule 2.1b])
|
|
|
|
// 2.2 Locations and Comments
|
|
|
|
/* not statically checkable */
|
|
|
|
// ========== WHITE SPACE RULES ==========
|
|
|
|
// 3.1 Spaces
|
|
|
|
/* not currently supported */
|
|
|
|
// 3.2 Alignment
|
|
|
|
/* not currently supported */
|
|
|
|
// 3.3 Black Lines
|
|
|
|
/* 783 - line does not end with a newline */
|
|
+e783
|
|
-append(783,[BARR-C:2018 Rule 3.3c])
|
|
|
|
// 3.4 Indentation
|
|
|
|
/* 525 - unexpected negative indentation */
|
|
+e525
|
|
-append(525,[BARR-C:2018 Rule 3.4a])
|
|
|
|
/* 539 - unexpected positive indentation */
|
|
+e539
|
|
-append(539,[BARR-C:2018 Rule 3.4a])
|
|
|
|
/* 725 - unexpected lack of indentation */
|
|
+e725
|
|
-append(725,[BARR-C:2018 Rule 3.4a])
|
|
|
|
// 3.5 Tabs
|
|
|
|
/* not currently supported */
|
|
|
|
// 3.6 Non-Printing Characters
|
|
|
|
/* not currently supported */
|
|
|
|
// ========== MODULE RULES ==========
|
|
|
|
// 4.1 Naming Conventions
|
|
|
|
/* 8516 - module name should contain only lowercase letters, numbers, and underscores */
|
|
-hook(module_open, -cond(!('%[file_name]' ~ '^[[:lower:][:digit:]_./\\\\]+$'),
|
|
+message(8516, "module '%[file_name]' should contain only lowercase letters, numbers, and underscores")))
|
|
+e8516
|
|
-append(8516,[BARR-C:2018 Rule 4.1a])
|
|
|
|
/* 8517 - module does not end with '.cpp' */
|
|
-hook(module_open, -cond(!('%[file_name]' ~ '[.]cpp$'),
|
|
+message(8517, "module '%[file_name]' should have '.cpp' extension")))
|
|
+e8517
|
|
-append(8517,[BARR-C:2018 Rule 4.1b])
|
|
|
|
/* 8518 - header does not end with '.hpp' */
|
|
-hook(header_open, -cond(!('%[file_name]' ~ '[.]hpp$'),
|
|
+message(8517, "header '%[file_name]' should have '.hpp' extension")))
|
|
+e8518
|
|
-append(8518,[BARR-C:2018 Rule 4.1b])
|
|
|
|
/* 8519 - 'main' function defined in file that does not contain the word 'main' */
|
|
-hook(func_decl, -cond('%[qual_name]' == 'main' && %[is_definition] && !('%[file]' ~ 'main'),
|
|
+message(8519, "main function defined in file '%[file]' which does not have the word 'main' in its name")))
|
|
+e8519
|
|
-append(8519,[BARR-C:2018 Rule 4.1d])
|
|
|
|
// 4.2 Header Files
|
|
|
|
/* 451 - header file repeatedly included but has no header guard */
|
|
+e451
|
|
-append(451,[BARR-C:2018 Rule 4.2b])
|
|
|
|
/* 967 - header file does not have a standard include guard */
|
|
+e967
|
|
-append(967,[BARR-C:2018 Rule 4.2b])
|
|
|
|
/* 9107 - header cannot be included in more than one translation unit because of the definition of symbol */
|
|
+e9107
|
|
-append(9107,[BARR-C:2018 Rule 4.2c])
|
|
|
|
/* 755 - global macro not referenced */
|
|
+e755
|
|
-append(755,[BARR-C:2018 Rule 4.2c])
|
|
|
|
/* 756 - global typedef not referenced */
|
|
+e756
|
|
-append(756,[BARR-C:2018 Rule 4.2c])
|
|
|
|
/* 757 - global declarator not referenced */
|
|
+e757
|
|
-append(757,[BARR-C:2018 Rule 4.2c])
|
|
|
|
/* 758 - global tag not referenced */
|
|
+e758
|
|
-append(758,[BARR-C:2018 Rule 4.2c])
|
|
|
|
/* 759 - header declaration for symbol could be moved from header to module */
|
|
+e759
|
|
-append(759,[BARR-C:2018 Rule 4.2c])
|
|
|
|
/* 768 - global field not referenced */
|
|
+e768
|
|
-append(768,[BARR-C:2018 Rule 4.2c])
|
|
|
|
/* 769 - global enumeration constant not referenced */
|
|
+e769
|
|
-append(769,[BARR-C:2018 Rule 4.2c])
|
|
|
|
// 4.3 Source Files
|
|
|
|
/* 9019 - declaration of symbol before #include */
|
|
-append(9019,[BARR-C:2018 Rule 4.3b])
|
|
|
|
/* 8520 - #include used with absolute path */
|
|
-hook(header_open, -cond('%[file_name]' ~ '^([[:alpha:]]:)?[/\\\\]',
|
|
+message(8520, "#include directive uses absolute path to include file '%[file_name]'")))
|
|
+e8520
|
|
-append(8520,[BARR-C:2018 Rule 4.3d])
|
|
|
|
/* 8521 - #include used to include module file */
|
|
-hook(header_open, -cond('%[file_name]' ~ '[.]c$',
|
|
+message(8521, "#include directive used to include module file '%[file_name]'")))
|
|
+e8521
|
|
-append(8521,[BARR-C:2018 Rule 4.3f])
|
|
|
|
// 4.4 File Templates
|
|
|
|
/* not statically checkable */
|
|
|
|
// ========== DATA TYPE RULES ==========
|
|
|
|
// 5.1 Naming Conventions
|
|
|
|
/* 8526 - typedef name should consist of lowercase letters and underscores */
|
|
//QL -hook(typename_decl, -cond(!('%[name]' ~ '^[[:lower:]_]*$'),
|
|
//QL +message(8526, "typedef name '%[name]' should consist of lowercase letters and underscores")))
|
|
//QL +e8526
|
|
//QL -append(8526,[BARR-C:2018 Rule 5.1a])
|
|
|
|
/* 8527 - typedef name should end with '_t' suffix */
|
|
//QL -hook(typename_decl, -cond(!('%[name]' ~ '_t$'),
|
|
//QL +message(8527, "typedef name '%[name]' should end with '_t' suffix")))
|
|
//QL +e8527
|
|
//QL -append(8527,[BARR-C:2018 Rule 5.1a])
|
|
|
|
/* 8528 - non-anonymous struct/union/enum declared outside of typedef */
|
|
//QL -hook(record_decl, -cond(%[is_freestanding] && !%[is_anonymous],
|
|
//QL +message(8528, "non-anonymous struct/union declared outside of a typedef")))
|
|
//QL -hook(enum_decl, -cond(%[is_freestanding] && '%[name]' != '',
|
|
//QL +message(8528, "non-anonymous enum declared outside of a typedef")))
|
|
//QL +e8528
|
|
//QL -append(8528,[BARR-C:2018 Rule 5.1b])
|
|
|
|
// 5.2 Fixed-Width Integers
|
|
|
|
/* 586 - keyword/type is deprecated */
|
|
+e586
|
|
|
|
-deprecate(type,signed char,[BARR-C:2018 Rule 5.2a])
|
|
-deprecate(type,unsigned char,[BARR-C:2018 Rule 5.2a])
|
|
-deprecate(type,signed short,[BARR-C:2018 Rule 5.2a])
|
|
-deprecate(type,unsigned short,[BARR-C:2018 Rule 5.2a])
|
|
-deprecate(type,signed int,[BARR-C:2018 Rule 5.2a])
|
|
-deprecate(type,unsigned int,[BARR-C:2018 Rule 5.2a])
|
|
-deprecate(type,signed long,[BARR-C:2018 Rule 5.2a])
|
|
-deprecate(type,unsigned long,[BARR-C:2018 Rule 5.2a])
|
|
-deprecate(type,signed long long,[BARR-C:2018 Rule 5.2a])
|
|
-deprecate(type,unsigned long long,[BARR-C:2018 Rule 5.2a])
|
|
|
|
-deprecate(keyword, short,[BARR-C:2018 Rule 5.2b])
|
|
-deprecate(keyword, long,[BARR-C:2018 Rule 5.2b])
|
|
|
|
/* 9209 - plain character data used with prohibited operator */
|
|
//QL +e9209
|
|
//QL -append(9209,[BARR-C:2018 Rule 5.2c])
|
|
|
|
// 5.3 Signed and Unsigned Integers
|
|
|
|
/* 9420 - bitfield does not have unsigned type */
|
|
+e9420
|
|
-append(9420,[BARR-C:2018 Rule 5.3a])
|
|
|
|
/* 9130 - bitwise operator applied to signed underlying type */
|
|
+e9130
|
|
-append(9130,[BARR-C:2018 Rule 5.3b])
|
|
|
|
/* 570 - negative value loses sign during implicit conversion */
|
|
+e570
|
|
-append(570,[BARR-C:2018 Rule 5.3c])
|
|
|
|
/* 713 - implicit conversion from unsigned to signed may lose precision */
|
|
+e713
|
|
-append(713,[BARR-C:2018 Rule 5.3c])
|
|
|
|
/* 8524 - combining signed and unsigned types with operator op1 */
|
|
-hook(binary_expr, -cond(%[walk_lhs_expr{false}.walk_type.is_integer] &&
|
|
%[walk_rhs_expr{false}.walk_type.is_integer] &&
|
|
!%[walk_lhs_expr.walk_past_paren_imp.walk_type.is_enumeral] &&
|
|
!%[walk_rhs_expr.walk_past_paren_imp.walk_type.is_enumeral] &&
|
|
!%[walk_lhs_expr.walk_past_paren_imp.walk_type.is_boolean] &&
|
|
!%[walk_rhs_expr.walk_past_paren_imp.walk_type.is_boolean] &&
|
|
'%[walk_lhs_expr.walk_past_paren_imp.walk_type.is_unsigned_int_enum]' !=
|
|
'%[walk_rhs_expr.walk_past_paren_imp.walk_type.is_unsigned_int_enum]',
|
|
+message(8524, "combining signed and unsigned types with operator '%[opcode]'")))
|
|
+e8524
|
|
-append(8524,[BARR-C:2018 Rule 5.3c])
|
|
|
|
// 5.4 Floating Point
|
|
|
|
/* 586 - type is deprecated */
|
|
-deprecate(type,float,[BARR-C:2018 Rule 5.4b])
|
|
-deprecate(type,double,[BARR-C:2018 Rule 5.4b])
|
|
-deprecate(type,long double,[BARR-C:2018 Rule 5.4b])
|
|
|
|
/* 777 - testing floating point values for equality */
|
|
+e777
|
|
-append(777,[BARR-C:2018 Rule 5.4b])
|
|
|
|
/* 9252 - testing floating point for equality using exact value */
|
|
+e9252
|
|
-append(9252,[BARR-C:2018 Rule 5.4b])
|
|
|
|
// 5.5 Structures and Unions
|
|
|
|
/* not currently supported */
|
|
|
|
// 5.6 Booleans
|
|
|
|
/* 8523 - cast to boolean */
|
|
-hook(cast_expr, -cond(%[is_cstyle_cast] && %[walk_type.is_boolean],
|
|
+message(8523, "cast to boolean")))
|
|
+e8523
|
|
-append(8523,[BARR-C:2018 Rule 5.6b])
|
|
|
|
// ========== PROCEDURE RULES ==========
|
|
|
|
// 6.1 Naming Conventions
|
|
|
|
/* 8501 - function has name that matches a keyword in C or C++ */
|
|
-hook(func_decl, -cond('%[name]' ~ '^(?P<keyword>alignas|alignof|and|and_eq|asm|auto|bitand|bitor|bool|break|case|catch|char|char8_t|char16_t|char32_t|class|compl|concept|const|consteval|constexpr|const_cast|continue|co_await|co_return|co_yield|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|false|float|for|friend|goto|if|inline|int|long|mutable|namespace|new|noexcept|not|not_eq|nullptr|operator|or|or_eq|private|protected|public|register|reinterpret_cast|requires|restrict|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|true|try|typedef|typeid|typename|union|unsigned|using|virtual|void|volatile|wchar_t|while|xor|xor_eq|_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local)$', +message(8501, "function '%[name]' matches the name of a C/C++ keyword")))
|
|
+e8501
|
|
-append(8501,[BARR-C:2018 Rule 6.1a])
|
|
|
|
/* 8502 - function has same name as standard library function */
|
|
/*QL
|
|
-hook(func_decl, -cond('%[name]' ~ '^(?:abort|abs|acos|acosf|acosh|acoshf|acoshl|acosl|asctime|asin|asinf|asinh|asinhf|asinhl|asinl|assert|atan|atan2|atan2f|atan2l|atanf|atanh|atanhf|atanhl|atanl|atexit|atof|atoi|atol|atoll|bsearch|btowc|cabs|cabsf|cabsl|cacos|cacosf|cacosh|cacoshf|cacoshl|cacosl|calloc|carg|cargf|cargl|casin|casinf|casinh|casinhf|casinhl|casinl|catan|catanf|catanh|catanhf|catanhl|catanl|cbrt|cbrtf|cbrtl|ccos|ccosf|ccosh|ccoshf|ccoshl|ccosl|ceil|ceilf|ceill|cexp|cexpf|cexpl|cimag|cimagf|cimagl|clearerr|clock|clog|clogf|clogl|conj|conjf|conjl|copysign|copysignf|copysignl|cos|cosf|cosh|coshf|coshl|cosl|cpow|cpowf|cpowl|cproj|cprojf|cprojl|creal|crealf|creall|csin|csinf|csinh|csinhf|csinhl|csinl|csqrt|csqrtf|csqrtl|ctan|ctanf|ctanh|ctanhf|ctanhl|ctanl|ctime|difftime|div|erf|erfc|erfcf|erfcl|erff|erfl|exit|_Exit|exp|exp2|exp2f|exp2l|expf|expl|expm1|expm1f|expm1l|fabs|fabsf|fabsl|fclose|fdim|fdimf|fdiml|feclearexcept|fegetenv|fegetexceptflag|fegetround|feholdexcept|feof|feraiseexcept|ferror|fesetenv|fesetexceptflag|fesetround|fetestexcept|feupdateenv|fflush|fgetc|fgetpos|fgets|fgetwc|fgetws|floor|floorf|floorl|fma|fmaf|fmal|fmax|fmaxf|fmaxl|fmin|fminf|fminl|fmod|fmodf|fmodl|fopen|fpclassify|fprintf|fputc|fputs|fputwc|fputws|fread|free|freopen|frexp|frexpf|frexpl|fscanf|fseek|fsetpos|ftell|fwide|fwprintf|fwrite|fwscanf|getc|getchar|getenv|gets|getwc|getwchar|gmtime|hypot|hypotf|hypotl|ilogb|ilogbf|ilogbl|imaxabs|imaxdiv|isalnum|isalpha|isblank|iscntrl|isdigit|isfinite|isgraph|isgreater|isgreaterequal|isinf|isless|islessequal|islessgreater|islower|isnan|isnormal|isprint|ispunct|isspace|isunordered|isupper|iswalnum|iswalpha|iswblank|iswcntrl|iswctype|iswdigit|iswgraph|iswlower|iswprint|iswpunct|iswspace|iswupper|iswxdigit|isxdigit|labs|ldexp|ldexpf|ldexpl|ldiv|lgamma|lgammaf|lgammal|llabs|lldiv|llrint|llrintf|llrintl|llround|llroundf|llroundl|localeconv|localtime|log|log10|log10f|log10l|log1p|log1pf|log1pl|log2|log2f|log2l|logb|logbf|logbl|logf|logl|longjmp|lrint|lrintf|lrintl|lround|lroundf|lroundl|malloc|mblen|mbrlen|mbrtowc|mbsinit|mbsrtowcs|mbstowcs|mbtowc|memchr|memcmp|memcpy|memmove|memset|mktime|modf|modff|modfl|nan|nanf|nanl|nearbyint|nearbyintf|nearbyintl|nextafter|nextafterf|nextafterl|nexttoward|nexttowardf|nexttowardl|perror|pow|powf|powl|printf|putc|putchar|puts|putwc|putwchar|qsort|raise|rand|realloc|remainder|remainderf|remainderl|remove|remquo|remquof|remquol|rename|rewind|rint|rintf|rintl|round|roundf|roundl|scalbln|scalblnf|scalblnl|scalbn|scalbnf|scalbnl|scanf|setbuf|setjmp|setlocale|setvbuf|signal|signbit|sin|sinf|sinh|sinhf|sinhl|sinl|snprintf|sprintf|sqrt|sqrtf|sqrtl|srand|sscanf|strcat|strchr|strcmp|strcoll|strcpy|strcspn|strerror|strftime|strlen|strncat|strncmp|strncpy|strpbrk|strrchr|strspn|strstr|strtod|strtof|strtoimax|strtok|strtol|strtold|strtoll|strtoul|strtoull|strtoumax|strxfrm|swprintf|swscanf|system|tan|tanf|tanh|tanhf|tanhl|tanl|tgamma|tgammaf|tgammal|time|tmpfile|tmpnam|tolower|toupper|towctrans|towlower|towupper|trunc|truncf|truncl|ungetc|ungetwc|va_arg|va_copy|va_end|va_start|vfprintf|vfscanf|vfwprintf|vfwscanf|vprintf|vscanf|vsnprintf|vsprintf|vsscanf|vswprintf|vswscanf|vwprintf|vwscanf|wcrtomb|wcscat|wcschr|wcscmp|wcscoll|wcscpy|wcscspn|wcsftime|wcslen|wcsncat|wcsncmp|wcsncpy|wcspbrk|wcsrchr|wcsrtombs|wcsspn|wcsstr|wcstod|wcstof|wcstoimax|wcstok|wcstol|wcstold|wcstoll|wcstombs|wcstoul|wcstoull|wcstoumax|wcsxfrm|wctob|wctomb|wctrans|wctype|wmemchr|wmemcmp|wmemcpy|wmemmove|wmemset|wprintf|wscanf)$', +message(8502, "function '%[name]' matches the name of a standard library function")))
|
|
+e8502
|
|
-append(8502,[BARR-C:2018 Rule 6.1b])
|
|
*/
|
|
|
|
/* 8503 - function has name that begins with an underscore */
|
|
-hook(func_decl, -cond('%[name]' ~ '^_', +message(8503, "function '%[name]' begins with an underscore")))
|
|
+e8503
|
|
-append(8503,[BARR-C:2018 Rule 6.1c])
|
|
|
|
/* 8504 - function name is longer than 31 characters */
|
|
-hook(func_decl, -cond('%[name]' ~ '.{32,}', +message(8504, "function '%[name]' is longer than 31 characters")))
|
|
+e8504
|
|
-append(8504,[BARR-C:2018 Rule 6.1d])
|
|
|
|
/* 8505 - function name contains upper case letter(s) */
|
|
//QL -hook(func_decl, -cond('%[name]' ~ '[[:upper:]]', +message(8505, "function '%[name]' contains uppercase letters")))
|
|
//QL +e8505
|
|
//QL -append(8505,[BARR-C:2018 Rule 6.1e])
|
|
|
|
/* 8506 - macro name contains lowercase letter(s) */
|
|
-hook(macro_define, -cond(!%[is_builtin] && '%[name]' ~ '[[:lower:]]', +message(8506, "macro '%[name]' contains lowercase letters")))
|
|
+e8506
|
|
-append(8506,[BARR-C:2018 Rule 6.1f])
|
|
|
|
// 6.2 Functions
|
|
|
|
/* 904 - return statement before end of function */
|
|
+e904
|
|
-append(904,[BARR-C:2018 Rule 6.2c])
|
|
|
|
/* 937 - old-style function declaration for function */
|
|
+e937
|
|
-append(937,[BARR-C:2018 Rule 6.2f])
|
|
|
|
/* 957 - function defined without a prototype in scope */
|
|
+e957
|
|
-append(957,[BARR-C:2018 Rule 6.2f])
|
|
|
|
/* 832 - parameter not explicitly declared, int assumed */
|
|
+e832
|
|
-append(832,[BARR-C:2018 Rule 6.2f])
|
|
|
|
// 6.3 Function-Like Macros
|
|
|
|
/* 9026 - function-like macro defined */
|
|
+e9026
|
|
-append(9026,[BARR-C:2018 Rule 6.3a])
|
|
|
|
/* 665 - unparenthesized parameter in macro is passed an expression */
|
|
+e665
|
|
-append(665,[BARR-C:2018 Rule 6.3b])
|
|
|
|
/* 666 - expression with side effects passed to repeated parameter */
|
|
+e666
|
|
-append(666,[BARR-C:2018 Rule 6.3b])
|
|
|
|
/* 773 - expression-like macro not parenthesized */
|
|
+e773
|
|
-append(773,[BARR-C:2018 Rule 6.3b])
|
|
|
|
/* 9022 - unparenthesized macro parameter in definition of macro */
|
|
+e9022
|
|
-append(9022,[BARR-C:2018 Rule 6.3b])
|
|
|
|
// 6.4 Threads of Execution
|
|
|
|
/* not currently supported */
|
|
|
|
// 6.5 Interrupt Service Routines
|
|
|
|
/* not currently supported */
|
|
|
|
// ========== VARIABLES ==========
|
|
|
|
// 7.1 Naming Conventions
|
|
|
|
/* 8507 - variable has name that matches a keyword in C or C++ */
|
|
-hook(var_decl, -cond('%[name]' ~ '^(?P<keyword>alignas|alignof|and|and_eq|asm|auto|bitand|bitor|bool|break|case|catch|char|char8_t|char16_t|char32_t|class|compl|concept|const|consteval|constexpr|const_cast|continue|co_await|co_return|co_yield|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|false|float|for|fortran|friend|goto|if|inline|int|interrupt|long|mutable|namespace|new|noexcept|not|not_eq|nullptr|operator|or|or_eq|private|protected|public|register|reinterpret_cast|requires|restrict|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|true|try|typedef|typeid|typename|union|unsigned|using|virtual|void|volatile|wchar_t|while|xor|xor_eq|_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local)$', +message(8507, "variable '%[name]' matches the name of a C/C++ keyword")))
|
|
+e8507
|
|
-append(8507,[BARR-C:2018 Rule 7.1a])
|
|
|
|
/* 8525 - variable has same name as standard library variable */
|
|
-hook(var_decl, -cond('%[name]' ~ '^(?:errno|stderr|stdin|stdout)$',
|
|
+message(8525, "variale '%[name]' matches the same name of a standard library variable")))
|
|
+e8525
|
|
-append(8525,[BARR-C:2018 Rule 7.1b])
|
|
|
|
/* 8508 - variable has name that begins with an underscore */
|
|
-hook(var_decl, -cond('%[name]' ~ '^_', +message(8508, "variable '%[name]' begins with an underscore")))
|
|
+e8508
|
|
-append(8508,[BARR-C:2018 Rule 7.1c])
|
|
|
|
/* 8509 - variable name is longer than 31 characters */
|
|
-hook(var_decl, -cond('%[name]' ~ '.{32,}', +message(8509, "variable '%[name]' is longer than 31 characters")))
|
|
+e8509
|
|
-append(8509,[BARR-C:2018 Rule 6.1d])
|
|
|
|
/* 8510 - variable name contains less than 3 characters */
|
|
//QL -hook(var_decl, -cond('%[name]' ~ '^.{1,2}$', +message(8510, "variable '%[name]' contains less than 3 characters")))
|
|
//QL +e8510
|
|
//QL -append(8510,[BARR-C:2018 Rule 7.1e])
|
|
|
|
/* 8511 - variable name contains upper case letter(s) */
|
|
//QL -hook(var_decl, -cond('%[name]' ~ '[[:upper:]]', +message(8511, "variable '%[name]' contains uppercase letters")))
|
|
//QL +e8511
|
|
//QL -append(8511,[BARR-C:2018 Rule 7.1f])
|
|
|
|
/* 8512 - global variable must start with 'g' */
|
|
//QL -hook(var_decl, -cond('%[linkage]' == 'external' && !('%[name]' ~ '^g'), +message(8512, "global variable '%[name]' should have 'g' prefix")))
|
|
//QL +e8512
|
|
//QL -append(8512,[BARR-C:2018 Rule 7.1j])
|
|
|
|
/* 8513 - variable of pointer type should have 'p' prefix */
|
|
/* 8514 - variable of pointer type should have 'pp' prefix */
|
|
//QL -hook(var_decl, -cond('%[walk_type.is_pointer]' == 'true',
|
|
//QL -cond('%[walk_type.walk_pointee.is_pointer]' == 'true',
|
|
//QL -cond(!('%[name]' ~ '^g?pp'), +message(8513, "variable '%[name]' of type '%[walk_type.as_string]' should have 'pp' prefix")),
|
|
//QL -cond(!('%[name]' ~ '^g?p'), +message(8514, "variable '%[name]' of type '%[walk_type.as_string]' should have 'p' prefix"))
|
|
//QL )))
|
|
//QL +e8513
|
|
//QL +e8514
|
|
//QL -append(8513,[BARR-C:2018 Rule 7.1k])
|
|
//QL -append(8514,[BARR-C:2018 Rule 7.1l])
|
|
|
|
/* 8515 - boolean variable should have 'b' prefix */
|
|
//QL -hook(var_decl, -cond('%[walk_type.is_boolean]' == 'true' && !('%[name]' ~ '^g?b'), +message(8515, "boolean variable '%[name]' should have 'b' prefix")))
|
|
//QL +e8515
|
|
//QL -append(8515,[BARR-C:2018 Rule 7.1m])
|
|
|
|
// 7.2 Initialization
|
|
|
|
/* 530 - likely using an uninitialized value */
|
|
+e530
|
|
-append(530,[BARR-C:2018 Rule 7.2a])
|
|
|
|
/* 603 - argument to parameter of type pointer to const may be a pointer to uninitialized memory */
|
|
+e603
|
|
-append(603,[BARR-C:2018 Rule 7.2a])
|
|
|
|
/* 644 - potentially using an uninitialized value */
|
|
+e644
|
|
-append(644,[BARR-C:2018 Rule 7.2a])
|
|
|
|
/* 708 - union initialization */
|
|
+e708
|
|
-append(708,[BARR-C:2018 Rule 7.2a])
|
|
|
|
/* 727 - static local symbol not explicitly initialized */
|
|
+e727
|
|
-append(727,[BARR-C:2018 Rule 7.2a])
|
|
|
|
/* 728 - file scope static variable not explicitly initialized */
|
|
+e728
|
|
-append(728,[BARR-C:2018 Rule 7.2a])
|
|
|
|
/* 729 - external variable not explicitly initialized */
|
|
+e729
|
|
-append(729,[BARR-C:2018 Rule 7.2a])
|
|
|
|
/* 738 - address of static local symbol not explicitly initialized before passed to a function */
|
|
+e738
|
|
-append(738,[BARR-C:2018 Rule 7.2a])
|
|
|
|
/* 784 - nul character truncated from string */
|
|
+e784
|
|
-append(784,[BARR-C:2018 Rule 7.2a])
|
|
|
|
/* 785 - too few initializers for aggregate */
|
|
+e785
|
|
-append(785,[BARR-C:2018 Rule 7.2a])
|
|
|
|
// ========== STATEMENT RULES ==========
|
|
|
|
// 8.1 Variable Declarations
|
|
|
|
/* 9146 - multiple declarators in a declaration */
|
|
+e9146
|
|
-append(9146,[BARR-C:2018 Rule 8.1a])
|
|
|
|
// 8.2 Conditional Statements
|
|
|
|
/* 720 - boolean test of assignment */
|
|
+e720
|
|
-append(720,[BARR-C:2018 Rule 8.2c])
|
|
|
|
/* 820 - boolean test of parenthesized assignment */
|
|
+e820
|
|
-append(820,[BARR-C:2018 Rule 8.2c])
|
|
|
|
/* 9013 - no 'else' at end of 'if ... else if' chain */
|
|
+e9013
|
|
-append(9013,[BARR-C:2018 Rule 8.2d])
|
|
|
|
// 8.3 Switch Statements
|
|
|
|
/* 9014 - switch without default */
|
|
+e9014
|
|
-append(9014,[BARR-C:2018 Rule 8.3b])
|
|
|
|
/* 616 - control flow falls through to next case without an intervening comment */
|
|
+e616
|
|
-append(616,[BARR-C:2018 Rule 8.3c])
|
|
|
|
// 8.4 Loops
|
|
|
|
/* 850 - for statement index variable modified in body */
|
|
+e850
|
|
-append(850,[BARR-C:2018 Rule 8.4b])
|
|
|
|
/* 716 - infinite loop via while */
|
|
+e716
|
|
-append(716,[BARR-C:2018 Rule 8.4c])
|
|
|
|
// 8.5 Jumps
|
|
|
|
/* 9041 - goto appears in block which is not nested in block containing label */
|
|
+e9041
|
|
-append(9041,[BARR-C:2018 Rule 8.5a])
|
|
|
|
/* 9064 - goto references earlier label */
|
|
+e9064
|
|
-append(9064,[BARR-C:2018 Rule 8.5a])
|
|
|
|
/* 586 - function/macro is deprecated */
|
|
-deprecate(function,abort,[BARR-C:2018 Rule 8.5b])
|
|
-deprecate(function,exit,[BARR-C:2018 Rule 8.5b])
|
|
-deprecate(function,longjmp,[BARR-C:2018 Rule 8.5b])
|
|
-deprecate(macro,setjmp,[BARR-C:2018 Rule 8.5b])
|
|
|
|
// 8.6 Equivalence Test
|
|
|
|
/* 8522 - variable should appear on RHS of '==' operator */
|
|
//QL -hook(binary_expr, -cond('%[opcode]' == '==' &&
|
|
//QL '%[walk_lhs_expr.walk_past_paren_cast.set_msg_loc.is_decl_ref_expr]' == 'true' &&
|
|
//QL '%[walk_rhs_expr.is_constant_expr]' == 'true',
|
|
//QL +message(8522, "variable '%[walk_lhs_expr.walk_past_paren_cast.walk_decl.qual_name]' should appear on RHS of '==' operator")))
|
|
//QL +e8522
|
|
//QL -append(8522,[BARR-C:2018 Rule 8.6a])
|