13

Is there anything that protected members or functions can be used for?

You cannot inherit from a union so there are no children that can access it. Does it provide a functional use or is just there because removing it was hassle?

Stefan
  • 3,669
  • 2
  • 32
  • 43

1 Answers1

12

protected in a union becomes completely equivalent to private, but this allowance does no harm and avoids extra special case handling and extra differences between union and struct/class (which are described all together in the standard).

Honestly, I think it's possible to use protected in a union just not to add the umteenth special case to the standard for the sake of it; maybe it didn't even come to mind to the standard committee to differentiate this behavior, since it's quite a bizarre corner case but does no harm as it's currently specified.

Matteo Italia
  • 123,740
  • 17
  • 206
  • 299
  • So it is just in there because it was more hassle than it was worth to remove it? – Stefan Nov 25 '13 at 15:32
  • @Stefan: I would say so; why bother with creating special cases? (ok, well, this is C++ and there are special cases and UB for everything, but the point stands) – Matteo Italia Nov 25 '13 at 15:34