From: Stephen Hemminger <stephen@networkplumber.org>
To: Bruce Richardson <bruce.richardson@intel.com>
Cc: <dev@dpdk.org>, Rosen Xu <rosen.xu@altera.com>
Subject: Re: [PATCH] raw/ifpga: fix comma warnings
Date: Thu, 12 Mar 2026 09:33:25 -0700 [thread overview]
Message-ID: <20260312093325.3603220b@phoenix.local> (raw)
In-Reply-To: <abLpp8jbldpWY8Bf@bricha3-mobl1.ger.corp.intel.com>
On Thu, 12 Mar 2026 16:28:23 +0000
Bruce Richardson <bruce.richardson@intel.com> wrote:
> Yes, it's disabled for the drivers, but if we enable it for raw/ifpga
> driver, how come this macro doesn't give the warning when it uses the exact
> same structure as the original code?
Short answer, clang treats macros as special case for comma operator.
As always AI has longer answer...
Great question — this is a well-known Clang behavior that trips people up.
Clang's `-Wcomma` warning fires when it sees a comma operator where the left-hand side result is discarded, since that's often a bug (someone meant `&&` or `;` instead of `,`). The expression `(tmp = TAILQ_NEXT(dfl, node), 1)` is a textbook trigger: the assignment result is discarded and only the `1` is used.
However, Clang deliberately suppresses most warnings — including `-Wcomma` — for code that originates from macro expansions. The rationale is that macro-expanded code is an established idiom the user didn't write directly at that call site, so warning on it would generate noise that the caller can't reasonably fix. The warning logic checks whether the expression's source location traces back to a macro expansion and, if so, skips the diagnostic.
So the two cases are semantically identical after preprocessing, but Clang's diagnostic engine distinguishes them by source location:
**Inline version** — the comma operator appears directly in your source code → Clang assumes you wrote it intentionally and warns you in case you didn't.
**Macro version** — the comma operator is inside `TAILQ_FOREACH_SAFE`'s expansion → Clang sees the macro origin, treats it as an intentional idiom, and suppresses the warning.
If you want to silence it in the inline case without rewriting the loop, you have a few options: cast the left side to `void` explicitly — `((void)(tmp = TAILQ_NEXT(dfl, node)), 1)` — which signals to Clang that the discard is intentional, or use a pragma to locally disable `-Wcomma`, or just use the macro (which is the idiomatic approach for TAILQ iteration anyway).
prev parent reply other threads:[~2026-03-12 16:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-12 0:23 [PATCH] raw/ifpga: fix comma warnings Stephen Hemminger
2026-03-12 9:15 ` Bruce Richardson
2026-03-12 16:03 ` Stephen Hemminger
2026-03-12 16:28 ` Bruce Richardson
2026-03-12 16:33 ` Stephen Hemminger [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260312093325.3603220b@phoenix.local \
--to=stephen@networkplumber.org \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=rosen.xu@altera.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox