diff --git a/gcc/testsuite/g++.dg/cpp/warning-1.C b/gcc/testsuite/g++.dg/cpp/warning-1.C new file mode 100644 index 0000000000000000000000000000000000000000..2d857cf747c9012889172af6a3b8110a186c9dec --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp/warning-1.C @@ -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 } diff --git a/gcc/testsuite/g++.dg/cpp/warning-2.C b/gcc/testsuite/g++.dg/cpp/warning-2.C new file mode 100644 index 0000000000000000000000000000000000000000..d6d5d9fc0813061f1837ad59ce1d7790dfc8e67a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp/warning-2.C @@ -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 } diff --git a/gcc/testsuite/g++.dg/cpp/warning-3.C b/gcc/testsuite/g++.dg/cpp/warning-3.C new file mode 100644 index 0000000000000000000000000000000000000000..1595b4d13053905c1d55590dd80c674472d8e9ad --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp/warning-3.C @@ -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 } diff --git a/libcpp/directives.cc b/libcpp/directives.cc index 802bd8c8bb5c6a2521cd78b87275f20f236a7173..918752f6b1f0f51a24df6ed246d01f90c6187880 100644 --- a/libcpp/directives.cc +++ b/libcpp/directives.cc @@ -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); diff --git a/libcpp/init.cc b/libcpp/init.cc index b184e1ffd995176eb2c7f00c3761ed56e653712f..39e7e75f010dcb687e76adc8ab99dfef9e14632e 100644 --- a/libcpp/init.cc +++ b/libcpp/init.cc @@ -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 } };