From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 743C73858D20; Tue, 15 Feb 2022 14:02:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 743C73858D20 From: "austinpmorton at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/85487] Support '#pragma region' and '#pragma endregion' to allow code folding with Visual Studio Date: Tue, 15 Feb 2022 14:02:51 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 8.0.1 X-Bugzilla-Keywords: easyhack X-Bugzilla-Severity: enhancement X-Bugzilla-Who: austinpmorton at gmail dot com X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Feb 2022 14:02:51 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D85487 --- Comment #5 from Austin Morton --- (In reply to Jonathan Wakely from comment #3) > The docs raise some questions. >=20 > They say that a #pragma region must be ended by a #pragma endregion. Shou= ld > the compiler check that and issue a diagnostic otherwise? >=20 > What is the form of the optional "name" that follows #pragma region? >=20 > What if #pragma endregion is followed by preprocessor tokens, not just a > comment? >=20 > If we don't care about validating anything, it's easy to make GCC complet= ely > ignore those pragmas: >=20 > --- a/gcc/c-family/c-pragma.cc > +++ b/gcc/c-family/c-pragma.cc > @@ -1218,6 +1218,15 @@ handle_pragma_message (cpp_reader *ARG_UNUSED(dumm= y)) > TREE_STRING_POINTER (message)); > } >=20=20 > +/* Ignore a no-op pragma that GCC recognizes, but which has no effect. = */ > +static void > +handle_pragma_ignore (cpp_reader *) > +{ > + tree x; > + while (pragma_lex (&x) !=3D CPP_EOF) > + /* Ignore the rest of the line. */; > +} > + > /* Mark whether the current location is valid for a STDC pragma. */ >=20=20 > static bool valid_location_for_stdc_pragma; > @@ -1633,6 +1642,9 @@ init_pragma (void) > c_register_pragma ("GCC", "pop_options", handle_pragma_pop_options); > c_register_pragma ("GCC", "reset_options", handle_pragma_reset_options= ); >=20=20 > + c_register_pragma (0, "region", handle_pragma_ignore); > + c_register_pragma (0, "endregion", handle_pragma_ignore); > + > c_register_pragma ("STDC", "FLOAT_CONST_DECIMAL64", > handle_pragma_float_const_decimal64); >=20=20 >=20 >=20 > This needs tests though. https://gcc.gnu.org/pipermail/gcc-patches/2020-September/553182.html I sent a patch to do exactly that in 2020 and it was not accepted. This seems like a very easy win. Both major competitors to GCC (clang and MSVC) implement this pragma exactly like in my patch (by completely ignoring it). As it stands today, this is plainly a deficiency in GCC when compared to its competition.=