7

I am wondering why void() is a prvalue of void but void{} does not exist...? See the following answer: https://stackoverflow.com/a/37708167/293195

For example in the context:

template<typename R>
R foo(){
 return R{};
}
Barry
  • 286,269
  • 29
  • 621
  • 977
Gabriel
  • 8,990
  • 6
  • 57
  • 101
  • 4
    [Obligatory](https://meta.stackoverflow.com/a/323382/2069064). It's hard to know what you're looking for in an answer here. Because [P0146](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0146r1.html) wasn't approved? Or because when added brace-initialization was added, nobody thought about `void`... or cares since. Or ...? – Barry Nov 12 '18 at 14:16
  • 4
    Related [How much existing C++ code would break if void was actually defined as `struct void {};`](https://stackoverflow.com/q/53197340/1708801) – Shafik Yaghmour Nov 12 '18 at 14:20
  • 1
    @Barry: there are a ton of language-design "why" questions which can be answered properly, in an objective manner. When someone puts a question, they don't know that the answer would be "god-knows-why", or "it's because ". Just an example, here's a "why" question, with a proper answer: https://stackoverflow.com/questions/8911696/if-condition-with-nullable. By the same person who wrote that "obligatory" answer. And even, a "god-knows-why" is a better answer than a no answer. This way, at least, we know, that there's no particular reason for something (so it's not a design decision). – geza Nov 12 '18 at 15:02
  • @geza Are you suggesting that this is one of those language-design "why" questions that can be answered properly in an objective manner? If you're not suggesting this, then I don't understand the point of the comment. I'm just stating that I do not know how to answer this question because I do not believe there is a meaningful, objective answer to it. – Barry Nov 12 '18 at 15:38
  • @Barry: Okay then, maybe I've just misunderstand your intents. – geza Nov 12 '18 at 15:53

1 Answers1

7

CWG 2351, resolved in June, has made void{} legal.

cpplearner
  • 13,776
  • 2
  • 47
  • 72