Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

/*	$NetBSD: msg_159.c,v 1.6 2023/04/22 17:30:35 rillig Exp $	*/
# 3 "msg_159.c"

// Test for message: assignment in conditional context [159]

/* lint1-extra-flags: -h */

const char *
example(int a, int b)
{

	if (a == b)
		return "comparison, not parenthesized";

	/*
	 * Clang-Tidy marks a comparison with extra parentheses as an error,
	 * expecting that assignments are parenthesized and comparisons
	 * aren't.
	 */
	if ((a == b))
		return "comparison, parenthesized";

	if (
# 25 "msg_159.c" 3 4
	    (a == b)
# 27 "msg_159.c"
	    )
		return "comparison, parenthesized, from system header";

	/* expect+1: warning: assignment in conditional context [159] */
	if (a = b)
		return "assignment, not parenthesized";

	/*
	 * GCC established the convention that an assignment that is
	 * parenthesized is intended as an assignment, so don't warn about
	 * that case.
	 */
	if ((a = b))
		return "assignment, parenthesized";

	if ((a = b) != 0)
		return "explicit comparison after assignment";

	return "other";
}