https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66639

--- Comment #3 from Simon Gleissner <simon at gleissner dot de> ---
Hi *

> If at all, this could only be provided as compiler extension.

Good point. Yes, i think this would be a adequate solution.

> (assuming making it constexpr doesn't break anything)

... which IMHO could only be tested safely with an optional compiler switch.

I have modified the test program (see below), instead of __PRETTY_FUNCTION__ i
have declared a 'static constexpr const char testarray[]'. This works
perfectly, the concatenated string is now stored as a constant object in
section .rodata:

        .section        .rodata
        .align 32
        .type   _ZZ4mainE4what, @object
        .size   _ZZ4mainE4what, 37
_ZZ4mainE4what:
        .byte   105
        .byte   110
        .byte   32
        .byte   39
...

As 'testarray[]' is no longer needed after evaluating 'what', it is removed
completely (i have not found it in the .S file), therefore only the final
string is stored.


#define THROW_SYSTEM_ERROR(ERROR_NO, CAUSE)                     \
do{                                                             \
        constexpr static auto what = MyLib::concatenate(        \
                "in '", testarray, "' by '" CAUSE "'");         \
        throw std::system_error(ERROR_NO,                       \
                std::system_category(), what.str);              \
} while(0)

int main()
{
        try
        {
                static constexpr const char testarray[] = "constexprFunc()";

                THROW_SYSTEM_ERROR(EINVAL, "testfunc()");
        }
        catch(const std::system_error& exception)
        {
                std::cerr << "Exception " << exception.what() << " (" <<
exception.code() << ")" << std::endl;
        }

        return 0;
}

Reply via email to