user2424607
user2424607

Reputation: 295

Expression cannot be used as a function in expansion of macro

I'm trying to compile some code (using GCC 4.8.2) and am getting an error: expression cannot be used as a function.

Here is the relevant code.

debug.h

// A macro for code which is not expected to be reached under valid assumptions
#if !defined(NDEBUG)
#define UNREACHABLE() do { \
    ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__); \
    assert(false); \
    } while(0)
#else 
    #define UNREACHABLE() ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__)
#endif

someFile.cpp (only the default line is really relevant)

HLSLBlockEncoder::HLSLBlockEncoderStrategy HLSLBlockEncoder::GetStrategyFor(ShShaderOutput outputType)
{
    switch (outputType)
    {
      case SH_HLSL9_OUTPUT: return ENCODE_LOOSE;
      case SH_HLSL11_OUTPUT: return ENCODE_PACKED;
      default: UNREACHABLE(); return ENCODE_PACKED;
    }
}

Error:

/.../debug.h:123:90: error: expression cannot be used as a function
     #define UNREACHABLE() ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__)
                                                                                          ^
/.../someFile.cpp:217:16: note: in expansion of macro 'UNREACHABLE'
       default: UNREACHABLE(); return ENCODE_PACKED;
                ^

I am trying to understand why the error is happening. Looking at this question I thought maybe the issue was that the function (HLSL...) was being used as a variable due to __FUNCTION__ in the macro. But according to the GCC documentation: "GCC provides three magic variables which hold the name of the current function, as a string", so I don't believe that is the problem. Any other ideas?

Upvotes: 1

Views: 3051

Answers (1)

user2424607
user2424607

Reputation: 295

Updating this with the solution I found.

Thanks to those above who told me to investigate ERR more. It turns out there was a duplicate definition of ERR in another header file that seems to have been causing my error. Changing the definition of ERR in debug.h to avoid this collision fixed my problems. :)

Upvotes: 1

Related Questions