libc6-dev:amd64 (2.26-0ubuntu2) has unusable signbit for C++ programs

Bug #1725869 reported by Andrew Paxie
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
glibc (Ubuntu)
New
Undecided
Unassigned

Bug Description

Environment
-----------

Test program compiled on Artful Aardvark Ubuntu 17.10.

$ which g++-4.8
/usr/bin/g++-4.8

$ /usr/bin/g++-4.8 --version
g++-4.8 (Ubuntu 4.8.5-4ubuntu6) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ which g++-4.9
/usr/bin/g++-4.9

$ /usr/bin/g++-4.9 --version
g++-4.9 (Ubuntu 4.9.4-2ubuntu1) 4.9.4
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ which g++-5
/usr/bin/g++-5

$ /usr/bin/g++-5 --version
g++-5 (Ubuntu 5.5.0-1ubuntu1) 5.4.1 20171010
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ which g++-6
/usr/bin/g++-6

$ /usr/bin/g++-6 --version
g++-6 (Ubuntu 6.4.0-8ubuntu1) 6.4.0 20171010
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ which g++-7
/usr/bin/g++-7

$ /usr/bin/g++-7 --version
g++-7 (Ubuntu 7.2.0-8ubuntu3) 7.2.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ dpkg --status libc6-dev:amd64
Package: libc6-dev
Status: install ok installed
Priority: optional
Section: libdevel
Installed-Size: 18041
Maintainer: Ubuntu Developers <email address hidden>
Architecture: amd64
Multi-Arch: same
Source: glibc
Version: 2.26-0ubuntu2
Provides: libc-dev
Depends: libc6 (= 2.26-0ubuntu2), libc-dev-bin (= 2.26-0ubuntu2), linux-libc-dev (>= 4.13.0)
Suggests: glibc-doc, manpages-dev
Breaks: binutils (<< 2.26), binutils-gold (<< 2.20.1-11), cmake (<< 2.8.4+dfsg.1-5), gcc-4.4 (<< 4.4.6-4), gcc-4.5 (<< 4.5.3-2), gcc-4.6 (<< 4.6.0-12), libhwloc-dev (<< 1.2-3), libjna-java (<< 3.2.7-4), liblouis-dev (<< 2.3.0-2), liblouisxml-dev (<< 2.4.0-2), make (<< 3.81-8.1), pkg-config (<< 0.26-1)
Conflicts: libc0.1-dev, libc0.3-dev, libc6.1-dev
Description: GNU C Library: Development Libraries and Header Files
 Contains the symlinks, headers, and object files needed to compile
 and link programs which use the standard C library.
Homepage: http://www.gnu.org/software/libc/libc.html
Original-Maintainer: GNU Libc Maintainers <email address hidden>

Test cases that fail
--------------------

$ g++-5 -x c++ - <<EOF
#include <math.h>
int main()
{
  return signbit(1.0);
}
EOF

In file included from <stdin>:1:0:
<stdin>: In function ‘int main()’:
<stdin>:4:10: error: expected primary-expression before ‘__typeof’
<stdin>:4:10: error: expected primary-expression before ‘float’
<stdin>:4:10: error: ‘__builtin_types_compatible_p’ was not declared in this scope
<stdin>:4:10: error: expected primary-expression before ‘__typeof’
<stdin>:4:10: error: expected primary-expression before ‘double’
<stdin>:4:10: error: expected primary-expression before ‘__typeof’
<stdin>:4:10: error: expected primary-expression before ‘long’
<stdin>:4:10: error: ‘__builtin_choose_expr’ was not declared in this scope
<stdin>:4:10: error: ‘__builtin_choose_expr’ was not declared in this scope
<stdin>:4:10: error: redeclaration of ‘<typeprefixerror>__builtin_choose_expr’
<stdin>:4:10: note: previous declaration ‘<typeprefixerror>__builtin_choose_expr’
<stdin>:4:10: error: ‘__builtin_choose_expr’ was not declared in this scope
<stdin>:4:10: error: redeclaration of ‘<typeprefixerror>__builtin_choose_expr’
<stdin>:4:10: note: previous declaration ‘<typeprefixerror>__builtin_choose_expr’

$ g++-4.9 -x c++ - <<EOF
#include <math.h>
int main()
{
  return signbit(1.0);
}
EOF

In file included from <stdin>:1:0:
<stdin>: In function ‘int main()’:
<stdin>:4:10: error: expected primary-expression before ‘__typeof’
<stdin>:4:10: error: expected primary-expression before ‘float’
<stdin>:4:10: error: ‘__builtin_types_compatible_p’ was not declared in this scope
<stdin>:4:10: error: expected primary-expression before ‘__typeof’
<stdin>:4:10: error: expected primary-expression before ‘double’
<stdin>:4:10: error: expected primary-expression before ‘__typeof’
<stdin>:4:10: error: expected primary-expression before ‘long’
<stdin>:4:10: error: ‘__builtin_choose_expr’ was not declared in this scope
<stdin>:4:10: error: ‘__builtin_choose_expr’ was not declared in this scope
<stdin>:4:10: error: redeclaration of ‘<typeprefixerror>__builtin_choose_expr’
<stdin>:4:10: note: previous declaration ‘<typeprefixerror>__builtin_choose_expr’
<stdin>:4:10: error: ‘__builtin_choose_expr’ was not declared in this scope
<stdin>:4:10: error: redeclaration of ‘<typeprefixerror>__builtin_choose_expr’
<stdin>:4:10: note: previous declaration ‘<typeprefixerror>__builtin_choose_expr’

$ g++-4.8 -x c++ - <<EOF
#include <math.h>
int main()
{
  return signbit(1.0);
}
EOF

In file included from <stdin>:1:0:
<stdin>: In function ‘int main()’:
<stdin>:4:10: error: expected primary-expression before ‘__typeof’
<stdin>:4:10: error: expected primary-expression before ‘float’
<stdin>:4:10: error: ‘__builtin_types_compatible_p’ was not declared in this scope
<stdin>:4:10: error: expected primary-expression before ‘__typeof’
<stdin>:4:10: error: expected primary-expression before ‘double’
<stdin>:4:10: error: expected primary-expression before ‘__typeof’
<stdin>:4:10: error: expected primary-expression before ‘long’
<stdin>:4:10: error: ‘__builtin_choose_expr’ was not declared in this scope
<stdin>:4:10: error: ‘__builtin_choose_expr’ was not declared in this scope
<stdin>:4:10: error: redeclaration of ‘<typeprefixerror>__builtin_choose_expr’
<stdin>:4:10: note: previous declaration ‘<typeprefixerror>__builtin_choose_expr’
<stdin>:4:10: error: ‘__builtin_choose_expr’ was not declared in this scope
<stdin>:4:10: error: redeclaration of ‘<typeprefixerror>__builtin_choose_expr’
<stdin>:4:10: note: previous declaration ‘<typeprefixerror>__builtin_choose_expr’

Test cases that succeed
-----------------------

$ g++-6 -x c++ - <<EOF
#include <math.h>
int main()
{
  return signbit(1.0);
}
EOF

$ g++-7 -x c++ - <<EOF
#include <math.h>
int main()
{
  return signbit(1.0);
}
EOF

Expected result
---------------

Successful compile and return 0.

Supposed cause
--------------

The definition of function-like macro __MATH_TG at
lines 343-74 of /usr/include/math.h
requires some finesse to handle C++ programs.

As noted in

gcc.gnu.org, "6.59 Other Built-in Functions Provided by GCC"
Available: https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
Accessed: 22 October 2017

the built-in functions __builtin_choose_expr and __builtin_types_compatible_p
are only available in C.

Workaround
----------

Hack /usr/include/math.h and modify line 346

#elif __HAVE_DISTINCT_FLOAT128

to read

#elif __HAVE_DISTINCT_FLOAT128 && !__cplusplus

This clearly doesn't cover all the cases but you get the picture.

Revision history for this message
Andrew Paxie (andrewpaxie) wrote :

Contacted <email address hidden> with details of this bug report.

They already had this bug report

"Bug 22296 - glibc 2.26: signbit build issue with Gcc 5.5.0 on x86_64"
https://sourceware.org/bugzilla/show_bug.cgi?id=22296

filed and fixed. May it be quickly cherry-picked and applied to
glibc 2.26 on Ubuntu Artful Aardvark.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.