Pimpl copying

Peter Kümmel syntheticpp at gmx.net
Sat Jul 15 07:31:24 BST 2006


Brad Hards wrote:
> On Saturday 15 July 2006 00:42, Peter Kümmel wrote:
>> +#define KDE_PIMPL_BASE_MACRO(COPY_ACCESS,X) \
>> +COPY_ACCESS: \
>> +    X(const X##&); \
>> +    X##& operator=(const X##&); \
>> +private: \
>> +    class X##Private; \
>> +    X##Private * const d;
>> +
>> +#define KDE_PIMPL_ENABLE_COPY(X)  KDE_PIMPL_BASE_MACRO(public, X)
>> +#define KDE_PIMPL_DISABLE_COPY(X) KDE_PIMPL_BASE_MACRO(private,X)
>> +
>> +
>>  #endif /* _KDE_MACROS_H_ */
> Hmm, I'm having problems with this:
> 
> Building CXX object kdecore/CMakeFiles/kdecore.dir/ktempdir.o
> In file included from /home/bradh/coding/kdelibs/kdecore/ktempdir.cpp:50:
> /home/bradh/coding/kdelibs/kdecore/ktempdir.h:164:1: error: pasting "KTempDir" 
> and "&" does not give a valid preprocessing token
> /home/bradh/coding/kdelibs/kdecore/ktempdir.h:164:1: error: pasting "KTempDir" 
> and "&" does not give a valid preprocessing token
> /home/bradh/coding/kdelibs/kdecore/ktempdir.h:164:1: error: pasting "KTempDir" 
> and "&" does not give a valid preprocessing token
> 
> This is with
> gcc version 4.1.1 20060525 (Red Hat 4.1.1-1)
> 
> Brad

I've fixed this by changing KTempDir.h,
don't wanna touch kdemacros.h.cmake until the final solution.

Seems gcc does not like 'X##&', 'X &' should work.
Index: kdemacros.h.cmake
===================================================================
--- kdemacros.h.cmake   (revision 562532)
+++ kdemacros.h.cmake   (working copy)
@@ -413,8 +413,8 @@

 #define KDE_PIMPL_BASE_MACRO(COPY_ACCESS,X) \
 COPY_ACCESS: \
-    X(const X##&); \
-    X##& operator=(const X##&); \
+    X(const X &); \
+    X & operator=(const X &); \
 private: \
     class X##Private; \
     X##Private * const d;

Is this a gcc bug or is X##& an invalid preprocessor command?




More information about the kde-core-devel mailing list