]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: __extension__ and -Wconditionally-supported
authorJason Merrill <jason@redhat.com>
Sun, 15 Sep 2024 09:34:43 +0000 (11:34 +0200)
committerJason Merrill <jason@redhat.com>
Sun, 15 Sep 2024 15:49:07 +0000 (17:49 +0200)
When we're explicitly choosing GCC extensions, we similarly shouldn't
complain about optional features that GCC provides.  This particular pattern
of cast between function and object pointer is used by gthr-posix.h on some
targets, including linux-gnu before glibc 2.34.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_unary_expression) [RID_EXTENSION]: Also
suppress -Wconditionally-supported.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wconditionally-supported-1.C: Add __extension__ cases.

gcc/cp/parser.cc
gcc/testsuite/g++.dg/warn/Wconditionally-supported-1.C

index 3c8c75575b04fc2cc0142cb6a3ae1b3917d719d9..4dd9474cf609e22d076e4f7a2af0a74f10dc5791 100644 (file)
@@ -9150,9 +9150,15 @@ cp_parser_unary_expression (cp_parser *parser, cp_id_kind * pidk,
 
            /* Save away the PEDANTIC flag.  */
            cp_parser_extension_opt (parser, &saved_pedantic);
+           /* Also suppress -Wconditionally-supported.  */
+           diagnostic_push_diagnostics (global_dc, input_location);
+           diagnostic_classify_diagnostic
+             (global_dc, OPT_Wconditionally_supported,
+              DK_IGNORED, input_location);
            /* Parse the cast-expression.  */
            expr = cp_parser_simple_cast_expression (parser);
            /* Restore the PEDANTIC flag.  */
+           diagnostic_pop_diagnostics (global_dc, input_location);
            pedantic = saved_pedantic;
 
            return expr;
index 3c32edba8cecdc18771d29158e47ce2ccb159e18..192d709fd79909883be63a415d40c0e04ecc6cac 100644 (file)
@@ -22,4 +22,10 @@ void foo ()
 
   pf = reinterpret_cast <PF>(po); // { dg-warning "8:casting between pointer-to-function and pointer-to-object is conditionally-supported" }
   po = reinterpret_cast <PO>(pf); // { dg-warning "8:casting between pointer-to-function and pointer-to-object is conditionally-supported" }
+
+  pf = __extension__ reinterpret_cast <PF>(pv);
+  pv = __extension__ reinterpret_cast <PV>(pf);
+
+  pf = __extension__ reinterpret_cast <PF>(po);
+  po = __extension__ reinterpret_cast <PO>(pf);
 }