From a9f9391e1eeccb9d062b9e73ef27ac577b23ed64 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Sun, 15 Sep 2024 11:34:43 +0200 Subject: [PATCH] c++: __extension__ and -Wconditionally-supported 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 | 6 ++++++ gcc/testsuite/g++.dg/warn/Wconditionally-supported-1.C | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 3c8c75575b04..4dd9474cf609 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -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; diff --git a/gcc/testsuite/g++.dg/warn/Wconditionally-supported-1.C b/gcc/testsuite/g++.dg/warn/Wconditionally-supported-1.C index 3c32edba8cec..192d709fd799 100644 --- a/gcc/testsuite/g++.dg/warn/Wconditionally-supported-1.C +++ b/gcc/testsuite/g++.dg/warn/Wconditionally-supported-1.C @@ -22,4 +22,10 @@ void foo () pf = reinterpret_cast (po); // { dg-warning "8:casting between pointer-to-function and pointer-to-object is conditionally-supported" } po = reinterpret_cast (pf); // { dg-warning "8:casting between pointer-to-function and pointer-to-object is conditionally-supported" } + + pf = __extension__ reinterpret_cast (pv); + pv = __extension__ reinterpret_cast (pf); + + pf = __extension__ reinterpret_cast (po); + po = __extension__ reinterpret_cast (pf); } -- 2.47.2