gcc(gnu), clang(llvm)コンパイルエラー・警告比較(9) R_13_0x.c。docker(163)


やってきました。

gcc(gnu) clang(llvm)コンパイルエラー比較

長らくごぶさたしていました。

MISRA の解説書は有料ですが、Codeは無償であげてくれています。

MISRA C:2012 Example-Suite
https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite

全体の記録は

Misra Example Suite at docker コンパイル完了までの道のり
https://qiita.com/kaizen_nagoya/items/71f04a0204d5a1114577

順にコンパイルエラーが出たものを比較し、
エラーを取るのなら取ってみます。

-Wall でコンパイルしています。

R_13_0x.c

$ clang 
R_13_01_1.c:42:35: warning: multiple unsequenced modifications to 'x' [-Wunsequenced]
   use_arr ( ( uint16_t[ 2 ] ) { x++, x++ } );
                                  ^    ~~
1 warning generated.
R_13_02.c:39:20: warning: multiple unsequenced modifications to 'i' [-Wunsequenced]
   COPY_ELEMENT ( i++ );     /* Non-compliant - i is modified twice and also read  */
                   ^~
R_13_02.c:30:37: note: expanded from macro 'COPY_ELEMENT'
#define COPY_ELEMENT( index ) ( b[( index )] = c[( index )] )  /* violates D.4.9 */
                                    ^              ~~~~~
R_13_02.c:52:9: warning: unsequenced modification and access to 'i' [-Wunsequenced]
   f ( i++, i );            /* Non-compliant - order of evaluation unspecified     */
        ^   ~
2 warnings generated.
R_13_03.c:78:8: warning: expression result unused [-Wunused-value]
       *p++;
       ^~~~
1 warning generated.
R_13_04.c:36:18: warning: unsequenced modification and access to 'x' [-Wunsequenced]
   a[ x ] = a[ x = y ];                       /* Non-compliant - also breaks R.13.2 */
      ~          ^
R_13_04.c:41:18: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
   if ( bool_var = false )                    /* Non-compliant - also breaks R.14.3 */
        ~~~~~~~~~^~~~~~~
R_13_04.c:41:18: note: place parentheses around the assignment to silence this warning
   if ( bool_var = false )                    /* Non-compliant - also breaks R.14.3 */
                 ^
        (               )
R_13_04.c:41:18: note: use '==' to turn this assignment into an equality comparison
   if ( bool_var = false )                    /* Non-compliant - also breaks R.14.3 */
                 ^
                 ==
R_13_04.c:56:9: warning: unsequenced modification and access to 'b' [-Wunsequenced]
   a[ b += c ] = a[ b ];                     /* Non-compliant - also breaks R.13.2  */
        ^           ~
3 warnings generated.
R_13_06.c:45:15: warning: expression with side effects has no effect in an unevaluated context [-Wunevaluated-expression]
   s = sizeof ( j++ );            /* Non-compliant          */
              ^
1 warning generated.

$ gcc 
R_13_02.c: In function 'R_13_2':
R_13_02.c:39:20: warning: operation on 'i' may be undefined [-Wsequence-point]
   30 | #define COPY_ELEMENT( index ) ( b[( index )] = c[( index )] )  /* violates D.4.9 */
      |                                                  ~~~~~~~~~
......
   39 |    COPY_ELEMENT ( i++ );     /* Non-compliant - i is modified twice and also read  */
R_13_02.c:30:52: note: in definition of macro 'COPY_ELEMENT'
   30 | #define COPY_ELEMENT( index ) ( b[( index )] = c[( index )] )  /* violates D.4.9 */
      |                                                    ^~~~~
R_13_02.c:52:9: warning: operation on 'i' may be undefined [-Wsequence-point]
   52 |    f ( i++, i );            /* Non-compliant - order of evaluation unspecified     */
      |        ~^~
R_13_03.c: In function 'R_13_3':
R_13_03.c:78:8: warning: value computed is not used [-Wunused-value]
   78 |        *p++;
      |        ^~~~
R_13_04.c: In function 'R_13_4':
R_13_04.c:36:18: warning: operation on 'x' may be undefined [-Wsequence-point]
   36 |    a[ x ] = a[ x = y ];                       /* Non-compliant - also breaks R.13.2 */
      |                ~~^~~
R_13_04.c:41:9: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   41 |    if ( bool_var = false )                    /* Non-compliant - also breaks R.14.3 */
      |         ^~~~~~~~
R_13_04.c:56:9: warning: operation on 'b' may be undefined [-Wsequence-point]
   56 |    a[ b += c ] = a[ b ];                     /* Non-compliant - also breaks R.13.2  */
      |       ~~^~~~
In file included from clear_lib.c:10:
clear_lib.c: In function 'g':
clear_lib.c:266:6: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  266 |  PR1((int)p,d);
      |      ^
misra_c.h:66:54: note: in definition of macro 'PR1'
   66 | #define PR1(a,b) (void)printf(" "#a  " = %" #b "\n", a)
      |                                                      ^
clear_lib.c: In function 'use_const_volatile_char_ptr':
clear_lib.c:279:6: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  279 |  PR1((int)cv_cp,d);
      |      ^
misra_c.h:66:54: note: in definition of macro 'PR1'
   66 | #define PR1(a,b) (void)printf(" "#a  " = %" #b "\n", a)
      |                                                      ^

docker hubでの作業

docker hubからの起動はこちら。

$ docker run it kaizenjapan/misra_c_2012_example /bin/bash

参考資料

仮説・検証(173)C言語(C++)に対する誤解、曲解、無理解、爽快。

[C][C++]の国際規格案の例題をコンパイルするときの課題7つ。
https://qiita.com/kaizen_nagoya/items/5f4b155030259497c4de
C Puzzle Bookの有り難み5つ、C言語規格及びCコンパイラの特性を認識
https://qiita.com/kaizen_nagoya/items/d89a48c1536a02ecdec9
MISRA C まとめ #include
https://qiita.com/kaizen_nagoya/items/f1a79a7cbd281607c7c9
どうやって MISRA Example Suiteをコンパイルするか
https://qiita.com/kaizen_nagoya/items/fbdbff5ff696e2ca7f00

ISO/IEC TS 17961:2013 C Secure Coding Rules(1) All list(to be confirmed)
https://qiita.com/kaizen_nagoya/items/54e056195c4f11b850a1

Autosar Guidelines C++14 example code compile list
https://qiita.com/kaizen_nagoya/items/8ccbf6675c3494d57a76

C++ N4741, N4606, N3242 Source Compile Error List
https://qiita.com/kaizen_nagoya/items/2e736e04339b340ffb4d