Author: Prashanth
Date: 2026-09-18T08:04:58-04:00
New Revision: 747c011130b66c197ff5b18892646933f3a1c838

URL: 
https://github.com/llvm/llvm-project/commit/747c011130b66c197ff5b18892646933f3a1c838
DIFF: 
https://github.com/llvm/llvm-project/commit/747c011130b66c197ff5b18892646933f3a1c838.diff

LOG: [clang][Sema][Tests] Add test coverage for function-like macro diagnostic 
edge cases and C++ (#223895)

Add C++ and edge-case test coverage for function-like macro diagnostic

Follow-up to #123495.

Adds regression tests covering cases not exercised by the original PR:
- Macro call with intervening comment/whitespace before '(', confirms
  findNextToken correctly skips these rather than misfiring
- Macro call with '(' across a line break
- Re-#define after #undef, confirms no stale state
- Array-size context (non-assignment expression)
- Variadic function-like macro
- New SemaCXX test confirming the diagnostic fires correctly in C++,
  since the implementation lives in shared SemaExpr.cpp

No behavior change, test coverage only.

Added: 
    

Modified: 
    clang/test/Sema/typo-correction-no-hang.cpp
    clang/test/Sema/typo-correction.c

Removed: 
    


################################################################################
diff  --git a/clang/test/Sema/typo-correction-no-hang.cpp 
b/clang/test/Sema/typo-correction-no-hang.cpp
index 34b8486bed902..3e7202e6aed9f 100644
--- a/clang/test/Sema/typo-correction-no-hang.cpp
+++ b/clang/test/Sema/typo-correction-no-hang.cpp
@@ -40,3 +40,10 @@ int Bar(const B &b) {
   return b.depar().longitude() + //expected-error{{no member named 'longitude' 
in 'A'}}
          b.depar().latitude();   //expected-error{{no member named 'latitude' 
in 'A'}}
 }
+
+#define BAZ() 1
+// expected-note@-1 {{'BAZ' defined here as a function-like macro}}
+
+void testFuncLikeMacroWithoutParens() {
+    int x = BAZ; // expected-error {{'BAZ' is defined as a function-like 
macro; did you mean 'BAZ(...)'?}}
+}

diff  --git a/clang/test/Sema/typo-correction.c 
b/clang/test/Sema/typo-correction.c
index 1f6bcd0485a02..7cda42f8640d5 100644
--- a/clang/test/Sema/typo-correction.c
+++ b/clang/test/Sema/typo-correction.c
@@ -140,3 +140,37 @@ void test5() {
     FOO1 + 1; // expected-error {{'FOO1' is defined as a function-like macro; 
did you mean 'FOO1(...)'?}}
     bar(FOO1); // expected-error {{'FOO1' is defined as a function-like macro; 
did you mean 'FOO1(...)'?}}
 }
+
+#undef FOO1
+
+void test6(){
+    int iter = FOO1;  //expected-error {{use of undeclared identifier 'FOO1'}}
+}
+
+
+#define FOO1() 99 // expected-note 2 {{'FOO1' defined here as a function-like 
macro}}
+
+void test7() {
+    int w = FOO1; // expected-error {{'FOO1' is defined as a function-like 
macro; did you mean 'FOO1(...)'?}}
+}
+
+#define FOO2() 42
+
+void test8() {
+    int y = FOO2 /* comment */ (); // no error expected — still a real call
+}
+
+void test9() {
+    int z = FOO2
+        (); // no error expected — paren across a line break
+}
+
+void test10() {
+    int arr[FOO1]; // expected-error {{'FOO1' is defined as a function-like 
macro; did you mean 'FOO1(...)'?}}
+}
+
+#define VARFOO(...) 1 // expected-note {{'VARFOO' defined here as a 
function-like macro}}
+
+void test11() {
+    int v = VARFOO; // expected-error {{'VARFOO' is defined as a function-like 
macro; did you mean 'VARFOO(...)'?}}
+}


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to