Bug 41955 - /usr/include/rpm/rpmlib.h is not C++ safe
Summary: /usr/include/rpm/rpmlib.h is not C++ safe
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Raw Hide
Classification: Retired
Component: rpm
Version: 1.0
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jeff Johnson
QA Contact: David Lawrence
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2001-05-23 11:07 UTC by Vladimir Kondratiev
Modified: 2007-04-18 16:33 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2001-05-23 13:22:52 UTC
Embargoed:


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

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.


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