preprocessor: Implement C++23 P2437R1 - Support for #warning [PR106646]
On Thu, Aug 18, 2022 at 11:02:44PM +0000, Joseph Myers wrote: > ISO C2x standardizes the existing #warning extension. Arrange > accordingly for it not to be diagnosed with -std=c2x -pedantic, but to > be diagnosed with -Wc11-c2x-compat. And here is the corresponding C++ version. Don't pedwarn about this for C++23/GNU++23 and tweak the diagnostics for C++ otherwise, + testsuite coverage. The diagnostic wording is similar e.g. to the #elifdef diagnostics. 2022-08-24 Jakub Jelinek <jakub@redhat.com> PR c++/106646 * init.cc: Implement C++23 P2437R1 - Support for #warning. (lang_defaults): Set warning_directive for GNUCXX23 and CXX23. * directives.cc (directive_diagnostics): Use different wording of #warning pedwarn for C++. * g++.dg/cpp/warning-1.C: New test. * g++.dg/cpp/warning-2.C: New test. * g++.dg/cpp/warning-3.C: New test.
This commit is contained in:
parent
42301c02e4
commit
365202625d
5 changed files with 28 additions and 4 deletions
6
gcc/testsuite/g++.dg/cpp/warning-1.C
Normal file
6
gcc/testsuite/g++.dg/cpp/warning-1.C
Normal file
|
@ -0,0 +1,6 @@
|
|||
// P2437R1 - Support for #warning
|
||||
// { dg-do preprocess }
|
||||
// { dg-options "-pedantic-errors" }
|
||||
|
||||
#warning example text /* { dg-warning "example text" } */
|
||||
// { dg-error "#warning before C\\\+\\\+23 is a GCC extension" "pedantic" { target c++20_down } .-1 }
|
6
gcc/testsuite/g++.dg/cpp/warning-2.C
Normal file
6
gcc/testsuite/g++.dg/cpp/warning-2.C
Normal file
|
@ -0,0 +1,6 @@
|
|||
// P2437R1 - Support for #warning
|
||||
// { dg-do preprocess }
|
||||
// { dg-options "-pedantic" }
|
||||
|
||||
#warning example text /* { dg-warning "example text" } */
|
||||
// { dg-warning "#warning before C\\\+\\\+23 is a GCC extension" "pedantic" { target c++20_down } .-1 }
|
6
gcc/testsuite/g++.dg/cpp/warning-3.C
Normal file
6
gcc/testsuite/g++.dg/cpp/warning-3.C
Normal file
|
@ -0,0 +1,6 @@
|
|||
// P2437R1 - Support for #warning
|
||||
// { dg-do preprocess }
|
||||
// { dg-options "" }
|
||||
|
||||
#warning example text /* { dg-warning "example text" } */
|
||||
// { dg-bogus "#warning before C\\\+\\\+23 is a GCC extension" "" { target *-*-* } .-1 }
|
|
@ -388,8 +388,14 @@ directive_diagnostics (cpp_reader *pfile, const directive *dir, int indented)
|
|||
else if (dir == &dtable[T_WARNING])
|
||||
{
|
||||
if (CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, warning_directive))
|
||||
cpp_error (pfile, CPP_DL_PEDWARN,
|
||||
"#%s before C2X is a GCC extension", dir->name);
|
||||
{
|
||||
if (CPP_OPTION (pfile, cplusplus))
|
||||
cpp_error (pfile, CPP_DL_PEDWARN,
|
||||
"#%s before C++23 is a GCC extension", dir->name);
|
||||
else
|
||||
cpp_error (pfile, CPP_DL_PEDWARN,
|
||||
"#%s before C2X is a GCC extension", dir->name);
|
||||
}
|
||||
else if (CPP_OPTION (pfile, cpp_warn_c11_c2x_compat) > 0)
|
||||
cpp_warning (pfile, CPP_W_C11_C2X_COMPAT,
|
||||
"#%s before C2X is a GCC extension", dir->name);
|
||||
|
|
|
@ -123,8 +123,8 @@ static const struct lang_flags lang_defaults[] =
|
|||
/* CXX17 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0 },
|
||||
/* GNUCXX20 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0 },
|
||||
/* CXX20 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0 },
|
||||
/* GNUCXX23 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1 },
|
||||
/* CXX23 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1 },
|
||||
/* GNUCXX23 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1 },
|
||||
/* CXX23 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1 },
|
||||
/* ASM */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue