Bug 41955

Summary: /usr/include/rpm/rpmlib.h is not C++ safe
Product: [Retired] Red Hat Raw Hide Reporter: Vladimir Kondratiev <vladimir.kondratiev>
Component: rpmAssignee: Jeff Johnson <jbj>
Status: CLOSED RAWHIDE QA Contact: David Lawrence <dkl>
Severity: medium Docs Contact:
Priority: medium    
Version: 1.0   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2001-05-23 13:22:52 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
fix c++ compilation none

Description Vladimir Kondratiev 2001-05-23 11:07:28 UTC
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 
function
/usr/include/rpm/rpmlib.h:40: invalid use of `this' in non-member 
function
 
Proposed fix:

Replace reserved C++ word 'this' with something else.

Comment 1 Vladimir Kondratiev 2001-05-23 11:14:54 UTC
Created attachment 19373 [details]
fix c++ compilation

Comment 2 Jeff Johnson 2001-05-23 12:21:15 UTC
Hmmm, this is C code, not C++ code, in rpmlib.h. And, the function is
within a
	#ifdef __cplusplus
	extern "C" {
	#endif
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
something
else going on here that needs to be understood first.. What compiler are you
using,
and why is your C++ compiler getting picky about a C variable name that is
clearly
marked as a C function?

Comment 3 Vladimir Kondratiev 2001-05-23 13:22:47 UTC
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:
---------test.cpp--------
#include <rpmlib.h>
void foo() {}
-------------------------
If you try to compile it (gcc -I/usr/include/rpm -c test.cpp) you get errors
mentioned.

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 13:35:33 UTC
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.