C++ Logo

SG7

Advanced search

Subject: Re: [isocpp-ext] CWG1962+CWG2362 type of __func__ / __func__ should be constexpr
From: Peter Dimov (pdimov_at_[hidden])
Date: 2020-04-30 09:48:21


Herring, Davis wrote:
> > I'm not sure I see what additional problems this would create. At the
> > moment,
> >
> > inline char f()
> > {
> > return __func__[0];
> > }
> >
> > already causes an ODR violation if __func__[0] doesn't have the same
> > value in two translation units. Allowing people to instantiate templates
> > with __func__[0] doesn't seem to add much.
>
> I don't see how the ODR can be violated by two tokenwise-identical
> definitions that don't refer to any external entity. Perhaps an
> implementation might generate two different-valued weak symbols for
> "f::__func__", but so long as only one of them is used (by whichever weak
> definition of f is chosen), this seems to work correctly.

All compilers optimize the above to just "return 'f';", so if __func__[0]
varies, so does the result.


SG7 list run by herb.sutter at gmail.com

Older Archives on Google Groups