Bug 41955 - /usr/include/rpm/rpmlib.h is not C++ safe
/usr/include/rpm/rpmlib.h is not C++ safe
Product: Red Hat Raw Hide
Classification: Retired
Component: rpm (Show other bugs)
All Linux
medium Severity medium
: ---
: ---
Assigned To: Jeff Johnson
David Lawrence
Depends On:
  Show dependency treegraph
Reported: 2001-05-23 07:07 EDT by Vladimir Kondratiev
Modified: 2007-04-18 12:33 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2001-05-23 09:22:52 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
fix c++ compilation (474 bytes, patch)
2001-05-23 07:14 EDT, Vladimir Kondratiev
no flags Details | Diff

  None (edit)
Description Vladimir Kondratiev 2001-05-23 07:07:28 EDT
Description of Problem:

Any C++ code that include /usr/include/rpm/rpmlib.h failed to compile.
Error occurrs here (line 39):

/*@unused@*/ static inline /*@null@*/ void * _free(/*@only@*/ /*@null@*/
const void * this) {
    if (this != NULL)	free((void *)this);
    return NULL;

Error messages is like these:
/usr/include/rpm/rpmlib.h:39: parse error before `this'
/usr/include/rpm/rpmlib.h: In function `void *_free (...)':
/usr/include/rpm/rpmlib.h:40: invalid use of `this' in non-member 
/usr/include/rpm/rpmlib.h:40: invalid use of `this' in non-member 
Proposed fix:

Replace reserved C++ word 'this' with something else.
Comment 1 Vladimir Kondratiev 2001-05-23 07:14:54 EDT
Created attachment 19373 [details]
fix c++ compilation
Comment 2 Jeff Johnson 2001-05-23 08:21:15 EDT
Hmmm, this is C code, not C++ code, in rpmlib.h. And, the function is
within a
	#ifdef __cplusplus
	extern "C" {
section. Yes, it may be unusual to have an entire static inline function within
an include file <shrug>.

While I'm not averse to changing the variable name "this", I think there's
else going on here that needs to be understood first.. What compiler are you
and why is your C++ compiler getting picky about a C variable name that is
marked as a C function?
Comment 3 Vladimir Kondratiev 2001-05-23 09:22:47 EDT
Even if function is in 'extern "C"', it is still parsed by C++ compiler.
extern "C" directive relates to linkage type only, it just dictates to not
mangle function name. 'this' is still the reserved word. C++ standard say
nothing about inline "C" functions, since this is extension, but assuming this
should be handled similar to #define, it is obvious function code should be
interpreted as C++ code when compiled by C++ compiler. It can't be the case that
part of file compiled as C while the rest - ac C++.

In my case, compiler is gcc as on rawhide (gcc-2.96-85).
I use simple test case:
#include <rpmlib.h>
void foo() {}
If you try to compile it (gcc -I/usr/include/rpm -c test.cpp) you get errors

I checked that if I change 'this' to 'ptr' (as in patch attached), this simple
test compiles fine.
Comment 4 Jeff Johnson 2001-05-23 09:35:33 EDT
OK, so the static inline function is C++, not C. Thanks for the clarification.

FIxed in next checkin, will be in rpm-4.0.3-0.26.

Note You need to log in before you can comment on or make changes to this bug.