This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/66639] Feature request C++: mark __func__ , __FUNCTION__ & __PRETTY_FUNCTION__ as constexpr
- From: "simon at gleissner dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 24 Jun 2015 09:26:46 +0000
- Subject: [Bug c++/66639] Feature request C++: mark __func__ , __FUNCTION__ & __PRETTY_FUNCTION__ as constexpr
- Auto-submitted: auto-generated
- References: <bug-66639-4 at http dot gcc dot gnu dot org/bugzilla/>
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;
}