Bug 85672 - [9 Regression] error: redefinition of 'constexpr long double std::abs(long double)'
Summary: [9 Regression] error: redefinition of 'constexpr long double std::abs(long do...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: 9.0
Assignee: Not yet assigned to anyone
URL:
Keywords: build
: 88078 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-05-06 15:01 UTC by John David Anglin
Modified: 2018-11-19 09:28 UTC (History)
3 users (show)

See Also:
Host: hppa2.0w-hp-hpux11.11
Target: hppa2.0w-hp-hpux11.11
Build: hppa2.0w-hp-hpux11.11
Known to work: 8.1.0
Known to fail: 9.0
Last reconfirmed: 2018-05-07 00:00:00


Attachments
Restore previous behaviour of #undef _GLIBCXX_USE_FLOAT128 based on configure checks. (676 bytes, patch)
2018-05-07 19:39 UTC, Jonathan Wakely
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John David Anglin 2018-05-06 15:01:43 UTC
libtool: compile:  /test/gnu/gcc/objdir/./gcc/xgcc -shared-libgcc -B/test/gnu/gc
c/objdir/./gcc -nostdinc++ -L/test/gnu/gcc/objdir/hppa2.0w-hp-hpux11.11/libstdc+
+-v3/src -L/test/gnu/gcc/objdir/hppa2.0w-hp-hpux11.11/libstdc++-v3/src/.libs -L/
test/gnu/gcc/objdir/hppa2.0w-hp-hpux11.11/libstdc++-v3/libsupc++/.libs -B/opt/gn
u/gcc/gcc-9/hppa2.0w-hp-hpux11.11/bin/ -B/opt/gnu/gcc/gcc-9/hppa2.0w-hp-hpux11.1
1/lib/ -isystem /opt/gnu/gcc/gcc-9/hppa2.0w-hp-hpux11.11/include -isystem /opt/g
nu/gcc/gcc-9/hppa2.0w-hp-hpux11.11/sys-include -fno-checking -I/test/gnu/gcc/gcc
/libstdc++-v3/../libgcc -I/test/gnu/gcc/objdir/hppa2.0w-hp-hpux11.11/libstdc++-v
3/include/hppa2.0w-hp-hpux11.11 -I/test/gnu/gcc/objdir/hppa2.0w-hp-hpux11.11/lib
stdc++-v3/include -I/test/gnu/gcc/gcc/libstdc++-v3/libsupc++ -D_GLIBCXX_SHARED -
fno-implicit-templates -Wall -Wextra -Wwrite-strings -Wcast-qual -Wabi -fdiagnos
tics-show-location=once -frandom-seed=atexit_thread.lo -g -O2 -c ../../../../gcc
/libstdc++-v3/libsupc++/atexit_thread.cc  -fPIC -DPIC -D_GLIBCXX_SHARED -o atexi
t_thread.o
In file included from /test/gnu/gcc/objdir/hppa2.0w-hp-hpux11.11/libstdc++-v3/include/cstdlib:77,
                 from ../../../../gcc/libstdc++-v3/libsupc++/atexit_thread.cc:25:
/test/gnu/gcc/objdir/hppa2.0w-hp-hpux11.11/libstdc++-v3/include/bits/std_abs.h:102:3: error: redefinition of 'constexpr long double std::abs(long double)'
   abs(__float128 __x)
   ^~~
/test/gnu/gcc/objdir/hppa2.0w-hp-hpux11.11/libstdc++-v3/include/bits/std_abs.h:78:3: note: 'constexpr long double std::abs(long double)' previously defined here
   abs(long double __x)
   ^~~
In file included from /test/gnu/gcc/objdir/hppa2.0w-hp-hpux11.11/libstdc++-v3/include/bits/move.h:55,
                 from /test/gnu/gcc/objdir/hppa2.0w-hp-hpux11.11/libstdc++-v3/include/bits/nested_exception.h:40,
                 from /test/gnu/gcc/gcc/libstdc++-v3/libsupc++/exception:144,
                 from /test/gnu/gcc/gcc/libstdc++-v3/libsupc++/new:40,
                 from ../../../../gcc/libstdc++-v3/libsupc++/atexit_thread.cc:26:
/test/gnu/gcc/objdir/hppa2.0w-hp-hpux11.11/libstdc++-v3/include/type_traits:347:12: error: redefinition of 'struct std::__is_floating_point_helper<long double>'
     struct __is_floating_point_helper<__float128>
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/test/gnu/gcc/objdir/hppa2.0w-hp-hpux11.11/libstdc++-v3/include/type_traits:342:12: note: previous definition of 'struct std::__is_floating_point_helper<long double>'
     struct __is_floating_point_helper<long double>
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Comment 1 Marc Glisse 2018-05-06 16:40:43 UTC
I think there is an inconsistency where we #define _GLIBCXX_USE_FLOAT128 0 (can you check your c++config.h?) to say that it shouldn't be supported, but then test with #ifdef and not #if.
Comment 2 John David Anglin 2018-05-06 16:59:29 UTC
The config file looks like this:

/* Define if __float128 is supported on this host. */
# define _GLIBCXX_USE_FLOAT128 0
#if !defined(__FLOAT128__) && !defined(__SIZEOF_FLOAT128__)
#undef _GLIBCXX_USE_FLOAT128
#endif

I think __FLOAT128__ and __SIZEOF_FLOAT128__ are defined because we have:

      /* Under HPUX, the __float128 type is a synonym for "long double".  */
      (*lang_hooks.types.register_builtin_type) (long_double_type_node,
                                                 "__float128");
Comment 3 Jonathan Wakely 2018-05-07 12:16:00 UTC
Yes it woud have been broken by r259813 and this should fix it:

--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -342,7 +342,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     struct __is_floating_point_helper<long double>
     : public true_type { };
 
-#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
+#if !defined(__STRICT_ANSI__) && _GLIBCXX_USE_FLOAT128
   template<>
     struct __is_floating_point_helper<__float128>
     : public true_type { };
Comment 4 Marc Glisse 2018-05-07 12:25:16 UTC
(In reply to Jonathan Wakely from comment #3)
> Yes it woud have been broken by r259813 and this should fix it:

I don't think that's sufficient:
- the same code is present in several files
- -Wsystem-headers -Wundef will warn
- it still leaves a weird situation where _GLIBCXX_USE_FLOAT128 may be 1, 0 or undefined, instead of just 2 choices.
Comment 5 Jonathan Wakely 2018-05-07 12:39:11 UTC
(In reply to Marc Glisse from comment #4)
> (In reply to Jonathan Wakely from comment #3)
> > Yes it woud have been broken by r259813 and this should fix it:
> 
> I don't think that's sufficient:
> - the same code is present in several files

Only two.

include/bits/std_abs.h and include/std/type_traits


> - -Wsystem-headers -Wundef will warn

That's the status quo. It would take a ton of effort to avoid -Wundef warnings in libstdc++ and that's not something I'm going to work on.


> - it still leaves a weird situation where _GLIBCXX_USE_FLOAT128 may be 1, 0
> or undefined, instead of just 2 choices.

Ah yes, good point. So we could either change include/Makefile.am to #undef it instead of setting it to 0, or do:

--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -611,7 +611,10 @@ namespace std
 
 /* Define if __float128 is supported on this host. */
 #define _GLIBCXX_USE_FLOAT128
-#if !defined(__FLOAT128__) && !defined(__SIZEOF_FLOAT128__)
+#if _GLIBCXX_USE_FLOAT128 == 0
+#undef _GLIBCXX_USE_FLOAT128
+#endif
+#elif !defined(__FLOAT128__) && !defined(__SIZEOF_FLOAT128__)
 #undef _GLIBCXX_USE_FLOAT128
 #endif
 

I think I'd prefer to change include/Makefile.am

Then no changes to <bits/std_abs.h> and <type_traits> would be needed.
Comment 6 Jonathan Wakely 2018-05-07 12:49:28 UTC
(In reply to Jonathan Wakely from comment #5)
> (In reply to Marc Glisse from comment #4)
> > - -Wsystem-headers -Wundef will warn
> 
> That's the status quo. It would take a ton of effort to avoid -Wundef
> warnings in libstdc++ and that's not something I'm going to work on.

In other words, don't use -Wsystem-headers -Wundef
Comment 7 Marc Glisse 2018-05-07 13:03:18 UTC
(In reply to Jonathan Wakely from comment #5)
> > - -Wsystem-headers -Wundef will warn
> 
> That's the status quo. It would take a ton of effort to avoid -Wundef
> warnings in libstdc++ and that's not something I'm going to work on.

I was only listing it as a way to introduce the next point, you can forget it.

> > - it still leaves a weird situation where _GLIBCXX_USE_FLOAT128 may be 1, 0
> > or undefined, instead of just 2 choices.
> 
> Ah yes, good point. So we could either change include/Makefile.am to #undef
> it instead of setting it to 0, or do:
> 
> --- a/libstdc++-v3/include/bits/c++config
> +++ b/libstdc++-v3/include/bits/c++config
> @@ -611,7 +611,10 @@ namespace std
>  
>  /* Define if __float128 is supported on this host. */
>  #define _GLIBCXX_USE_FLOAT128
> -#if !defined(__FLOAT128__) && !defined(__SIZEOF_FLOAT128__)
> +#if _GLIBCXX_USE_FLOAT128 == 0
> +#undef _GLIBCXX_USE_FLOAT128
> +#endif
> +#elif !defined(__FLOAT128__) && !defined(__SIZEOF_FLOAT128__)
>  #undef _GLIBCXX_USE_FLOAT128
>  #endif
>  
> 
> I think I'd prefer to change include/Makefile.am
> 
> Then no changes to <bits/std_abs.h> and <type_traits> would be needed.

Yes, or maybe don't generate #define _GLIBCXX_USE_FLOAT128 0 but instead /* #undef _GLIBCXX_USE_FLOAT128 */ as we used to do and as the rest of the c++config.h file does. Actually, I am not sure why r259813 needed to change so many things...
Comment 8 Jonathan Wakely 2018-05-07 19:05:23 UTC
(In reply to Marc Glisse from comment #7)
> Yes, or maybe don't generate #define _GLIBCXX_USE_FLOAT128 0 but instead /*
> #undef _GLIBCXX_USE_FLOAT128 */ as we used to do and as the rest of the
> c++config.h file does.

All of those are auto-generated. The custom logic for the float128 macro isn't auto-generated.

> Actually, I am not sure why r259813 needed to change
> so many things...

Because changing /* #undef _GLIBCXX_USE_FLOAT128 */ to a #define was done by autoconf, and that gets automatically added at the end of the c++config file after any manual alterations. The new logic that does:

#if defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)
#undef _GLIBCXX_USE_FLOAT128
#endif

comes before the automatically added parts.

My autotools-fu is too weak to come up with anything better but I'd be very happy if you can suggest something cleaner.
Comment 9 Jonathan Wakely 2018-05-07 19:09:53 UTC
(In reply to Jonathan Wakely from comment #8)
> The new logic [...] comes before the automatically added parts.

And obviously you can't #undef something that hasn't been defined yet.
Comment 10 Jonathan Wakely 2018-05-07 19:39:19 UTC
Created attachment 44083 [details]
Restore previous behaviour of #undef _GLIBCXX_USE_FLOAT128 based on configure checks.

This still follows the same approach of custom logic instead of autogenerated macros, but restores the old behaviour when support is absent during configuration.
Comment 11 Marc Glisse 2018-05-08 11:10:32 UTC
(In reply to Jonathan Wakely from comment #8)
> My autotools-fu is too weak to come up with anything better but I'd be very
> happy if you can suggest something cleaner.

For the general case, the autoconf manual suggests having another file and using
AH_BOTTOM([#include <post.h>])
to get it included at the end of config.h.

However, in the specific case of c++config.h in libstdc++, we are building it manually in include/Makefile.am:

sed ... < ${glibcxx_srcdir}/include/bits/c++config > $@
sed ... < ${CONFIG_HEADER} >> $@
echo "" >> $@
echo "#endif // _GLIBCXX_CXX_CONFIG_H" >> $@

If we wanted to, it wouldn't be hard to cat whatever >> $@ after CONFIG_HEADER.

Since you have something that works now, there is no need to change it, but we should keep this in mind for next time.
Comment 12 Jonathan Wakely 2018-05-08 11:13:06 UTC
Thanks for the suggestion, it would clean up a few things in c++config so I'll move to that next time, instead of adding another hack.
Comment 13 Jonathan Wakely 2018-05-08 13:05:36 UTC
Author: redi
Date: Tue May  8 13:05:04 2018
New Revision: 260043

URL: https://gcc.gnu.org/viewcvs?rev=260043&root=gcc&view=rev
Log:
PR libstdc++/85672 #undef _GLIBCXX_USE_FLOAT128 when not supported

Restore the behaviour in GCC 8 and earlier where _GLIBCXX_USE_FLOAT128
is not defined when configure detects support is missing. This avoids
having three states where the macro is either 1, 0, or undefined.

	PR libstdc++/85672
	* include/Makefile.am [!ENABLE_FLOAT128]: Change c++config.h entry
	to #undef _GLIBCXX_USE_FLOAT128 instead of defining it to zero.
	* include/Makefile.in: Regenerate.
	* include/bits/c++config (_GLIBCXX_USE_FLOAT128): Move definition
	within conditional block.

Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/Makefile.am
    trunk/libstdc++-v3/include/Makefile.in
    trunk/libstdc++-v3/include/bits/c++config
Comment 14 Jonathan Wakely 2018-05-08 13:46:14 UTC
This should be fixed now.
Comment 15 Jonathan Wakely 2018-07-31 09:39:01 UTC
Author: redi
Date: Tue Jul 31 09:38:28 2018
New Revision: 263084

URL: https://gcc.gnu.org/viewcvs?rev=263084&root=gcc&view=rev
Log:
PR libstdc++/84654 Disable __float128 specializations for -mno-float128

Backport from mainline
2018-05-08  Jonathan Wakely  <jwakely@redhat.com>

	PR libstdc++/85672
	* include/Makefile.am [!ENABLE_FLOAT128]: Change c++config.h entry
	to #undef _GLIBCXX_USE_FLOAT128 instead of defining it to zero.
	* include/Makefile.in: Regenerate.
	* include/bits/c++config (_GLIBCXX_USE_FLOAT128): Move definition
	within conditional block.

Backport from mainline
2018-05-01  Tulio Magno Quites Machado Filho  <tuliom@linux.vnet.ibm.com>

	PR libstdc++/84654
	* acinclude.m4: Set ENABLE_FLOAT128 instead of _GLIBCXX_USE_FLOAT128.
	* config.h.in: Remove references to _GLIBCXX_USE_FLOAT128.
	* configure: Regenerate.
	* include/Makefile.am: Replace the value of _GLIBCXX_USE_FLOAT128
	based on ENABLE_FLOAT128.
	* include/Makefile.in: Regenerate.
	* include/bits/c++config: Define _GLIBCXX_USE_FLOAT128.
	[!defined(__FLOAT128__) && !defined(__SIZEOF_FLOAT128__)]: Undefine
	_GLIBCXX_USE_FLOAT128.

Modified:
    branches/gcc-8-branch/libstdc++-v3/ChangeLog
    branches/gcc-8-branch/libstdc++-v3/acinclude.m4
    branches/gcc-8-branch/libstdc++-v3/config.h.in
    branches/gcc-8-branch/libstdc++-v3/configure
    branches/gcc-8-branch/libstdc++-v3/include/Makefile.am
    branches/gcc-8-branch/libstdc++-v3/include/Makefile.in
    branches/gcc-8-branch/libstdc++-v3/include/bits/c++config
Comment 16 Jonathan Wakely 2018-08-07 22:51:22 UTC
Author: redi
Date: Tue Aug  7 22:50:49 2018
New Revision: 263382

URL: https://gcc.gnu.org/viewcvs?rev=263382&root=gcc&view=rev
Log:
PR libstdc++/84654 Disable __float128 specializations for -mno-float128

Backport from mainline
2018-05-08  Jonathan Wakely  <jwakely@redhat.com>

	PR libstdc++/85672
	* include/Makefile.am [!ENABLE_FLOAT128]: Change c++config.h entry
	to #undef _GLIBCXX_USE_FLOAT128 instead of defining it to zero.
	* include/Makefile.in: Regenerate.
	* include/bits/c++config (_GLIBCXX_USE_FLOAT128): Move definition
	within conditional block.

Backport from mainline
2018-05-01  Tulio Magno Quites Machado Filho  <tuliom@linux.vnet.ibm.com>

	PR libstdc++/84654
	* acinclude.m4: Set ENABLE_FLOAT128 instead of _GLIBCXX_USE_FLOAT128.
	* config.h.in: Remove references to _GLIBCXX_USE_FLOAT128.
	* configure: Regenerate.
	* include/Makefile.am: Replace the value of _GLIBCXX_USE_FLOAT128
	based on ENABLE_FLOAT128.
	* include/Makefile.in: Regenerate.
	* include/bits/c++config: Define _GLIBCXX_USE_FLOAT128.
	[!defined(__FLOAT128__) && !defined(__SIZEOF_FLOAT128__)]: Undefine
	_GLIBCXX_USE_FLOAT128.

Modified:
    branches/gcc-7-branch/libstdc++-v3/ChangeLog
    branches/gcc-7-branch/libstdc++-v3/acinclude.m4
    branches/gcc-7-branch/libstdc++-v3/config.h.in
    branches/gcc-7-branch/libstdc++-v3/configure
    branches/gcc-7-branch/libstdc++-v3/include/Makefile.am
    branches/gcc-7-branch/libstdc++-v3/include/Makefile.in
    branches/gcc-7-branch/libstdc++-v3/include/bits/c++config
Comment 17 Jonathan Wakely 2018-11-19 09:28:54 UTC
*** Bug 88078 has been marked as a duplicate of this bug. ***