diff options
author | Jakub Jelinek <jakub@redhat.com> | 2025-08-04 14:27:14 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2025-08-04 14:27:14 +0200 |
commit | b9f443b6177881c490fbce9ba65b86a7cd65f11f (patch) | |
tree | f4c321be9c5aab91ef6e78a4b59fa6d83523dfa0 | |
parent | d49d359b0c5266b314bcf31405746909d99927a1 (diff) | |
download | gcc-b9f443b6177881c490fbce9ba65b86a7cd65f11f.zip gcc-b9f443b6177881c490fbce9ba65b86a7cd65f11f.tar.gz gcc-b9f443b6177881c490fbce9ba65b86a7cd65f11f.tar.bz2 |
libcpp: Use pedwarn instead of warning for CWG2578 diagnostics [PR120778]
This is another case which changed from compile time undefined behavior
to ill-formed, diagnostic required. Now, we warn on this, so pedantically
that is good enough, maybe all we need is a testcase, but the following
patch changes it to a pedwarn for C++26.
2025-08-04 Jakub Jelinek <jakub@redhat.com>
PR preprocessor/120778
* macro.cc (stringify_arg): For C++26 emit a pedarn instead of warning
for \ at the end of stringification.
* g++.dg/DRs/dr2578.C: New test.
-rw-r--r-- | gcc/testsuite/g++.dg/DRs/dr2578.C | 10 | ||||
-rw-r--r-- | libcpp/macro.cc | 5 |
2 files changed, 14 insertions, 1 deletions
diff --git a/gcc/testsuite/g++.dg/DRs/dr2578.C b/gcc/testsuite/g++.dg/DRs/dr2578.C new file mode 100644 index 0000000..0dce23b --- /dev/null +++ b/gcc/testsuite/g++.dg/DRs/dr2578.C @@ -0,0 +1,10 @@ +// DR 2578 - Undefined behavior when creating an invalid string literal via stringizing +// { dg-do preprocess } +// { dg-options "-pedantic-errors" } + +#define A(a) #a +#define B(a) A(a) +#define C \\ + +const char *x = B(C); // { dg-warning "invalid string literal, ignoring final '\\\\'" "" { target c++23_down } } +// { dg-error "invalid string literal, ignoring final '\\\\'" "" { target c++26 } .-1 } diff --git a/libcpp/macro.cc b/libcpp/macro.cc index be25710..d869b02 100644 --- a/libcpp/macro.cc +++ b/libcpp/macro.cc @@ -1003,7 +1003,10 @@ stringify_arg (cpp_reader *pfile, const cpp_token **first, unsigned int count) /* Ignore the final \ of invalid string literals. */ if (backslash_count & 1) { - cpp_error (pfile, CPP_DL_WARNING, + cpp_error (pfile, + CPP_OPTION (pfile, cplusplus) + && CPP_OPTION (pfile, lang) >= CLK_GNUCXX26 + ? CPP_DL_PEDWARN : CPP_DL_WARNING, "invalid string literal, ignoring final %<\\%>"); dest--; } |