C and C++


LANG.STRUCT.ALIGNAS.IAS : Inconsistent Alignment Specifications

要旨

An object (variable or a field) is declared with multiple alignment specifications that are not consistent.

For the sake of this check:

This class is a strict subset of Use of Alignas.

See also Too Many Alignment Specifiers.

プロパティ

クラス名 Inconsistent Alignment Specifications
日本語クラス名 Inconsistent Alignment Specifications
クラス分類 信頼性 (reliability)
ニーモニック LANG.STRUCT.ALIGNAS.IAS
カテゴリー
MisraC2023 MisraC2023:1.4 Emergent language features shall not be used
  MisraC2023:8.15 All declarations of an object with an explicit alignment specification shall specify the same alignment
Misra2012 Misra2012:1.4 Emergent language features shall not be used
  Misra2012:8.15 All declarations of an object with an explicit alignment specification shall specify the same alignment
CERT-C CERT-C:MSC23-C Beware of vendor-specific library and language differences
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Inconsistent Alignment Specifications"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

/* LANG.STRUCT.ALIGNAS.IAS.c */

#include "LANG.STRUCT.ALIGNAS.IAS.h"

alignas(8) int hc_same_const;                        /* ('Use of Alignas' warning issued when enabled) */
alignas(4) int hc_diff_const;                        /* ('Use of Alignas' warning issued when enabled) */
alignas(2*4) int hc_same_const_exp;                  /* ('Use of Alignas' warning issued when enabled) */
int hc_one_spec;                                /* 'Inconsistent Alignment Specifications' warning issued here:
                                                 * - explicit alignment specified in .h file, but none here
                                                 */
alignas(4) int hc_type_const;                        /* ('Use of Alignas' warning issued when enabled) */
alignas(alignof(int)) int hc_type_alignof_type;      /* ('Use of Alignas' and 'Use of Alignof' warnings issued when enabled) */
/* LANG.STRUCT.ALIGNAS.IAS.h */

#include <stdalign.h>

extern alignas(8) int h_one_spec;                      /* ok: single declaration; single alignas specification
                                                        * ('Use of Alignas' warning issued when enabled)
                                                        */
extern alignas(8) alignas(4) int h_diff_const; /* 'Inconsistent Alignment Specifications' warning issued here
                                                * - two different alignments in the same declaration
                                                * ('Too Many Alignment Specifiers' and 'Use of Alignas' warnings
                                                * also issued when enabled)
                                                */
extern alignas(8) int hc_same_const;                   /* ok: alignment specified in .c file is 8
                                                        * ('Use of Alignas' warning issued when enabled)
                                                        */
extern alignas(8) int hc_diff_const;           /* 'Inconsistent Alignment Specifications' warning issued here
                                                * - alignment specified in .c file is 4
                                                * ('Use of Alignas' warning also issued when enabled)
                                                */
extern alignas(8) int hc_same_const_exp;               /* ok: alignment specified in .c file is 2*4 (==8)
                                                        * ('Use of Alignas' warning issued when enabled)
                                                        */
extern alignas(8) int hc_one_spec;

extern alignas(int) int hc_type_const;         /* 'Inconsistent Alignment Specifications' warning issued here
                                                * - alignment specified in .c file is 4
                                                * - a warning is issued even if the alignment of int is 4
                                                * ('Use of Alignas' warning also issued when enabled)
                                                */
extern alignas(int) int hc_type_alignof_type;  /* 'Inconsistent Alignment Specifications' warning issued here
                                                * - alignment specified in .c file is alignof(int)
                                                * ('Use of Alignas' warning also issued when enabled)
                                                */

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。