Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

`A7-1-7`: Exclude expression statements in macros

オープン
#629 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
38/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
cpp
領域
devtools

調査の方向性

A7-1-7 クエリと、マクロ展開された宣言および式文の周囲の括弧付けを調査します。提供されている foo(a, b) の C++ 例を使用して、マクロ展開中に位置がどのように割り当てられるかを調べます。関連のない式文を誤って削除することなく、その例が適合するものとして除外されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Difficulty-Low false positive/false negative Impact-Medium Standard-AUTOSAR
Affected rules
  • A7-1-7
Description

Macro expansion can cause multiple expressions and statements to appear at the same location. We exclude macro expanded declarations, I think we should do the same for expression statements.

Reviewing the query, I think this is actually caused by a bracketing issue:

    not isAffectedByMacro() and
   // MISSING OPENING BRACKET HERE
    exists(Declaration d |
       ...
    )
    or
    this instanceof ExprStmt and
    not exists(ForStmt f | f.getInitialization().getAChild*() = this) and
    not exists(LambdaExpression l | l.getLambdaFunction().getBlock().getAChild*() = this)
   // MISSING CLOSED BRACKET HERE

There's also an interesting thing happening here with locations - as we might expect such macro expansions to by the not l1 = l2 line in the select clause:

  exists(Location l1, Location l2 |
    e1.getLocation() = l1 and
    e2.getLocation() = l2 and
    not l1 = l2 and
....

The reason this doesn't exclude this case is that when we expand the macro, we may provide different locations for the expressions and statements within, if we can associate them with a specific macro parameter.

Example
#define foo(x, y)                                                              \
  x++;                                                                         \
  y++;

void test_macro() {
  int a = 1;
  int b = 1;
  foo(a, b); // COMPLIANT
}
主要言語
CodeQL
スター
227
フォーク
82
平均マージ
6日 7時間
マージ済み PR(30日)
9

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

github/codeql-coding-standards のほかの issue

github/codeql-coding-standards の issue をすべて見る

似ている issue

DevTools の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。