https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91292

            Bug ID: 91292
           Summary: Mangler incorrectly handles negative numbers in
                    expressions
           Product: gcc
           Version: 9.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jorg.brown at gmail dot com
  Target Milestone: ---

Consider these four templated functions, each using an enable_if:

template<typename T>
typename std::enable_if<(int)sizeof(T) >= -(1), int>::type size1(T *t);

template<typename T>
typename std::enable_if<(int)sizeof(T) >= -1, int>::type size2(T *t);

template<typename T>
typename std::enable_if<(int)sizeof(T) >= -(1.), int>::type size3(T *t);

template<typename T>
typename std::enable_if<(int)sizeof(T) >= -1., int>::type size4(T *t);



According to http://itanium-cxx-abi.github.io/cxx-abi/abi.html#expressions , a
negative number isn't treated as a negative literal; it is a negated number. 
This means that it is mangled as though it were positive, and then its negation
is mangled.  So -1 and -(1) are treated the same.

Separately, if the number is a floating-point number, gcc seems to mangle them
all the same: into (double)[ffffffff00000000] , which is actually a NaN.

See https://godbolt.org/z/qIYbgQ for a repro using gcc 9.1.  Currently the four
routines above are mangled by gcc into: (after demangling)

std::enable_if<((int)(sizeof (int)))>=(-(1)), int>::type size1<int>(int*)
std::enable_if<((int)(sizeof (int)))>=(-1), int>::type size2<int>(int*)
std::enable_if<((int)(sizeof (int)))>=(-((double)[3ff0000000000000])),
int>::type size3<int>(int*)
std::enable_if<((int)(sizeof (int)))>=((double)[ffffffff00000000]), int>::type
size4<int>(int*)

Reply via email to