================
@@ -0,0 +1,200 @@
+// RUN: %clang_cc1 -fsyntax-only -Wmacro-mixed-operator -verify %s
+
+// ------------------------------------------------------------
+// Basic macro body precedence problem
+// ------------------------------------------------------------
+#define FOO 2+3
+// 2+(3*4) == 14, not (2+3)*4 == 20
+int n = FOO*4; // expected-warning {{operator '+' in macro expansion has
operand outside the macro; operator precedence may be different than expected}}
+
+// ------------------------------------------------------------
+// Macro argument precedence problem
+// ------------------------------------------------------------
+#define FOO_ARG(x) 2+x
+int m = FOO_ARG(3*4); // expected-warning {{operator '+' in macro expansion
has operand outside the macro; operator precedence may be different than
expected}}
+
+// ------------------------------------------------------------
+// Operator entirely outside macros (should NOT warn)
+// ------------------------------------------------------------
+int k = 2 + 3 * 4; // no-warning
+
+// ------------------------------------------------------------
+// Operator comes from macro argument only (should NOT warn)
+// ------------------------------------------------------------
+#define ID(x) x
+int p = ID(2+3)*4; // no-warning
+
+// ------------------------------------------------------------
+// Macro with proper parentheses (should NOT warn)
+// ------------------------------------------------------------
+#define SAFE_ADD (2+3)
+int q = SAFE_ADD*4; // no-warning
+
+#define SAFE_ARG(x) (2+(x))
+int r = SAFE_ARG(3*4); // no-warning
+
+// ------------------------------------------------------------
+// Nested macro expansion
+// ------------------------------------------------------------
+#define INNER 2+3
+#define OUTER INNER
+int s = OUTER*4; // expected-warning {{operator '+' in macro expansion has
operand outside the macro; operator precedence may be different than expected}}
+
+// ------------------------------------------------------------
+// Macro producing multiplication interacting with external +
+// ------------------------------------------------------------
+#define MUL 2*3
+int t = MUL+4; // no-warning
+
+// ------------------------------------------------------------
+// Macro with multiple operators
+// ------------------------------------------------------------
+#define MIXED 1+2*3
+int u = MIXED+4; // no-warning
+
+// ------------------------------------------------------------
+// Macro argument containing another macro
+// ------------------------------------------------------------
+#define ADD(x) 2+x
+#define VALUE 3*4
+int v = ADD(VALUE); // expected-warning {{operator '+' in macro expansion has
operand outside the macro; operator precedence may be different than expected}}
+
+// ------------------------------------------------------------
+// Macro where entire expression stays inside expansion
+// ------------------------------------------------------------
+#define FULL (2+3)
+int w = FULL; // no-warning
+
+// ------------------------------------------------------------
+// Operator both operands inside macro body
+// ------------------------------------------------------------
+#define ADD_TWO (2+3)
+int x = ADD_TWO; // no-warning
----------------
zmodem wrote:
This seems identical to the case above?
https://github.com/llvm/llvm-project/pull/184924
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits