Bug 69751 - error: call of overloaded 'abs(size_t)' is ambiguous
Summary: error: call of overloaded 'abs(size_t)' is ambiguous
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-02-10 15:57 UTC by mgansser@alice.de
Modified: 2016-02-10 16:43 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mgansser@alice.de 2016-02-10 15:57:51 UTC
g++ -c -ggdb -O0 -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -fPIC -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/mysql -I/usr/include/python2.7 -I/usr/include/python2.7 -D_GNU_SOURCE -DBINDEST='"/usr/bin"' -DTARGET='"epgd"' -DLOG_PREFIX='""' -DPLGDIR='"/usr/lib64/epgd"' -DUSEUUID -DUSEMD5 -DUSELIBXML -DUSELIBARCHIVE -DUSEJSON -DUSEGUNZIP -I/usr/include/libxml2 -I/usr/include/libxml2  -DGIT_REV='""' -o series.o series.c
series.c: In member function 'int cEpgd::evaluateEpisodes()':
series.c:90:99: error: call of overloaded 'abs(size_t)' is ambiguous
                if (::abs(strlen(evtCompShortText) - strlen(episodeDb->getStrValue("COMPPARTNAME"))) >= dMin)
                                                                                                   ^
In file included from /usr/include/c++/6.0.0/cstdlib:75:0,
                 from /usr/include/c++/6.0.0/stdlib.h:36,
                 from /usr/include/libxml2/libxml/SAX.h:16,
                 from /usr/include/libxml2/libxml/globals.h:20,
                 from /usr/include/libxml2/libxml/xmlIO.h:117,
                 from /usr/include/libxml2/libxml/parser.h:811,
                 from /usr/include/libxslt/transform.h:15,
                 from epgd.h:11,
                 from series.c:8:
/usr/include/stdlib.h:774:12: note: candidate: int abs(int)
 extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
            ^~~
the program compiles fine with gcc-5.3.1
Comment 1 Marek Polacek 2016-02-10 16:01:13 UTC
This is invalid; calling abs() on an unsigned value does not make sense.
Cf. http://cplusplus.github.io/LWG/lwg-active.html#2192
Comment 2 Jonathan Wakely 2016-02-10 16:05:59 UTC
(In reply to mgansser@alice.de from comment #0)
> series.c:90:99: error: call of overloaded 'abs(size_t)' is ambiguous
>                 if (::abs(strlen(evtCompShortText) -
> strlen(episodeDb->getStrValue("COMPPARTNAME"))) >= dMin)
>                                                                             

This doesn't do what the author of that code thinks it does. If the second string is longer than the first then the difference between them is not a negative number, it's a huge unsigned value. Calling abs(int) on a huge unsigned value will overflow and is undefined behaviour.

This is exactly why calling abs() here should be an error: the code has undefined behaviour and should be fixed.
Comment 3 mgansser@alice.de 2016-02-10 16:43:20 UTC
many thanks for supporting me, problem was solved.