lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Roberto Ierusalimschy wrote:
> When I compile lpeg (version 0.5) with g++ (that is, as C++ code), I
> get the following error: 
> 
> lpeg.c:395: error: invalid conversion from 'int' to 'const char*'
> 
> That line is as follows:
> 
>           return luaL_error(L, "too many pending calls/choices"),
> NULL; 
> 
> (The function actually returns 'const char *'). If I remove the
> LuaL_error call from the expression, the error disapears. (So, it
> seems that NULL is still compatible with const char* ;) Parentheses
> around the comma expression have no effect. Is this a bug in gcc? Or
> am I doing something stupid?    
> 
> I am using gcc version 4.0.3.

I have the exact same behaviour with mingw-gcc 3.4.4 on win32. I don't
know if it's a bug, but it's clearly related to implicit conversion.
Here are two possible working workarounds beyond the simple "don't use
comma expression":

/* Default constructor */
// It would be nice to be able call the default constructor
// of qualified types, but as it is you must use a typedef.
typedef const char* str_t;
const char* foo()
{
//  return std::printf("foo\n"), (const char*)();
    return std::printf("foo\n"), str_t();
}

/* Explicit cast */
#define NULLSTR ((const char*)0)
const char* bar()
{
    return std::printf("bar\n"), NULLSTR;
}