Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] Bug with macros

Hey guys,

This example was taken from a program, I've distilled it to it's essence though but chosen to keep an example because it expresses a time where one might use this (I find all to often bugs can be given a low priority simply because they are rarely used).

Anyway:

------------------------------------------------------

#define CREATE_LISTENER(FOR,TYPE) \
class On##FOR##Emmitter; \
class On##FOR##Listener { \
    private: \
        void stopListeningTo(On##FOR##Emitter* what) { } \
        On##FOR##Emitter* listeningTo; \
    protected:\
        On##FOR##Listener() { listeningTo = nullptr; } \
virtual ~On##FOR##Listener() { if(listeningTo != nullptr) { stopListeningTo(listeningTo); } } \

#define FINISH_LISTENER() };


class Number { };

CREATE_LISTENER(ValueChange,Number)

FINISH_LISTENER()

------------------------------------------------------

Eclipse CDT complains on the CREATE_LISTENER line with: "Type 'CREATE_LISTENER(ValueChange,Number)' could not be resolved" I'm not quite sure about this error (what it means or where it comes from) - there is one error marked within the macro for the "stopListeningTo" call used in the destructor, eclipse says: Invalid arguments '
Candidates are:
void stopListeningTo(? *)
'

The macro is correctly expanded to read:

-------------------------------------------------------

class OnValueChangeEmmitter; \
class OnValueChangeListener { \
    private: \
        void stopListeningTo(OnValueChangeEmitter* what) { } \
        OnValueChangeEmitter* listeningTo; \
    protected:\
        OnValueChangeListener() { listeningTo = nullptr; } \
virtual ~OnValueChangeListener() { if(listeningTo != nullptr) { stopListeningTo(listeningTo); } }

-------------------------------------------------------

So I am not sure what is going on underneath to result in this.

While I am here, it'd be great if explore macro expansion actually allowed one to explore, maybe a list of steps to choose from and their results, it'd also be nice if it didn't highlight all the text of the expansion, it'd be great if it used syntax highlighting though! Or failing that just displaying normally.

Alec


Back to the top