C++ Logo


Advanced search

Re: [SG7] [isocpp-ext] CWG1962+CWG2362 type of __func__ / __func__ should be constexpr

From: Herring, Davis <herring_at_[hidden]>
Date: Thu, 30 Apr 2020 14:29:38 +0000
> 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.

Allowing __func__[0] to be a constant expression, on the other hand, allows nonsense like

  inline auto f() {
    return static_cast<int(*)[__func__[0]+1]>(nullptr);

which is also not an ODR violation if repeated in multiple translation units but might make interestingly different things happen in them. This latter issue of course already arises with sizeof in the status quo, which is part of CWG1962's worry.


Received on 2020-04-30 09:32:40