diff mbox

[C++] Fix option handling when -std=gnu++14 is not used (PR 69865)

Message ID 20160219122212.GD3017@tucnak.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Feb. 19, 2016, 12:22 p.m. UTC
Hi!

On Fri, Feb 19, 2016 at 12:59:45PM +0100, Jakub Jelinek wrote:
> Of course not, and that would be the wrong thing to do.
> The definition spot of libc_name_p comes from gperf itself, the prototype
> from cfns.gperf, which we can of course adjust.

This is related to
https://gcc.gnu.org/ml/gcc-patches/2015-08/msg00375.html
But, as we use it in a header, in C++ and don't provide an out of line
definition for it, we really don't want the gnu_inline attribute in this
case, because unlike in C, where gnu_inline attribute has one meaning when
applied to inline and another when applied to extern inline, in C++
it always means the extern inline GNU inline semantics.  And gperf clearly
wants the C inline __attribute__((gnu_inline)) semantics.
IMHO gperf should be fixed to only use __attribute__((gnu_inline)) for C++.

BTW, the prototypes aren't really needed anymore in cfns.gperf, we use it
in C++ only and C++ doesn't have -Wstrict-prototypes -Wmissing-prototypes.

So, for cfns.* I think we should use until gperf is fixed:

2016-02-19  Jakub Jelinek  <jakub@redhat.com>

	* cfns.gperf: Remove prototypes for hash and libc_name_p
	inlines.  Undefine __GNUC_STDC_INLINE__ and
	__GNUC_GNU_INLINE__ for C++.
	* cfns.h: Regenerated.


	Jakub

Comments

Jakub Jelinek Feb. 19, 2016, 12:26 p.m. UTC | #1
On Fri, Feb 19, 2016 at 01:22:12PM +0100, Jakub Jelinek wrote:
> wants the C inline __attribute__((gnu_inline)) semantics.
> IMHO gperf should be fixed to only use __attribute__((gnu_inline)) for C++.

For C of course.
Thus emit
#ifndef __cplusplus
#if defined __GNUC_STDC_INLINE__ || defined __GNUC_GNU_INLINE__
__attribute__ ((__gnu_inline__))
#endif
#endif
or something similar.

	Jakub
Bernd Edlinger Feb. 19, 2016, 1:07 p.m. UTC | #2
On 19.02.2016 13:22, Jakub Jelinek wrote:
> Hi!
>
> On Fri, Feb 19, 2016 at 12:59:45PM +0100, Jakub Jelinek wrote:
>> Of course not, and that would be the wrong thing to do.
>> The definition spot of libc_name_p comes from gperf itself, the prototype
>> from cfns.gperf, which we can of course adjust.
>
> This is related to
> https://gcc.gnu.org/ml/gcc-patches/2015-08/msg00375.html
> But, as we use it in a header, in C++ and don't provide an out of line
> definition for it, we really don't want the gnu_inline attribute in this
> case, because unlike in C, where gnu_inline attribute has one meaning when
> applied to inline and another when applied to extern inline, in C++
> it always means the extern inline GNU inline semantics.  And gperf clearly
> wants the C inline __attribute__((gnu_inline)) semantics.
> IMHO gperf should be fixed to only use __attribute__((gnu_inline)) for C++.
>
> BTW, the prototypes aren't really needed anymore in cfns.gperf, we use it
> in C++ only and C++ doesn't have -Wstrict-prototypes -Wmissing-prototypes.
>
> So, for cfns.* I think we should use until gperf is fixed:
>

Yeah, that is ugly, but we don't have any alternatives.
So please commit then I can continue with my new patch.

Thanks
Bernd.

> 2016-02-19  Jakub Jelinek  <jakub@redhat.com>
>
> 	* cfns.gperf: Remove prototypes for hash and libc_name_p
> 	inlines.  Undefine __GNUC_STDC_INLINE__ and
> 	__GNUC_GNU_INLINE__ for C++.
> 	* cfns.h: Regenerated.
>
> --- gcc/cp/cfns.gperf.jj	2016-01-04 14:55:57.000000000 +0100
> +++ gcc/cp/cfns.gperf	2016-02-19 13:16:50.374311181 +0100
> @@ -16,14 +16,13 @@ for more details.
>   You should have received a copy of the GNU General Public License
>   along with GCC; see the file COPYING3.  If not see
>   <http://www.gnu.org/licenses/>.  */
> -#ifdef __GNUC__
> -__inline
> +
> +/* Don't use gnu_inline attribute that gperf 3.0.3 and later emits
> +   for C++.  */
> +#if defined(__cplusplus) && defined(__GNUC__)
> +#  undef __GNUC_STDC_INLINE__
> +#  undef __GNUC_GNU_INLINE__
>   #endif
> -static unsigned int hash (const char *, unsigned int);
> -#ifdef __GNUC__
> -__inline
> -#endif
> -const char * libc_name_p (const char *, unsigned int);
>   %}
>   %%
>   # The standard C library functions, for feeding to gperf; the result is used
> --- gcc/cp/cfns.h.jj	2016-01-04 14:55:57.000000000 +0100
> +++ gcc/cp/cfns.h	2016-02-19 13:17:02.458142071 +0100
> @@ -1,4 +1,4 @@
> -/* ANSI-C code produced by gperf version 3.0.3 */
> +/* ANSI-C code produced by gperf version 3.0.4 */
>   /* Command-line: gperf -o -C -E -k '1-6,$' -j1 -D -N libc_name_p -L ANSI-C cfns.gperf  */
>
>   #if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
> @@ -47,14 +47,13 @@ for more details.
>   You should have received a copy of the GNU General Public License
>   along with GCC; see the file COPYING3.  If not see
>   <http://www.gnu.org/licenses/>.  */
> -#ifdef __GNUC__
> -__inline
> -#endif
> -static unsigned int hash (const char *, unsigned int);
> -#ifdef __GNUC__
> -__inline
> +
> +/* Don't use gnu_inline attribute that gperf 3.0.3 and later emits
> +   for C++.  */
> +#if defined(__cplusplus) && defined(__GNUC__)
> +#  undef __GNUC_STDC_INLINE__
> +#  undef __GNUC_GNU_INLINE__
>   #endif
> -const char * libc_name_p (const char *, unsigned int);
>   /* maximum key range = 391, duplicates = 0 */
>
>   #ifdef __GNUC__
> @@ -124,7 +123,7 @@ hash (register const char *str, register
>
>   #ifdef __GNUC__
>   __inline
> -#ifdef __GNUC_STDC_INLINE__
> +#if defined __GNUC_STDC_INLINE__ || defined __GNUC_GNU_INLINE__
>   __attribute__ ((__gnu_inline__))
>   #endif
>   #endif
>
> 	Jakub
>
diff mbox

Patch

--- gcc/cp/cfns.gperf.jj	2016-01-04 14:55:57.000000000 +0100
+++ gcc/cp/cfns.gperf	2016-02-19 13:16:50.374311181 +0100
@@ -16,14 +16,13 @@  for more details.
 You should have received a copy of the GNU General Public License
 along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
-#ifdef __GNUC__
-__inline
+
+/* Don't use gnu_inline attribute that gperf 3.0.3 and later emits
+   for C++.  */
+#if defined(__cplusplus) && defined(__GNUC__)
+#  undef __GNUC_STDC_INLINE__
+#  undef __GNUC_GNU_INLINE__
 #endif
-static unsigned int hash (const char *, unsigned int);
-#ifdef __GNUC__
-__inline
-#endif
-const char * libc_name_p (const char *, unsigned int);
 %}
 %%
 # The standard C library functions, for feeding to gperf; the result is used
--- gcc/cp/cfns.h.jj	2016-01-04 14:55:57.000000000 +0100
+++ gcc/cp/cfns.h	2016-02-19 13:17:02.458142071 +0100
@@ -1,4 +1,4 @@ 
-/* ANSI-C code produced by gperf version 3.0.3 */
+/* ANSI-C code produced by gperf version 3.0.4 */
 /* Command-line: gperf -o -C -E -k '1-6,$' -j1 -D -N libc_name_p -L ANSI-C cfns.gperf  */
 
 #if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
@@ -47,14 +47,13 @@  for more details.
 You should have received a copy of the GNU General Public License
 along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
-#ifdef __GNUC__
-__inline
-#endif
-static unsigned int hash (const char *, unsigned int);
-#ifdef __GNUC__
-__inline
+
+/* Don't use gnu_inline attribute that gperf 3.0.3 and later emits
+   for C++.  */
+#if defined(__cplusplus) && defined(__GNUC__)
+#  undef __GNUC_STDC_INLINE__
+#  undef __GNUC_GNU_INLINE__
 #endif
-const char * libc_name_p (const char *, unsigned int);
 /* maximum key range = 391, duplicates = 0 */
 
 #ifdef __GNUC__
@@ -124,7 +123,7 @@  hash (register const char *str, register
 
 #ifdef __GNUC__
 __inline
-#ifdef __GNUC_STDC_INLINE__
+#if defined __GNUC_STDC_INLINE__ || defined __GNUC_GNU_INLINE__
 __attribute__ ((__gnu_inline__))
 #endif
 #endif