https://gcc.gnu.org/g:6026a54f2faedf0be3b8e15b3e69492d21cfc082

commit r16-3062-g6026a54f2faedf0be3b8e15b3e69492d21cfc082
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Thu Aug 7 08:53:23 2025 +0200

    c++: Add testcase for CWG2577 [PR120778]
    
    And here is the last part of the paper.  Contrary what the paper claims
    (clearly they haven't tried -pedantic nor -pedantic-errors), I think we
    already diagnose everything we should.
    
    2025-08-07  Jakub Jelinek  <ja...@redhat.com>
    
            PR preprocessor/120778
            * g++.dg/DRs/dr2577-1.C: New test.
            * g++.dg/DRs/dr2577-2.C: New test.
            * g++.dg/DRs/dr2577-2.h: New file.
            * g++.dg/DRs/dr2577-3.C: New test.
            * g++.dg/DRs/dr2577-3.h: New file.

Diff:
---
 gcc/testsuite/g++.dg/DRs/dr2577-1.C | 40 +++++++++++++++++++++++++++++++++++++
 gcc/testsuite/g++.dg/DRs/dr2577-2.C | 13 ++++++++++++
 gcc/testsuite/g++.dg/DRs/dr2577-2.h |  1 +
 gcc/testsuite/g++.dg/DRs/dr2577-3.C |  7 +++++++
 gcc/testsuite/g++.dg/DRs/dr2577-3.h |  1 +
 5 files changed, 62 insertions(+)

diff --git a/gcc/testsuite/g++.dg/DRs/dr2577-1.C 
b/gcc/testsuite/g++.dg/DRs/dr2577-1.C
new file mode 100644
index 000000000000..784b6a8c4cf1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/DRs/dr2577-1.C
@@ -0,0 +1,40 @@
+// DR 2577 - Undefined behavior for preprocessing directives in macro arguments
+// { dg-do preprocess }
+// { dg-options "-pedantic-errors" }
+
+#define A(x)
+#define B(x, y)
+A(
+#if 1                          // { dg-error "embedding a directive within 
macro arguments is not portable" }
+1
+#else                          // { dg-error "embedding a directive within 
macro arguments is not portable" }
+2
+#endif                         // { dg-error "embedding a directive within 
macro arguments is not portable" }
+)
+B(1,
+#line 234                      // { dg-error "embedding a directive within 
macro arguments is not portable" }
+)
+#line 18
+A(
+#define C 1                    // { dg-error "embedding a directive within 
macro arguments is not portable" }
+)
+A(
+#undef C                       // { dg-error "embedding a directive within 
macro arguments is not portable" }
+)
+B(42,
+# 234 "dr2577-1.C"             // { dg-error "embedding a directive within 
macro arguments is not portable" }
+)                              // { dg-error "style of line directive is a GCC 
extension" "" { target *-*-* } .-1 }
+#line 28 "dr2577-1.C"
+B(
+#warning "foobar"              // { dg-error "embedding a directive within 
macro arguments is not portable" }
+, 12)                          // { dg-error "'#warning' before C\\\+\\\+23 is 
a GCC extension" "" { target c++20_down } .-1 }
+                               // { dg-warning "#warning \"foobar\"" "" { 
target *-*-* } .-2 }
+A(
+#pragma GCC diagnostics push   // { dg-error "embedding a directive within 
macro arguments is not portable" }
+)
+B(5,
+#pragma GCC diagnostics pop    // { dg-error "embedding a directive within 
macro arguments is not portable" }
+)
+A(
+#error foobar                  // { dg-error "embedding a directive within 
macro arguments is not portable" }
+)                              // { dg-error "#error foobar" "" { target *-*-* 
} .-1 }
diff --git a/gcc/testsuite/g++.dg/DRs/dr2577-2.C 
b/gcc/testsuite/g++.dg/DRs/dr2577-2.C
new file mode 100644
index 000000000000..e54006ae6fc8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/DRs/dr2577-2.C
@@ -0,0 +1,13 @@
+// DR 2577 - Undefined behavior for preprocessing directives in macro arguments
+// { dg-do preprocess }
+// { dg-options "-pedantic-errors" }
+
+#define A(x, y, z) x + y + z
+int a = A(
+#include "dr2577-2.h"          // { dg-error "embedding a directive within 
macro arguments is not portable" }
+,
+#include "dr2577-2.h"
+,
+#include "dr2577-2.h"
+);
+// { dg-error "unterminated argument list invoking macro 'A'" "" { target 
*-*-* } 0 }
diff --git a/gcc/testsuite/g++.dg/DRs/dr2577-2.h 
b/gcc/testsuite/g++.dg/DRs/dr2577-2.h
new file mode 100644
index 000000000000..d00491fd7e5b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/DRs/dr2577-2.h
@@ -0,0 +1 @@
+1
diff --git a/gcc/testsuite/g++.dg/DRs/dr2577-3.C 
b/gcc/testsuite/g++.dg/DRs/dr2577-3.C
new file mode 100644
index 000000000000..6ebf419fb8cb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/DRs/dr2577-3.C
@@ -0,0 +1,7 @@
+// DR 2577 - Undefined behavior for preprocessing directives in macro arguments
+// { dg-do preprocess }
+// { dg-options "-pedantic-errors" }
+
+#define A(x) x
+int a = A(
+#include "dr2577-3.h"          // { dg-error "embedding a directive within 
macro arguments is not portable" }
diff --git a/gcc/testsuite/g++.dg/DRs/dr2577-3.h 
b/gcc/testsuite/g++.dg/DRs/dr2577-3.h
new file mode 100644
index 000000000000..5e36ce0121e4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/DRs/dr2577-3.h
@@ -0,0 +1 @@
+1)

Reply via email to