public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH v2] c-family: Enable -fpermissive for C and ObjC
@ 2023-11-06 14:06 Florian Weimer
  2023-11-06 14:11 ` Jakub Jelinek
  0 siblings, 1 reply; 5+ messages in thread
From: Florian Weimer @ 2023-11-06 14:06 UTC (permalink / raw)
  To: gcc-patches

Future changes will treat some C front end warnings similar to
-Wnarrowing.

gcc/

	* doc/invoke.texi (Warning Options): Mention C diagnostics
	for -fpermissive.

gcc/c-family/

	* c.opt (fpermissive): Enable for C and ObjC.
	* c-opts.cc (set_std_c89): Enable -fpermissive.

---
v2: Rebased after David's m_* member changes.  Still no test suite
    regressions.  Actual tests will need some C permerrors, which
    we do not yet have.

 gcc/c-family/c-opts.cc | 6 ++++++
 gcc/c-family/c.opt     | 2 +-
 gcc/doc/invoke.texi    | 8 ++++++--
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc
index a980912f7e1..dbf92be9698 100644
--- a/gcc/c-family/c-opts.cc
+++ b/gcc/c-family/c-opts.cc
@@ -1711,6 +1711,12 @@ set_std_c89 (int c94, int iso)
   flag_isoc99 = 0;
   flag_isoc11 = 0;
   flag_isoc2x = 0;
+  /* -std=gnu89 etc. should not override -pedantic-errors.  */
+  if (!global_dc->m_pedantic_errors)
+    {
+      flag_permissive = 1;
+      global_dc->m_permissive = 1;
+    }
   lang_hooks.name = "GNU C89";
 }
 
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 29d3d789a49..cc3a6610148 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -2112,7 +2112,7 @@ C ObjC C++ ObjC++
 Look for and use PCH files even when preprocessing.
 
 fpermissive
-C++ ObjC++ Var(flag_permissive)
+C ObjC C++ ObjC++ Var(flag_permissive)
 Downgrade conformance errors to warnings.
 
 fplan9-extensions
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 6e776a0faa1..dfa01220b93 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -6170,13 +6170,17 @@ errors by @option{-pedantic-errors}.  For instance:
 Downgrade some required diagnostics about nonconformant code from
 errors to warnings.  Thus, using @option{-fpermissive} allows some
 nonconforming code to compile.  Some C++ diagnostics are controlled
-only by this flag, but it also downgrades some diagnostics that have
-their own flag:
+only by this flag, but it also downgrades some C and C++ diagnostics
+that have their own flag:
 
 @gccoptlist{
 -Wnarrowing @r{(C++)}
 }
 
+The @option{-fpermissive} option is the default for historic C language
+modes (@option{-std=c89}, @option{-std=gnu89}, @option{-std=c90},
+@option{-std=gnu90}).
+
 @opindex Wall
 @opindex Wno-all
 @item -Wall

base-commit: 3cc9ad41db87fb85b13a56bff1f930c258542a70


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] c-family: Enable -fpermissive for C and ObjC
  2023-11-06 14:06 [PATCH v2] c-family: Enable -fpermissive for C and ObjC Florian Weimer
@ 2023-11-06 14:11 ` Jakub Jelinek
  2023-11-06 14:19   ` Florian Weimer
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Jelinek @ 2023-11-06 14:11 UTC (permalink / raw)
  To: Florian Weimer; +Cc: gcc-patches

On Mon, Nov 06, 2023 at 03:06:39PM +0100, Florian Weimer wrote:
> Future changes will treat some C front end warnings similar to
> -Wnarrowing.
> 
> gcc/
> 
> 	* doc/invoke.texi (Warning Options): Mention C diagnostics
> 	for -fpermissive.
> 
> gcc/c-family/
> 
> 	* c.opt (fpermissive): Enable for C and ObjC.
> 	* c-opts.cc (set_std_c89): Enable -fpermissive.

Won't this set flag_permissive even for -std=c89 -std=c99 ?
Haven't tried, but if set_std_c* is called multiple times if more than
one -std= option appears, then perhaps this should be done later after
processing all options, not during that processing.

	Jakub


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] c-family: Enable -fpermissive for C and ObjC
  2023-11-06 14:11 ` Jakub Jelinek
@ 2023-11-06 14:19   ` Florian Weimer
  2023-11-06 14:31     ` Jakub Jelinek
  0 siblings, 1 reply; 5+ messages in thread
From: Florian Weimer @ 2023-11-06 14:19 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

* Jakub Jelinek:

> On Mon, Nov 06, 2023 at 03:06:39PM +0100, Florian Weimer wrote:
>> Future changes will treat some C front end warnings similar to
>> -Wnarrowing.
>> 
>> gcc/
>> 
>> 	* doc/invoke.texi (Warning Options): Mention C diagnostics
>> 	for -fpermissive.
>> 
>> gcc/c-family/
>> 
>> 	* c.opt (fpermissive): Enable for C and ObjC.
>> 	* c-opts.cc (set_std_c89): Enable -fpermissive.
>
> Won't this set flag_permissive even for -std=c89 -std=c99 ?
> Haven't tried, but if set_std_c* is called multiple times if more than
> one -std= option appears, then perhaps this should be done later after
> processing all options, not during that processing.

Ugh, you are right.

What would be the right place to do this kind of final option
processing?  Where those SET_OPTION_IF_UNSET are?

Thanks,
Florian


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] c-family: Enable -fpermissive for C and ObjC
  2023-11-06 14:19   ` Florian Weimer
@ 2023-11-06 14:31     ` Jakub Jelinek
  2023-11-06 15:42       ` Florian Weimer
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Jelinek @ 2023-11-06 14:31 UTC (permalink / raw)
  To: Florian Weimer; +Cc: gcc-patches

On Mon, Nov 06, 2023 at 03:19:32PM +0100, Florian Weimer wrote:
> * Jakub Jelinek:
> 
> > On Mon, Nov 06, 2023 at 03:06:39PM +0100, Florian Weimer wrote:
> >> Future changes will treat some C front end warnings similar to
> >> -Wnarrowing.
> >> 
> >> gcc/
> >> 
> >> 	* doc/invoke.texi (Warning Options): Mention C diagnostics
> >> 	for -fpermissive.
> >> 
> >> gcc/c-family/
> >> 
> >> 	* c.opt (fpermissive): Enable for C and ObjC.
> >> 	* c-opts.cc (set_std_c89): Enable -fpermissive.
> >
> > Won't this set flag_permissive even for -std=c89 -std=c99 ?
> > Haven't tried, but if set_std_c* is called multiple times if more than
> > one -std= option appears, then perhaps this should be done later after
> > processing all options, not during that processing.
> 
> Ugh, you are right.
> 
> What would be the right place to do this kind of final option
> processing?  Where those SET_OPTION_IF_UNSET are?

c_common_post_options ?
Generally, we have global_options, which are the values of the options
(implicit or explicit) and then another variable of the same type,
global_options_set, which uses all values just as booleans whether the
option was set explicitly or not.

	Jakub


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] c-family: Enable -fpermissive for C and ObjC
  2023-11-06 14:31     ` Jakub Jelinek
@ 2023-11-06 15:42       ` Florian Weimer
  0 siblings, 0 replies; 5+ messages in thread
From: Florian Weimer @ 2023-11-06 15:42 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

* Jakub Jelinek:

> On Mon, Nov 06, 2023 at 03:19:32PM +0100, Florian Weimer wrote:
>> * Jakub Jelinek:
>> 
>> > On Mon, Nov 06, 2023 at 03:06:39PM +0100, Florian Weimer wrote:
>> >> Future changes will treat some C front end warnings similar to
>> >> -Wnarrowing.
>> >> 
>> >> gcc/
>> >> 
>> >> 	* doc/invoke.texi (Warning Options): Mention C diagnostics
>> >> 	for -fpermissive.
>> >> 
>> >> gcc/c-family/
>> >> 
>> >> 	* c.opt (fpermissive): Enable for C and ObjC.
>> >> 	* c-opts.cc (set_std_c89): Enable -fpermissive.
>> >
>> > Won't this set flag_permissive even for -std=c89 -std=c99 ?
>> > Haven't tried, but if set_std_c* is called multiple times if more than
>> > one -std= option appears, then perhaps this should be done later after
>> > processing all options, not during that processing.
>> 
>> Ugh, you are right.
>> 
>> What would be the right place to do this kind of final option
>> processing?  Where those SET_OPTION_IF_UNSET are?
>
> c_common_post_options ?
> Generally, we have global_options, which are the values of the options
> (implicit or explicit) and then another variable of the same type,
> global_options_set, which uses all values just as booleans whether the
> option was set explicitly or not.

Yes, c_common_post_options seems to work.  Thanks for the hint regarding
global_options_set.  I can use it to make -std=gnu89 -fno-permissive do
something useful.  I'm going to send an update patch.

Florian


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-11-06 15:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-06 14:06 [PATCH v2] c-family: Enable -fpermissive for C and ObjC Florian Weimer
2023-11-06 14:11 ` Jakub Jelinek
2023-11-06 14:19   ` Florian Weimer
2023-11-06 14:31     ` Jakub Jelinek
2023-11-06 15:42       ` Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).