From d7c3000147c1d8090f66a2baf4623d2c0dfe8eb6 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Thu, 18 Aug 2022 23:01:01 +0000 Subject: preprocessor: Support #warning for standard C2x 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. Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/testsuite/ * gcc.dg/cpp/c11-warning-1.c, gcc.dg/cpp/c11-warning-2.c, gcc.dg/cpp/c11-warning-3.c, gcc.dg/cpp/c11-warning-4.c, gcc.dg/cpp/c2x-warning-1.c, gcc.dg/cpp/c2x-warning-2.c, gcc.dg/cpp/gnu11-warning-1.c, gcc.dg/cpp/gnu11-warning-2.c, gcc.dg/cpp/gnu11-warning-3.c, gcc.dg/cpp/gnu11-warning-4.c, gcc.dg/cpp/gnu2x-warning-1.c, gcc.dg/cpp/gnu2x-warning-2.c: New tests. libcpp/ * include/cpplib.h (struct cpp_options): Add warning_directive. * init.cc (struct lang_flags, lang_defaults): Add warning_directive. * directives.cc (DIRECTIVE_TABLE): Mark #warning as STDC2X not EXTENSION. (directive_diagnostics): Diagnose #warning with -Wc11-c2x-compat, or with -pedantic for a standard not supporting #warning. --- libcpp/directives.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'libcpp/directives.cc') diff --git a/libcpp/directives.cc b/libcpp/directives.cc index 4104d51..802bd8c 100644 --- a/libcpp/directives.cc +++ b/libcpp/directives.cc @@ -158,7 +158,7 @@ static void cpp_pop_definition (cpp_reader *, struct def_pragma_macro *); D(elifndef, T_ELIFNDEF, STDC2X, COND | ELIFDEF) \ D(error, T_ERROR, STDC89, 0) \ D(pragma, T_PRAGMA, STDC89, IN_I) \ - D(warning, T_WARNING, EXTENSION, 0) \ + D(warning, T_WARNING, STDC2X, 0) \ D(include_next, T_INCLUDE_NEXT, EXTENSION, INCL | EXPAND) \ D(ident, T_IDENT, EXTENSION, IN_I) \ D(import, T_IMPORT, EXTENSION, INCL | EXPAND) /* ObjC */ \ @@ -385,6 +385,15 @@ directive_diagnostics (cpp_reader *pfile, const directive *dir, int indented) && !(dir == &dtable[T_IMPORT] && CPP_OPTION (pfile, objc)) && CPP_PEDANTIC (pfile)) cpp_error (pfile, CPP_DL_PEDWARN, "#%s is a GCC extension", dir->name); + 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); + 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); + } else if (((dir->flags & DEPRECATED) != 0 || (dir == &dtable[T_IMPORT] && !CPP_OPTION (pfile, objc))) && CPP_OPTION (pfile, cpp_warn_deprecated)) -- cgit v1.1