Hi! 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.
Tested on x86_64-linux and i686-linux, ok for trunk? 2025-08-06 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-2.h: New file. --- gcc/testsuite/g++.dg/DRs/dr2577-1.C.jj 2025-08-06 15:12:24.640033269 +0200 +++ gcc/testsuite/g++.dg/DRs/dr2577-1.C 2025-08-06 16:05:12.134023501 +0200 @@ -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 } --- gcc/testsuite/g++.dg/DRs/dr2577-2.C.jj 2025-08-06 16:05:35.129718707 +0200 +++ gcc/testsuite/g++.dg/DRs/dr2577-2.C 2025-08-06 16:14:20.033765879 +0200 @@ -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 } --- gcc/testsuite/g++.dg/DRs/dr2577-2.h.jj 2025-08-06 16:06:20.305119929 +0200 +++ gcc/testsuite/g++.dg/DRs/dr2577-2.h 2025-08-06 16:06:44.572798276 +0200 @@ -0,0 +1 @@ +1 --- gcc/testsuite/g++.dg/DRs/dr2577-3.C.jj 2025-08-06 16:11:09.729286055 +0200 +++ gcc/testsuite/g++.dg/DRs/dr2577-3.C 2025-08-06 16:15:12.931065370 +0200 @@ -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" } --- gcc/testsuite/g++.dg/DRs/dr2577-3.h.jj 2025-08-06 16:11:43.266841918 +0200 +++ gcc/testsuite/g++.dg/DRs/dr2577-3.h 2025-08-06 16:11:48.553771904 +0200 @@ -0,0 +1 @@ +1) Jakub